Skip to content

Project 2.10.1: SMART SOUND ALERT SYSTEM

Description You will learn how to detect the presence or absence of light.
Use case Controlling visibility of light in streetlights at different times of the day

Components (Things You will need)

LED Arduino Uno Arduino USB Cable Breadboard Jumper Wires LDR Sensor

Building the circuit

Things Needed:

  • Arduino Uno = 1
  • Arduino USB cable = 1
  • Light dependent resistor = 1
  • Red jumper wire = 1
  • Black jumper wire = 1
  • Green jumper wire = 1
  • White jumper wire = 1

Mounting the component on the breadboard

Things needed:

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: Take the Buzzer and insert it into the horizontal connectors on the breadboard.

Buzzer fixed on breadboard.

WIRING THE CIRCUIT

Step 1: Take the red jumper wire. Connect one end of the wire to the “VCC” port on the light dependent resistor and the other end to the “5V” port on the Arduino UNO.

Red wire fixed on breadboard.

Step 2: Take the black jumper wire. Connect one end of the wire to the “GND” hole on the Arduino UNO and the other end to the “GND” port on the light dependent resistor.

Black wire fixed on breadboard.

Step 3: Take the white jumper wire. Connect one end of the wire to the “DO” hole on the resistor and the other end to hole number 2 on the Arduino UNO.

White wire fixed on breadboard.

Step 4: Take the green jumper wire. Connect one end of the wire to the “AO” port on the Arduino UNO to the “AO” port on the light dependent resistor.

Green wire fixed on breadboard.

Step 5: Take the brown jumper wire. Connect one end of the wire to one of the ports of the longer pin of the LED and connect the other end to hole number 6 on the Arduino UNO.

Brown wire fixed on breadboard.

Step 6: Take the purple jumper wire. Connect one end of the wire to one of the ports of the shorter pin of the LED and connect the other end to the “GND” on the Arduino UNO.

Purple 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 = 2; as shown below in the image

Code 2.

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

Code 3.

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

Code 4.

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

Code 4.

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

Code 5.

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

Code 6.

Step 9: Type Serial.print(“Analog Value:”); as shown below in the image

Code 7.

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

Code 8.

Step 11: Type Serial.print(“Digital Value:”); as shown below in the image

Code 9.

Step 12: Type Serial.println(digitalValue); as shown below in the image

Code 10.

Step 13: Type if(ldrValue < 100){ as shown below in the image

Code 11.

Step 14: Type digitalWrite(BUZZER, HIGH);} as shown below in the image

Code 12.

Step 15: Type else{digitalWrite(BUZZER, LOW);} as shown below in the image

Code 12.

Step 16: Save your code. See the Getting Started section

Step 17: Select the arduino board and port See the Getting Started section:Selecting Arduino Board Type and Uploading your code.

Step 18: Upload your code. See the Getting Started section:Selecting Arduino Board Type and Uploading your code

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. You have now learnt how to program a buzzer to go off in the absence of light. Practice, as they say makes perfect. Continue to work hard and in time you’ll master it.