Skip to content

Project 2.9.5: SMART STREET LIGHT (5 LEDs)

Description You will learn how use the detection of the presence or absence of light to turn on or turn off LEDs.
Use case Controlling visibility of light in streetlights at different times of the day.

Components (Things You will need)

LEDs Arduino Uno Arduino USB Cable Breadboard Jumper Wires LDR Sensor

Building the circuit

Things Needed:

  • 1 Arduino Uno
  • 1 Arduino USB cable
  • 1 Light dependent resistor
  • 1 Green LED
  • 1 Red LED
  • 1 Blue LED
  • 1 White LED
  • 1 Yellow LED
  • 1 Breadboard
  • 1 Red jumper wire
  • 1 Black jumper wire
  • 1 Green jumper wire
  • 2 Brown jumper wire
  • 1 White jumper wire
  • 2 Violet jumper wire
  • 1 Yellow jumper wire
  • 2 Orange jumper wire

Mounting the component on the breadboard

Things needed:

  • 1 Light dependent resistor
  • 1 Green LED
  • 1 Red LED
  • 1 Blue LED
  • 1 White LED
  • 1 Yellow LED
  • 1 Breadboard

Step 1: Take the light dependent resistor and the breadboard, insert the light dependent resistor into the horizontal connectors on the breadboard.

LDR sensor fixed on breadboard.

Step 2: Insert the red LED into the horizontal connectors on the breadboard beside the LDR and take note of where the positive pin (long pin) is and where the negative pin (short pin) is as shown in the picture below.

Red LED fixed on breadboard.

Step 3: Insert the LED green into the horizontal connectors on the breadboard on the other side of the LDR and take note of where the positive pin (long pin) is and where the negative pin (short pin) is as shown in the picture below.

Green LED fixed on breadboard.

Step 4: Insert the blue LED into the horizontal connectors on the breadboard on the other side of the LDR and take note of where the positive pin (long pin) is and where the negative pin (short pin) is as shown in the picture below.

Blue LED fixed on breadboard.

Step 5: Insert the white LED into the horizontal connectors on the breadboard on the other side of the LDR and take note of where the positive pin (long pin) is and where the negative pin (short pin) is as shown in the picture below.

White LED fixed on breadboard.

Step 6: Insert the Yellow LED into the horizontal connectors on the breadboard on the other side of the LDR and take note of where the positive pin (long pin) is and where the negative pin (short pin) is as shown in the picture below.

Yellow LED fixed on breadboard.

WIRING THE CIRCUIT

Things Needed:

  • 1 Red male-to-male jumper wire
  • 1 Black male-to-male jumper wire
  • 1 White male-to-male jumper wire
  • 1 Yellow male-to-male jumper wire
  • 1 Brown male-to-male jumper wire
  • 3 Green male-to-male Jumper Wire
  • 2 Violet male-to-male Jumper Wire
  • 2 Orange male-to-male Jumper Wire
  • 1 Grey male-to-male Jumper Wire
  • 1 Blue male-to-male Jumper Wire

Step 1: Take the green jumper wire. Connect one end of the wire to the “VCC” port on the LDR module and the other end to the “5V” port on the Arduino UNO board. As shown in the picture below.

Green wire fixed on breadboard.

Step 2: Take the black jumper wire, connect one end of the wire to the “GND” port on the Arduino UNO board and the other end to the “GND” port on the LDR module. As shown in the picture below

Black wire fixed on breadboard.

Step 3: Take the violet jumper wire, connect one end of the wire to the “DO” pin of the LDR module and the other end to the digital pin 8 on the Arduino UNO board. As shown in the picture below.

Violet wire fixed on breadboard.

Step 4: Take the brown jumper wire, connect one end of the wire to the “AO” port on the Arduino UNO board and the other end of the pin to the “AO” pin of the LDR module.

Brown wire fixed on breadboard.

Step 5: Take the orange jumper wire. Connect one end of the wire to the negative pin of the red LED and connect the other end to GND pin on the Arduino UNO board. As shown in the picture below.

Orange wire fixed on breadboard.

Step 6: Take the red jumper wire, connect one end of the wire to the positive pin of the red LED and connect the other end to digital pin 5 on the Arduino UNO board. As shown in the picture below.

Red wire fixed on breadboard.

Step 7: The Breadboard has sections labelled negative and positive. In these sections current runs through horizontally. Since we are working with 5 LEDs where we will need more than 3 GNDs we would transfer one GND to negative section of the Breadboard.

