Arduino Tutorial: Dog Door Buzzer

This Arduino tutorial will use a photoresistor and a piezo buzzer to create a buzzer for your dog door to know when your best friend comes and goes. A photoresistor is a light-controlled variable resistor whose resistance  decreases with exposure to light. As your dog passes through the door, the photoresistor’s resistance will decrease and cause thepiezo buzzer to sound.

 

Components:

1 Arduino Board

1 Breadboard

1 Photoresistor

1 Piezo Buzzer

1 10K ohm resistor

1  6” USB A/B cable

Hookup Wires

 

Directions:

  1. Start off by placing your photoresistor on the breadboard. Connect a wire from the 5V source to the photoresistor. Place a 10k Ω resistor on the other pin of the photoresistor. Connect a wire from the resistor to the A0 pin and a wire from the other leg of the resistor to the ground of your Arudino board.
  2. Connect a wire from digital pin 7 to the piezo buzzer on the breadboard. Be sure to ground the Piezo Buzzer.
  1. Open the Arduino software and create a new sketch; then upload the code below into the sketch:

int rcvpin=A0;

int buzzpin=7;

 

void setup()

 

{

 

pinMode(rcvpin,INPUT);

 

pinMode(buzzpin,OUTPUT);

 

buzz(200);

 

buzz(200);

 

buzz(200);

 

delay(2000);

 

Serial.begin(9600);

 

}

 

void loop()

 

{

 

int ldrval=analogRead(rcvpin);

 

Serial.println(ldrval);

 

if(ldrval>=500)

 

{

 

buzz(50);

 

}

 

}

 

void buzz(unsigned char time)

 

{

 

analogWrite(buzzpin,170);

 

delay(time);

 

analogWrite(buzzpin,0);

 

delay(time);

 

}

 

4.Connect a USB A/B cable from your computer to the Arduino. Click “Upload” in the Arduino program to run your sketch.

 

5.To test your code, cover the photoresistor to buzz the piezo buzzer.

corra02

Leave a Reply

Your email address will not be published. Required fields are marked *