Arduino air-horn alarm

Using an Arduino to detect light, sound alarm.

Just wanted to share a very simple setup for sounding an air-horn using a servo connected to an Arduino.  I found that it can be tricky to get the mounting just right, and that  the servo (I’m using a standard issue Hitec HS-322HD) can have trouble pressing the trigger.  It takes a fair amount of effort (for a servo) to press the button and sound the horn.  You may have to play with the mounting to get it just right and take advantage of the best position for leverage.

You can see above I’ve fashioned a mount and some zip ties to fasten the servo.  I made this out of high density urethane which can be found at sign supply shops.  I’m sure results will vary depending on the brand of air horn you buy as I would guess they all have different tolerances and need more/less pressure to actuate the horn.

Above, you’ll see the Arduino with a protoshield mounted to the top along-side the airhorn.

Parts needed:

Arduino (any, I’m using a Duemilanove)
Photocell (also known as an LDR, or light-dependent resistor), Iike this one: https://www.adafruit.com/products/161
resistor (I’m using a 220 ohm,  but it will depend on the value of your Photocell)
Servo: You’ll need one that will run happily on the 40ma of current an Arduino pin will provide.

Here’s a schematic:

Here’s the Arduino code:

 //this sketch measures the light level of a room when powered up, sets a thresshold value, and waits for lights to be turned on to trigger the servo.
#define LDRpin 0
#include <Servo.h>
Servo myservo;
int AlarmHasSounded = 0;
int LDRval = 0;
int ThreshholdValue = 0;
void setup() {
 Serial.begin(9600);
 myservo.attach(11);
 myservo.write(90);
 ThreshholdValue=analogRead(LDRpin); //get original light level of the room
 delay(60000);

}
void loop() {

 LDRval = analogRead(LDRpin);
 Serial.println(LDRval);
 delay(100);
if (LDRval > (20+ThreshholdValue) ) {
 if (AlarmHasSounded == 0) { //check to make sure alarm has not sounded yet
 delay(3000); //how long to wait from the time of lights turning on to triggering the servo
 myservo.write(0);
 delay(1000);
 myservo.write(90);
 AlarmHasSounded = 1;
 Serial.println("Alarm Triggered!");
 }

}

}

The code above will need to be modified for your particular ambient light settings.  Depending on how much the amount of light fluctuates under normal conditions, you will need to modify the line that contains :

if (LDRval > (20+ThreshholdValue)

where the value ’20’ is a representation of the fluctuation you expect.

Additionally, you can modify the code to sense a laser beam from a laser pointer such that it acts as a trip-wire, as shown below:

Here’s a tip if you wish to do the laser tripwire thing, wrap some black electrical tape around a drinking straw and cover the photocell with it.  That way, the photocell will not be receiving much input from stray ambient light and it makes your program much easier to tune.  You could use this for the regular light-sensing alarm code posted above as well if you needed to shield the photocell from a specific light source.

-shane

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>