Red wire fixed on breadboard.

Step 8: Connect one end of the green male-to-male jumper wire to the GND of the Arduino Uno board and the other end to the negative section of the Breadboard to power the whole negative section as shown in the picture below.

Green wire fixed on breadboard.

Step 9: Take the white jumper wire, connect one end of the wire to the negative pin of the green LED and connect the other end to negative section of the Breadboard. As shown in the picture below.

White wire fixed on breadboard.

Step 10: Take the yellow jumper wire, connect one end of the wire to the positive pin of the green LED and connect the other end to the digital pin 7 on the Arduino UNO board. As shown in the picture below.

Yellow wire fixed on breadboard.

Step 11: Take the blue jumper wire, connect one end of the wire to the negative pin of the green LED and connect the other end to negative section of the Breadboard. As shown in the picture below.

Blue wire fixed on breadboard.

Step 12: Take the grey jumper wire, connect one end of the wire to the positive pin of the green LED and connect the other end to the digital pin 6 on the Arduino UNO board. As shown in the picture below.

Grey wire fixed on breadboard.

Step 13: Take the violet jumper wire, connect one end of the wire to the positive pin of the green LED and connect the other end to the negative section of the Breadboard. As shown in the picture below.

Violet wire fixed on breadboard.

Step 14: Take the orange jumper wire, connect one end of the wire to the positive pin of the green LED and connect the other end to the digital pin 13 on the Arduino UNO board. As shown in the picture below.

Orange wire fixed on breadboard.

PROGRAMMING

Step 1: Open your Arduino IDE. See how to set up here: Getting Started.

Step 2: Type const int LDR_PIN = A0. as shown below in the image

NB: Make sure you avoid errors when typing. Do not omit any character or symbol especially the bracket { } and semicolons ; and place them as you see in the image . The code that comes after the two ash backslashes “//” are called comments. They are not part of the code that will be run, they only explain the lines of code. You can avoid typing them.

Code 1.

Step 3: Type const int DO_PIN = 8; as shown below in the image

Code 2.

Step 4: Type const int Red = 5; as shown below in the image

Code 3.

Step 5: Type const int Green = 7; as shown below in the image

Code 4.

Step 6: Type const int Blue = 6; as shown below in the image

Code 4.

Step 7: Type const int White = 13; as shown below in the image

Code 5.

Step 8: Type const int Yellow = 3; as shown below in the image

Code 6.

Step 9: Type int ldrValue; as shown below in the image

Code 7.

Step 10: Type int digitalValue; as shown below in the image

Code 8.

Step 11: Type pinMode (DO_PIN, INPUT); as shown below in the image

Code 9.

Step 12: Type int redValue,greenValue,blueValue; as shown below in the image

Code 10.

Step 13: Type pinMode (DO_PIN, INPUT); as shown below in the image

Code 11.

Step 14: Type Serial.begin(9600); as shown below in the image

Code 12.

Step 15: Type pinMode(Red,OUTPUT); pinMode (Green,OUTPUT); pinMode(Blue, OUTPUT);pinMode(White, OUTPUT);pinMode(Yellow, OUTPUT); as shown below in the image

Code 13.

Step 16: Type int ldrValue = analogRead (LDR_PIN); as shown below in the image

Code 14.

Step 17: Type int lightState= digitalRead (DO_PIN); as shown below in the image

Code 15.

Step 18: Type Serial.printIn (ldrValue); as shown below in the image

Code 16.

Step 19: Type if (lightState == HIGH) {

Code 17.

Step 20: Type Serial.println ("Light is not present");

Code 18.

Step 21: Type

``` cpp

digitalWrite (Red, HIGH); digitalWrite (Green, HIGH); digitalWrite (Blue, HIGH); digitalWrite (White, HIGH); digitalWrite (Yellow, HIGH); ```

Code 19.

Step 22: Type

``` cpp
else {

Serial.println ("Light is present"); digitalWrite (Red, LOW); digitalWrite (Green, LOW); digitalWrite (Blue, LOW); digitalWrite (White, LOW); digitalWrite (Yellow, LOW); } ```

Code 20.

Code 21.

Conclusion

If you encounter any problems when trying to upload your code to the board, run through your code again to check for any errors or missing lines of code. If you did not encounter any problems and the program ran as expected Congratulations on a job well done.