Smart Signal Light System By Arduino Mega 2560

Introduction:
  • In this article I have explained about the Smart Signal Light System using Arduino Mega 2560.
  • It is used to generate light correctly.
  • It will automatically generate the signals. 
Parts Of Lists:
  • Arduino Mega 2560
  • Led-3
  • Bread Board
  • Push Button
  • Hookup Wires
Connetions:

Step 1: Connection From LED To Board:
  • Connect the LED1 of positive pin to the 03 of the Arduino board.
  • Connect the LED2 of positive pin to the 04 of the Arduino board.
  • Connect the LED3 of positive pin to the 05 of the Arduino board.
  • Connect the LEDS negative pin to the GND commonly. 
Step 2: Connection From PUSHBUTTON To Board:
  • Connect the positive pin to the 7 of the Arduino board with the positive side. Connect the 5v of the board.
  • Connect the negative side to the GND of the board. 
Programming
  1. int one = 03;    
  2. int two = 04;    
  3. int three = 05;    
  4. int btn = 7;    
  5. int state = 0;    
  6. void setup()    
  7. {    
  8.     pinMode(one, OUTPUT);    
  9.     pinMode(two, OUTPUT);    
  10.     pinMode(three, OUTPUT);    
  11. }    
  12. void loop()    
  13. {    
  14.     if (digitalRead(btn))    
  15.     {    
  16.         if (state == 0)    
  17.         {    
  18.             setLights(HIGH, LOW, LOW);    
  19.             state = 1;    
  20.         } else if (state == 1)     
  21.         {    
  22.             setLights(HIGH, HIGH, LOW);    
  23.             state = 2;    
  24.         } else if (state == 2)     
  25.         {    
  26.             setLights(LOW, LOW, HIGH);    
  27.             state = 3;    
  28.         } else if (state == 3)    
  29.         {    
  30.             setLights(LOW, HIGH, LOW);    
  31.             state = 0;    
  32.         }    
  33.         delay(1000);    
  34.     }    
  35. }    
  36. void Traffic(int red, int yellow, int green)    
  37. {    
  38.     digitalWrite(one, red);    
  39.     digitalWrite(two, yellow);    
  40.     digitalWrite(three, green);    
  41. }    
Explanation:
  • It can glow the lights automatically with the delay times.
  • We can set the delay time and watch the LEDs/lights, it changes automatically.
  • When the first light glows, the second and third remains off.
  • Second light glows the third and first is off.
  • Third light glows the first and second is off. 
Output:

  
                                                     Figure 1: Output
 
Read more articles on Arduino:

Up Next
    Ebook Download
    View all
    Learn
    View all