Devices & Components
Arduino Uno Rev3
Jumper wires (generic)
Buzzer, Piezo
Laser Module
LDR, 5 Mohm
Breadboard (generic)
Software & Tools
Arduino IDE
Project description
Code
Arduino code
arduino
1const int ledPin = 13; 2 3const int buzzerPin = 12; 4 5const int ldrPin = A0; 6const int laserPin = 7; 7 8void setup () { 9 10Serial.begin(9600); 11 12pinMode(ledPin, OUTPUT); 13 14pinMode(buzzerPin, OUTPUT); 15 16pinMode(ldrPin, INPUT); 17pinMode( laserPin , OUTPUT); 18 19digitalWrite( laserPin , HIGH); 20 21} 22 23void loop() { 24 25int ldrStatus = analogRead(ldrPin); 26 27if (ldrStatus > 1) { 28 29tone(buzzerPin, 100); 30 31digitalWrite(ledPin, HIGH); 32 33delay(100); 34 35noTone(buzzerPin); 36 37digitalWrite(ledPin, LOW); 38 39delay(100); 40 41Serial.println(" ALARM ACTIVATED "); 42 43} 44 45else { 46 47noTone(buzzerPin); 48 49digitalWrite(ledPin, LOW); 50 51Serial.println("ALARM DEACTIVATED"); 52 53} 54Serial.println( ldrStatus ); 55//delay(10); 56}
Arduino code
arduino
1const int ledPin = 13; 2 3const int buzzerPin = 12; 4 5const int ldrPin = A0; 6const int laserPin = 7; 7 8void setup () { 9 10Serial.begin(9600); 11 12pinMode(ledPin, OUTPUT); 13 14pinMode(buzzerPin, OUTPUT); 15 16pinMode(ldrPin, INPUT); 17pinMode( laserPin , OUTPUT); 18 19digitalWrite( laserPin , HIGH); 20 21} 22 23void loop() { 24 25int ldrStatus = analogRead(ldrPin); 26 27if (ldrStatus > 1) { 28 29tone(buzzerPin, 100); 30 31digitalWrite(ledPin, HIGH); 32 33delay(100); 34 35noTone(buzzerPin); 36 37digitalWrite(ledPin, LOW); 38 39delay(100); 40 41Serial.println(" ALARM ACTIVATED "); 42 43} 44 45else { 46 47noTone(buzzerPin); 48 49digitalWrite(ledPin, LOW); 50 51Serial.println("ALARM DEACTIVATED"); 52 53} 54Serial.println( ldrStatus ); 55//delay(10); 56}
Downloadable files
Arduino connections
Arduino connections

Comments
Only logged in users can leave comments