I want to build a laser trip wire with my 9 year old son and hook it up to an old fart machine speaker we have. I am brand new to Arduino. Any tips on what parts to use, tutorials, etc would be appreciated!
Or if Arduino is overboard for this type of project, let me know!
What electronics skills do you have? E.g. Can you solder? Can you build a 555 timer circuit on proto board from a schematic? Have you used a breadboard to construct simple circuits?
I Googled for "laser trip wire project", it seems like a popular topic with many hits. Your answer to my question above would affect which projects would be a match for your skills.
Is this just a one-off gag project or something you'd like to build off like an install you might use for more than 10 minutes?
I prefer using LDR modules with a digital out signal. You can use a simple LDR (light dependent resistor) and analogRead(laserSensor); but you'll have to experiment around with lighting conditions and changing values in your Arduino sketch to get consistent results, which can be difficult at the best of times because lasers jostle off target very easily.
With the digital out LDR module, there should be a built in LED and adjustment potentiometer, at least. So you just keep polling the sensor and if the laser is interrupted, clean trigger. Adjustment is a snap since you just use a small screwdriver to turn the potentiometer slowly and wait for the built in LED indicator light to turn on in the presence of the laser.
They also have modules with relays built in (I have not personally used one like this though) and depending on the speaker you're outputting to and how it works, might be very easy to set up. Can't know without knowing your speaker more.
It's quite doable though. My most popular Hallowe'en attraction in my Haunt is by far the laser maze.
Google this and you should be able to find the 5 pack of modules I use.
Can't stress enough what a game changer the digital signal out modules are compared to the analog out kind.
5PCS Photosensitive Sensor Module, Digital Light Detection Photoresistor Sensor Module for Arduino Smart Car Robot
Here's a chopped down version of my laser maze (the Arduino side anyway) that should point you in the right direction. The comment about the powerswitchtail refers to a product of the same name that comes prebuilt with a relay attached to an AC cord to allow users to easily and safely interface an Arduino to something that runs off AC mains.
If you use just a DC-DC relay, the code will work the same. The alarm timer bit is specific to my install, for the flashing red light and to let the attached PC (not needed for this snippet) know when to stop playing the alarm audio.
const int sensor1 = 2;
const int relayPin = 9; //pin 9 attaches to powerSwitchTail, UNO R3 pin to PST in+; Arduino gnd to PST in-
int lightSensorState, relayState;
unsigned long currentMillis, previousMillis, alarmTime, lastAlarmTime;
const long countdownInterval = 10; //this times alarmTimer = 2000/1000 total time alarm sounds
int alarmTimer = 100; // controls length of alarm sound
bool sensorTripped = false;
void setup() {
Serial.begin(115200);
pinMode(sensor1, INPUT);
pinMode(relayPin, OUTPUT);
resetVariables();
}
void loop() {
readSensors();
handleSensors();
}
void readSensors() {
if (digitalRead(sensor1) == 1) {
sensorTripped = true;
}
}
void handleSensors() {
if (sensorTripped == true) {
static uint32_t previousMillis = 0;
if (millis() - previousMillis > 100) {
previousMillis = millis();
lightSensorState = 1;
}
sensorTripped = false;
}
switch (lightSensorState) {
case 0:
relayState = LOW;
digitalWrite(relayPin, relayState);
break;
case 1:
Serial.println("alarm");
relayState = HIGH;
digitalWrite(relayPin, relayState);
while (alarmTimer >= 0) {
alarmTime = millis();
if (alarmTime - lastAlarmTime > countdownInterval) {
lastAlarmTime = alarmTime;
alarmTimer--;
}
}
if (alarmTimer <= 0) {
Serial.println("off");
alarmTimer = 200; // reset timer for next alarm event
relayState = LOW;
digitalWrite(relayPin, relayState);
lightSensorState = 0;
}
break;
default:
break;
}
}
void resetVariables() {
lightSensorState = 0;
relayState = LOW;
}
Oh yeah, very important tip: make sure the wires you use for the LDR module are long enough to give you a few inches of slack and make sure the modules themselves can be easily detached and reattached to your wall or whatever.
It's a LOT easier to align the laser by moving the LDR module, as opposed to trying to aim the laser across a room or doorway to hit the LDR.