
Here is a wire you can not trip on.
Replace the ‘wire’ with a laser.
A photocell is the target for the laser pointer:


When the laser lands on this voltage divider target, the voltage measured at the Arduino is below the threshold, and the alarm is silent. But when the laser does not hit its intended target, the voltage is above the threshold, and the alarm sounds.
The sound is generated from the Arduino itself using the tone() function. The output (audio) is connected to a piezo speaker mounted to the top of the enclosure. The red momentary button resets the alarm if it has been triggered. It also tests the speaker to allow the user to set the audio level.

Three signals are needed outside the enclosure: +5V, ground, and the sensor’s output. The unit is designed to be indoors, with the sensor and laser pointer outside, so a standard, three conductor extension cord is used to travel the ~30m between the devices.

In the following demo, the audio level is set (button and potentiometer), the alarm is tripped, then reset (button).
CODE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
/* tripWire http://creativetechnical.ca/tripwire/ A laser pointer aimed at a photocell - break the path and an audible alarm is turned on. */ #define THRESHOLD 100 //threshold of the alarm trigger compensate for ambient/location light #define SENSOR_PIN A0 #define RESET_PIN A1 #define LED_PIN 13 #define SPEAKER_PIN 9 int sensorValue = 0; bool alarmState = 0; bool speakerState = 0; //////////////////////////////////////////////////////////////////// void setup() { Serial.begin(9600); pinMode(SENSOR_PIN, INPUT); pinMode(RESET_PIN, INPUT_PULLUP); pinMode(LED_PIN, OUTPUT); pinMode(SPEAKER_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); for(int pitch = 50; pitch < 5000; pitch++) { tone(SPEAKER_PIN, pitch, 40); // (pin, pitch, milliseconds) } } ////////////////////////////////////////////////////////////////// void loop() { speakerState = digitalRead(RESET_PIN); if (speakerState == LOW) { tone(SPEAKER_PIN, 300, 50); // (pin, pitch, milliseconds) } sensorValue = analogRead(SENSOR_PIN); Serial.println(sensorValue); if(sensorValue > THRESHOLD) { alarmState = 1; } while(alarmState == 1) { for(int pitch = 200; pitch < 400; pitch+=10) { tone(SPEAKER_PIN, pitch, 50); // (pin, pitch, milliseconds) } //3 sec delay once alarm has been triggered, but: //still reading reset button in those 3 seconds for (int i = 0; i < 300; i++) { alarmState = digitalRead(RESET_PIN); if (alarmState == 0) { break; //if reset button is pushed, don't wait } delay(10); } } } |