Components Required:

  • 1 x Arduino Uno
  • LED
  • Buzzer(photoresistor)
  •  220 and 10K ohm resistor
  • Blackboard
  • Wires

Description:

In this project; we will see using LDR to activate a buzzer and an LED. When light shines on LDR; the buzzer will give the alarm and the LED will flash.

Min Required: 30 Min

Connections:

procedure:

  1. Buzzer attach to board (the buzzer long leg (+) and short leg (-))
  2. LED attach to board (the LED long leg (+) and short leg (-))
  3. 220 resistor attach to board from the LED long leg (+)
  4. LDR attach to board
  5. 10k resistor attach to board from LDR one leg
  6. The wire connects to ground, then the same wire attaches to board.
  7. The wire connects to buzzer short leg, then the same wire attaches to GND on the board.
  8. The wire attaches to LED short leg, then the same wire connect to GND on the board.
  9. The wire connects to 10k resistor empty leg, then the same wire connects to GND on the board.
  10. The wire connects to +5V, then the same wire attaches to LDR empty leg.
  11. The wire connects to digital 12, then attach to buzzer long leg.
  12. The wire connects to digital 13, then attach to 220 resistor empty leg.
  13. The wire connects to A0, then attach to LDR’s – resistor’s same column.
  14. Connect Arduino to your Laptop/PC by USB Cable.( we use A to B USB cable for Arduino which is also used in printers )
  15. Open Arduino IDE ( You can download it from here you can use online platform Arduino Web editor )
  16. Go to File > New type the code given above.
  17. Check program, save it and then upload it.

 

The line of Codes:

const int ledPin = 13;

const int buzzerPin = 12;

const int ldrPin = A0;

void setup () {

Serial.begin(9600);

pinMode(ledPin, OUTPUT);

pinMode(buzzerPin, OUTPUT);

pinMode(ldrPin, INPUT);

}

void loop() {

int ldrStatus = analogRead(ldrPin);

if (ldrStatus >= 400) {

tone(buzzerPin, 100);

digitalWrite(ledPin, HIGH);

delay(100);

noTone(buzzerPin);

digitalWrite(ledPin, LOW);

delay(100);

Serial.println(“———– ALARM ACTIVATED ———–“);

}

else {

noTone(buzzerPin);

digitalWrite(ledPin, LOW);

Serial.println(“ALARM DEACTIVATED”);

}

}