How can i combine these two instructables for halloween prop?

I am making a haunted house, and want my pneumatic props to be triggered once the laser beam is broken. I have followed the instuctable for a laser tripwire  https://www.instructables.com/id/Another-Arduino-Laser-Tripwire/ and the instructable for a 110v controller  https://www.instructables.com/id/Yet-Another-Arduino-110v-Power-Controller/ both work great seperately, however what i would like to do is have 4 lasers, and each one controls one of the 4 outlets. can anyone help me in code and schematic? i would greatly appreciate it.

Sam

sort by: active | newest | oldest
bwrussell5 years ago
The layout is pretty simple, just build and connect 4 trip wires and then connect the outlet controller.

The code is also fairly simple. Use a matching numbering system, laser 1 controls outlet 1, etc, and then use an if...then for each laser that in English says: if tripwire X is broken then turn on outlet X for T seconds. I would include something to prevent the laser from triggering in rapid succession, basically ignore any breaks for some time after the first break, to keep the props from jerking up and down if a group walks by. If you wanted to get really fancy you could write functions to cut down on the amount of code (assuming you can pass variables into Arduino functions, I haven't used one with Arduino) but even without them it should be fairly compact.
Basically if you were able to program them separately then you should be able to combined them with relative ease.
Zukibeast (author)  bwrussell5 years ago
Thank you for your reply, what you have suggested is basically what I have tried so far, I guess I should have included that I have attempted something similar to what you have recommended. I think my main problem is how would I wire it? If i were to follow the wiring "diagram" from the laser tripwire instructable but with 4 photo cells, things get screwy. what I think needs to happen is to basically follow the same diagram but add in diodes so that one photo cells readings arent affecting analog pin 1,2,3 and 4. not sure if that makes any sense or not.
You can define pins 8, 9, 10, and 11 as outputs and hook them up the four gang outlet pins per that instructable.

You could include four photocells connecting each to analog pins 0, 1, 2, and 3.

Then change the tripwire code to read each photocell and set the output pin if it has tripped. You'll need to change the code so that it does not 'delay(1000)' but notes the time and adds one second to it to tell the code when to turn off the outlets. Something like so:

int outletPin1 = 11;
int outletPin2 = 10;
int outletPin3 = 9;
int outletPin4 = 8;

long outlet_OFFTIME_1 = 0;
long outlet_OFFTIME_2 = 0;
long outlet_OFFTIME_3 = 0;
long outlet_OFFTIME_4 = 0;

void setup()
{
pinMode(outletPin1, OUTPUT); // sets the digital pin as output
pinMode(outletPin2, OUTPUT); // sets the digital pin as output
pinMode(outletPin3, OUTPUT); // sets the digital pin as output
pinMode(outletPin4, OUTPUT); // sets the digital pin as output
digitalWrite(outletPin1, LOW);
digitalWrite(outletPin2, LOW);
digitalWrite(outletPin3, LOW);
digitalWrite(outletPin4, LOW);
}

void loop()
{
if(analogRead(0) < 850) // Tripwire 1 activated
{
digitalWrite(outletPin1, HIGH); // turns on outlet pin 1
outlet_OFFTIME_1 = millis() + 1000; //lets hold the outlet on for 1 second
}

if(analogRead(1) < 850) // Tripwire 2 activated
{
digitalWrite(outletPin2, HIGH); // turns on outlet pin 2
outlet_OFFTIME_2 = millis() + 1000; //lets hold the outlet on for 1 second
}


if(analogRead(2) < 850) // Tripwire 3 activated
{
digitalWrite(outletPin3, HIGH); // turns on outlet pin 3
outlet_OFFTIME_3 = millis() + 1000; //lets hold the outlet on for 1 second
}


if(analogRead(3) < 850) // Tripwire 4 activated
{
digitalWrite(outletPin2, HIGH); // turns on outlet pin 4
outlet_OFFTIME_4 = millis() + 1000; //lets hold the outlet on for 1 second
}

// is it time to turn them off?

if (millis()>=outlet_OFFTIME_1)
{
digitalWrite(outletPin1, LOW); // turns off outlet pin 1
}

if (millis()>=outlet_OFFTIME_2)
{
digitalWrite(outletPin2, LOW); // turns off outlet pin 2
}

if (millis()>=outlet_OFFTIME_3)
{
digitalWrite(outletPin3, LOW); // turns off outlet pin 3
}

if (millis()>=outlet_OFFTIME_4)
{
digitalWrite(outletPin4, LOW); // turns off outlet pin 4
}
}


The photocells may be a little difficult to get right - be sure you get the right values when you experiment so that they are properly tripped both when it is dark and during the daytime.

Best Wishes
maewert maewert5 years ago
Opps:
digitalWrite(outletPin2, HIGH); // turns on outlet pin 4

should have read:

digitalWrite(outletPin4, HIGH); // turns on outlet pin 4
Zukibeast (author)  maewert5 years ago
I will have to try this tonight. I don't think I am doing the photocells correctly. In the tripwire ible mentioned above, only 1 is used. The directions say to connect 1 leg of the photocell to 5v, the other to a 10k resistor then to ground and also to analog pin1. Can I do that with 4 photocells? Wouldn't things get.messed up by connecting them all to 5v, ground and seperate analog pins? I would have to think that doing it this way will cause one photocells readings to effect all of my analog values. Am I right or wrong? Btw maewert grea t instructable on the 110v controller. My only suggestion is hot glue instead of epoxy.
The photocells act like variable resistors whose resistance changes based on how much light they are receiving. I have attached a diagram showing how you can wire two photocells up. They should not interfere wit each other this way. You can add more as you like.
tripwire.JPG
Zukibeast (author)  maewert5 years ago
You have made my day, and most likely my month. A million thanks Maewert. I wired up my photocells as you have instructed and after tweaking the values for the photocells it works without a hitch. And also thank you bwrussell both of you have been a great help. :) :)
I hope you post pictures of your build after you're finished. Sounds like it could be a lot of fun!