Arduino Light Sensor and Alarm

Introduction: Arduino Light Sensor and Alarm

About: I am here to share what I make. Hopefully, you can learn from watching what I have done and even improve upon it. As an Amazon Associate I earn from qualifying purchases.

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Gather Parts

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

Step 2: Put Parts in Place

Not much explaining to do here; just follow the picture.

Step 3: Wire It Up

>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

Step 4: Coding

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

Open the Serial Monitor in the Arduino program, and watch what happens!

Robotics Contest 2016

Participated in the
Robotics Contest 2016

Be the First to Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    2 Discussions

    0
    tytower
    tytower

    5 months ago

    It saves a lot of mucking around if you just include the ".ino" file while you have it handy. Yeh?

    0
    theoriginalrage
    theoriginalrage

    4 years ago

    This is a pretty cool idea. I like how you made it modular. Good work.