Light Detector Buzzer

by olechowskil in Circuits > Gadgets

235 Views, 0 Favorites, 0 Comments

Light Detector Buzzer

IMG_1456[356].jpg
photo.jpg

This buzzer can be put into food boxes(crackers, bread, cereal, etc...) and it will alert you by buzzing to tell you when the box isn't fully closed(uses light to detect this)

Supplies

IMG_1448[344].jpg
Screenshot 2023-05-24 113431.png

Arduino Uno R3, breadboard, photoresistor, resistor, buzzer, 9v battery and connector, and male to male wires

Tinkercad Coding

Screenshot 2023-05-24 113431.png
code.png

On Tinkercad, place the following items; Arduino Uno R3, breadboard, photoresistor, resistor, buzzer, 9v battery and connector, and male to male wires. connect them as the photo shows. Then place the code blocks in the order that the photo shows. Finally start the simulation on Tinkercad, move the slider on the photoresistor and make sure the code is working. The buzzer should turn on when light hits the photoresistor. CODE HERE:

// C++ code

//

int pos = 0;


int i = 0;


void setup()

{

 pinMode(A0, INPUT);

 pinMode(9, OUTPUT);

 pinMode(9, OUTPUT);

}


void loop()

{

 if (analogRead(A0) >= 500) {

  tone(9, 29, 1000); // play tone 10 (A#0 = 29 Hz)

 } else {

  digitalWrite(9, LOW);

 }

 delay(10); // Delay a little bit to improve simulation performance

}

Set Up Physical Board

IMG_1452[348].jpg
Screenshot 2023-05-24 113431.png

With the physical pieces in hand, place them on the bread board and Arduino the same way they are placed on Tinkercad.

Get the Code Working

IMG_1453.jpg
Screenshot 2023-05-24 115137.png

Download the Arduino IDE software at https://www.arduino.cc/en/software . Then plug in the code from Tinkercad into the software. Plug in your physical Arduino and send the code over using the arrow button in the top left corner as shown in the photo. Your Arduino should then start working. When the photoresistor detects light, it will buzz very annoyingly until light is no longer hitting it anymore.

FINISH

Now, you can place this computer wherever you like, whether it is in a cereal box, refrigerator, or room. This light detector can be used for many things, have fun!!