Looking for schematic for this circuit.

Discussion in 'The Projects Forum' started by Kid347, Aug 20, 2016.

  1. Kid347

    Thread Starter Member

    Aug 14, 2015
    68
    0
    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
     
  2. blocco a spirale

    AAC Fanatic!

    Jun 18, 2008
    1,438
    368
    Last edited: Aug 20, 2016
  3. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,671
    897
  4. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    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
    [​IMG]
     
    Last edited: Aug 20, 2016
    Kid347 likes this.
  5. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    And the code for it not my code but theres
    Code (Text):
    1. #include <NewPing.h>            //include the NewPing library
    2.  
    3. //I/O pins
    4. int rLED = 0;
    5. int gLED = 1;
    6. int buttonPin = 2;
    7. int echo = 3;
    8. int trigger = 4;
    9.  
    10.  
    11.  
    12. //values to keep track of
    13. int distance = 0;
    14. int set = 0;
    15. int upper = 0;            
    16. int lower = 0;
    17. int range = 3;                                   //range is +/- so it is double the value in inches
    18. int count = 0;
    19. boolean lastButton = LOW;          //keep track of button status
    20. boolean currentButton = LOW;
    21. int previous = 0;                              //keep track of distances to identify when car is parked
    22. int current = 0;
    23.  
    24. NewPing sonar(0, 1, 500);       //constructor for NewPing sonar(triggerPin, echoPin, max_CM)
    25.  
    26. void setup()
    27. {
    28. pinMode(gLED, OUTPUT);
    29. pinMode(rLED, OUTPUT);
    30. pinMode(buttonPin, INPUT);
    31. }
    32. void loop()
    33. {
    34.   distance = sonar.ping_in();                  //detect distance in inches
    35.   if(distance == 0) distance = 500;          //if no distance is read, set at max distance
    36.   current = distance;                                //to check how long car has been parked in order to enter power save
    37.   delay(100);                                             //Slow program down - save battery?
    38.   currentButton = debounce(lastButton);            //reads button status and performs debounce, fixes unexpected button behavior
    39.   if(lastButton == LOW && currentButton == HIGH)          //when button pushed, set desired distance for parking
    40.   {
    41.     set = distance;                                //new variable for distance measured
    42.     flashGreen();                                  //flicker green LED 3 times
    43.     flashGreen();
    44.     flashGreen();
    45.   }
    46.   lastButton = currentButton;            //reset button status
    47.   upper = set + range;                        //  +/- inch tolerance range
    48.   lower = set - range;
    49.   if(distance <= upper && distance >= lower)            //within set area, stop!
    50.   {
    51.     //distance fluctuates some resulting in false movement detection
    52.     if(current == previous || current == previous + 1 || current == previous - 1 )
    53.     {
    54.       count++;                           //increase count if car has not moved
    55.     }
    56.     else
    57.     {
    58.       count = 0;                          //resent count if there is a significat change in distance
    59.     }
    60.  
    61.     // if distance doest change for 250 cycles (30 sec) turn off LED -> power saving mode
    62.     if(count >= 250)
    63.     {
    64.       off();
    65.       count = 250;                        //dont increment forever
    66.     }
    67.     else
    68.     {
    69.       red();                                   // within range, stop. red LED on
    70.     }
    71.  
    72.   }
    73.   if(distance > upper)
    74.   {
    75.     count = 0;                            //if car moves slow enough, it may never reset the count in above code, we reset again, just in case
    76.                                      
    77.     if(distance >= set+120)              //sensor becomes innacurate at distances much further than 120 inches
    78.     {                                                   //no car in garage turn LED off
    79.       off();
    80.     }                                            
    81.     if(distance < set+120 && distance > set+50)                  //car is detected
    82.     {                                                                                           //if distance is less than set + 120 inches and greater than set +50 inches
    83.       green();
    84.     }
    85.     if(distance <= set+50 && distance > upper)                  //wihtin 50 inches of set distance, slow down
    86.     {
    87.       yellow();
    88.     }
    89.   }
    90.   if(distance < lower)                                                           //car is too close, you must back up
    91.   {
    92.     count = 0;                                                                         //same situation for if car moves very slowly
    93.     flashRed();
    94.   }
    95.   previous = distance;                                                        //update distances
    96. }                                                                                            //end of loop
    97.  
    98. //debounce method to correct for voltage spikes that cause unexpected behavior
    99. boolean debounce(boolean last)
    100. {
    101.   boolean current = digitalRead(buttonPin);
    102.   if (last != current)
    103.   {
    104.     delay(5);
    105.     current = digitalRead(buttonPin);
    106.   }
    107.   return current;
    108. }
    109.  
    110. //color methods;
    111. void green()
    112. {
    113.    digitalWrite(rLED, HIGH);                 //because of pull-up resistor circuit, code is inverted
    114.    digitalWrite(gLED, LOW);
    115. }
    116. void red()
    117. {
    118.   digitalWrite(gLED, HIGH);  
    119.   digitalWrite(rLED, LOW);
    120. }
    121. void yellow()
    122. {
    123.   digitalWrite(rLED, 0);
    124.   digitalWrite(gLED, 100);
    125. }
    126. void flashRed()
    127. {
    128.   digitalWrite(gLED, HIGH);                     //flash red LED
    129.   digitalWrite(rLED, LOW);
    130.   delay(100);
    131.   digitalWrite(rLED, HIGH);
    132.   delay(100);
    133. }
    134. void flashGreen()
    135. {
    136.   digitalWrite(rLED, HIGH);
    137.   digitalWrite(gLED, LOW);                  //flicker green LED when button pushed
    138.   delay(50);
    139.   digitalWrite(gLED,HIGH);
    140.   delay(50);
    141. }
    142. void off()
    143. {
    144.   digitalWrite(gLED, HIGH);                  //turn off the LED
    145.   digitalWrite(rLED, HIGH);
    146. }
    147.  
     
  6. Kid347

    Thread Starter Member

    Aug 14, 2015
    68
    0
     
  7. Kid347

    Thread Starter Member

    Aug 14, 2015
    68
    0
    Thank You, I will try this. I assume the code for this circuit is what is in the next reply?
     
  8. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    Yep post 5 is the code
     
  9. Kid347

    Thread Starter Member

    Aug 14, 2015
    68
    0
    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.
     
  10. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    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: Aug 21, 2016
  11. Kid347

    Thread Starter Member

    Aug 14, 2015
    68
    0
    I found the original post, it has pictures along with the schematic, the problem is that the pictures are different from the schematic.
     
  12. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    I said that in 2 post I even said why that happens
    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: Aug 21, 2016
  13. panic mode

    Senior Member

    Oct 10, 2011
    1,318
    304

    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....
     
  14. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    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
     
Loading...