Arduino Light Sensor and Alarm
by millerman4487 in Circuits > Arduino
7372 Views, 9 Favorites, 0 Comments
Arduino Light Sensor and Alarm
![arduino2 3.png](/proxy/?url=https://content.instructables.com/FC4/KZVX/INC09YCM/FC4KZVXINC09YCM.png&filename=arduino2 3.png)
This is a design of mine that you place inside of a box, drawer, or fridge and plays an alarm noise whenever you open the box, drawer, or fridge. It uses a light-sensitive resistor and is quiet when it is dark(the box is closed) and plays a noise when it is light(the box in open). It works especially well in the refrigerator, since a light comes on when you open it. You can use this to protect your things, annoy people, or help you stay on your diet by playing an annoying noise when you open the fridge.
Gather Parts
![arduino2 4.png](/proxy/?url=https://content.instructables.com/F45/ZC4M/INC09YCN/F45ZC4MINC09YCN.png&filename=arduino2 4.png)
You will need:
>a photoresistor (I use an R4)
> a 10kΩ resistor (brown-black-orange)
>a piezo buzzer
>a 9v battery and battery clip
>an Arduino board
>a Breadboard
>Jumper wires
Buy Specialty Parts:
photoresistor - https://www.sparkfun.com/products/9088
piezo buzzer - https://www.sparkfun.com/products/7950
Put Parts in Place
![arduino2 1.png](/proxy/?url=https://content.instructables.com/FBT/PMZ9/INC09YBW/FBTPMZ9INC09YBW.png&filename=arduino2 1.png)
Not much explaining to do here; just follow the picture.
Wire It Up
![arduino2 2.png](/proxy/?url=https://content.instructables.com/F83/9G5M/INC09YC7/F839G5MINC09YC7.png&filename=arduino2 2.png)
>Photoresistor goes to 5v, and ground through the resistor. Ground side of photoresistor goes to analog pin A2
>Piezo Buzzer goes to ground, and digital pin 2
>9v battery goes to ground and the Vin pin on board
Coding
![arduino2 7.png](/proxy/?url=https://content.instructables.com/FA3/R41G/INC09ZEZ/FA3R41GINC09ZEZ.png&filename=arduino2 7.png)
![arduino2 8.png](/proxy/?url=https://content.instructables.com/FCM/WBR0/INBYYRG7/FCMWBR0INBYYRG7.png&filename=arduino2 8.png)
Connect your Arduino to your computer and upload this code:
}const int dark = 200; //set dark parameters const int sound = 50; //set noise to play void setup() { pinMode(2, OUTPUT); pinMode(A2, INPUT); Serial.begin(9600); } void loop() { int light = analogRead(A2); if (light < dark) { Serial.print(light); Serial.println(" It's dark"); } else { Serial.print(light); Serial.println(" It's light"); tone(2, sound, 10); } delay(10); }
![Mountain View](/proxy/?url=https://content.instructables.com/FA3/R41G/INC09ZEZ/FA3R41GINC09ZEZ.png?auto=webp&fit=bounds&frame=1&height=1024&width=1024)
Open the Serial Monitor in the Arduino program, and watch what happens!