Looking for schematic for this circuit.

Thread Starter

Kid347

Joined Aug 14, 2015
70
I am hoping that someone can tell me where I can find the schematic for this circuit on the breadboard. I had put this together some time ago, and I must have borrowed some parts form time to time. However I got to this point, I can't get this circuit to work and I can't find the schematic to rebuild the circuit. it is a ATtiny85 IC with a HC-SR04 distance sensor going to a 3 pin RGB. It was intended to be a garage parking sensor green when it senses something, then it goes yellow as it senses something getting closer, and then it goes red when it is time to stop. If anyone has any insight on how this circuit works, I would greatly appreciate it. Thank You in advance.20160819_230818.jpg
 

be80be

Joined Jul 5, 2008
2,072
What he has there is not going to work two resistors are on the same pin it's miss wired and that's not a RBG led it only has 3 legs they have 4
Don't like these but this is more how it should be
 
Last edited:

be80be

Joined Jul 5, 2008
2,072
And the code for it not my code but theres
Code:
#include <NewPing.h>            //include the NewPing library

//I/O pins
int rLED = 0;
int gLED = 1;
int buttonPin = 2;
int echo = 3;
int trigger = 4;



//values to keep track of
int distance = 0;
int set = 0;
int upper = 0;            
int lower = 0;
int range = 3;                                   //range is +/- so it is double the value in inches
int count = 0;
boolean lastButton = LOW;          //keep track of button status
boolean currentButton = LOW;
int previous = 0;                              //keep track of distances to identify when car is parked
int current = 0;

NewPing sonar(0, 1, 500);       //constructor for NewPing sonar(triggerPin, echoPin, max_CM)

void setup()
{
pinMode(gLED, OUTPUT);
pinMode(rLED, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
  distance = sonar.ping_in();                  //detect distance in inches
  if(distance == 0) distance = 500;          //if no distance is read, set at max distance
  current = distance;                                //to check how long car has been parked in order to enter power save
  delay(100);                                             //Slow program down - save battery?
  currentButton = debounce(lastButton);            //reads button status and performs debounce, fixes unexpected button behavior
  if(lastButton == LOW && currentButton == HIGH)          //when button pushed, set desired distance for parking
  {
    set = distance;                                //new variable for distance measured
    flashGreen();                                  //flicker green LED 3 times
    flashGreen();
    flashGreen();
  }
  lastButton = currentButton;            //reset button status
  upper = set + range;                        //  +/- inch tolerance range
  lower = set - range;
  if(distance <= upper && distance >= lower)            //within set area, stop!
  {
    //distance fluctuates some resulting in false movement detection
    if(current == previous || current == previous + 1 || current == previous - 1 )
    {
      count++;                           //increase count if car has not moved
    }
    else
    {
      count = 0;                          //resent count if there is a significat change in distance
    }
  
    // if distance doest change for 250 cycles (30 sec) turn off LED -> power saving mode
    if(count >= 250)
    {
      off();
      count = 250;                        //dont increment forever
    }
    else
    {
      red();                                   // within range, stop. red LED on
    }
  
  }
  if(distance > upper)
  {
    count = 0;                            //if car moves slow enough, it may never reset the count in above code, we reset again, just in case
                                      
    if(distance >= set+120)              //sensor becomes innacurate at distances much further than 120 inches
    {                                                   //no car in garage turn LED off
      off();
    }                                             
    if(distance < set+120 && distance > set+50)                  //car is detected
    {                                                                                           //if distance is less than set + 120 inches and greater than set +50 inches
      green();
    }
    if(distance <= set+50 && distance > upper)                  //wihtin 50 inches of set distance, slow down
    {
      yellow();
    }
  }
  if(distance < lower)                                                           //car is too close, you must back up
  {
    count = 0;                                                                         //same situation for if car moves very slowly
    flashRed();
  }
  previous = distance;                                                        //update distances
}                                                                                            //end of loop

//debounce method to correct for voltage spikes that cause unexpected behavior
boolean debounce(boolean last)
{
  boolean current = digitalRead(buttonPin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(buttonPin);
  }
  return current;
}

//color methods;
void green()
{
   digitalWrite(rLED, HIGH);                 //because of pull-up resistor circuit, code is inverted
   digitalWrite(gLED, LOW);
}
void red()
{
  digitalWrite(gLED, HIGH);  
  digitalWrite(rLED, LOW);
}
void yellow()
{
  digitalWrite(rLED, 0);
  digitalWrite(gLED, 100);
}
void flashRed()
{
  digitalWrite(gLED, HIGH);                     //flash red LED
  digitalWrite(rLED, LOW);
  delay(100);
  digitalWrite(rLED, HIGH);
  delay(100);
}
void flashGreen()
{
  digitalWrite(rLED, HIGH);
  digitalWrite(gLED, LOW);                  //flicker green LED when button pushed
  delay(50);
  digitalWrite(gLED,HIGH);
  delay(50);
}
void off()
{
  digitalWrite(gLED, HIGH);                  //turn off the LED
  digitalWrite(rLED, HIGH);
}
 

Thread Starter

Kid347

Joined Aug 14, 2015
70
Yep post 5 is the code
Am I missing something or are the circuits different? If you look at the picture of the circuit it shows 3 resistors going to the RGB, and the Fritzing picture shows only 2. Also the wires coming out of the Attiny85 are different one picture shows using pins 2 and 3. The other shows using pins 1 and 2. Can someone please clarify. Thank You.
 

be80be

Joined Jul 5, 2008
2,072
The picture you posted is wrong what I posted is how it should be hooked up.
First off you don't need 3 resistors your only using two colors to make red green yellow.
You see this alot someone forgets the camera and slaps something that half looks like it. What I posted you should work as you wanted with the code i posted to it.
20160819_230818.jpg
 
Last edited:

be80be

Joined Jul 5, 2008
2,072
I found the original post, it has pictures along with the schematic, the problem is that the pictures are different from the schematic.
I said that in 2 post I even said why that happens
You see this alot someone forgets the camera and slaps something that half looks like it.
Anything that has arduino in it you forsure see stuff left out. It's because of the way they handle things I guess makes for lazy.
I'm not saying everyone is lazy that uses a arduino or it's not good to use one.
But it was dreamed up to get people programming of all ages and now you have people not taking time to draw out a circuit they snap a pic and leave out parts you need to know or get mad because you don't.
 
Last edited:

panic mode

Joined Oct 10, 2011
2,761
The picture you posted is wrong what I posted is how it should be hooked up.
First off you don't need 3 resistors your only using two colors to make red green yellow.
You see this alot someone forgets the camera and slaps something that half looks like it. What I posted you should work as you wanted with the code i posted to it.
View attachment 110831

those resistors are WAAAAY too large for driving LEDs.

red-red-yellow-gold is 220k 5%. for LED you need something on the other of 10mA (5-20mA depending on model).
10mA * 220k Ohm = 2200 V.

i do not see 2.2kV source....
 

be80be

Joined Jul 5, 2008
2,072
That's the OP picture. The pic I posted in #4 are red red brown 220 ohm.
I think someone grabbed the idea and posted some pictures to make it look like they did something.
I believe in drawing it out myself
 
Top