This project was part of the Lane Tech HS Physical Computing Lab course. I created this project as part of the Home Automation / IoT project.
Before beginning with the tutorial, I want to put a warning that the relay portion of this project should be handled with caution and be very dangerous. You will be working with 120 V from the wall and can electrocute yourself if not done well. Please work with an electrician or a trained teacher.
Part 1: The RelayFor this project, it is ideal to use a cheap extension cord because you will be cutting it and changing it permanently. It does not matter which one you use but I got this one from a Dollar General. You'll need the extension cord and a relay.
1. Find out what side of the extension cord is power and separate the two to make it easier. We want to cut power because we're controlling the power given to the extension cord.
2. Next cut the power cord (not ribbed) with wire clippers and strip each end of wire a little. You don’t want the wires to stick out of the relay without the plastic covering but you can always cut it shorter.
3. Twist the ends very tightly so that all the smaller wires inside become one. This part has to fit inside the relay so make sure it tight and won’t come apart.
4. Lightly tin each exposed end with solder using the soldering iron to ensure that the smaller wires won’t come apart.
5. The next step is to unscrew the top of the relay to loosen where the cord will go into. Do not loosen it too much or pieces of the relay will begin to fall out. For this project we will be putting the side attached to the plug going into the wall into common (the hole in the middle) and the side where the appliances will be plugged into in normally opened (the hole on the left or NO). This will allow the cord to be off until we tell power to run through it. Shove each side into the correct slots until there is no more wire showing and tighten the screw so that the cords will not come out.
6. This is it for the relay/extension cord part and wiring the relay to the Photon requires female/male jumper wires that go into the pins on the other side of the relay into the breadboard. GND goes to ground, VCC goes to power (3v3), and IN goes into D6 which is the input pin. At this point, uploading the attached code for testing the relay would be a good idea.
In terms of controlling the relay via Internet, I used the Particle App to call a function that would turn the relay on and off. In order to do this, you must have a Particle account that is attached to the Photon you are using in order to call the function. The function is written into the code and has the argument "on", "off", and "loop". "on" and "off" work as a master switch that stops the loop and sensor from running so there does not have to be a person tripping the sensor to activate it or turn it off. "loop" simply turns the sensor and loop "back on".
This next part is the burglar alarm. You could use these two parts separately or only do one but they work well together as well. For the burglar alarm you will need an IR LED (IR Emitter), a IR Receiver (Photo Diode), a piezo buzzer, a 3.3V coin battery with it's holder.
1 . The first and easiest thing to do is wire up the Piezo Buzzer. You just connect the positive side to power and the negative to ground. I placed a piece of masking over it to amplify the sound.
2. Next is wiring the photo diode. Photo Diodes give analog values so you have to use an analog pin on the Photon. There are only so many pins on the Photon that read analog so you have to do your research for the microcontroller used. On the Photon, A0 works perfectly. Because I needed the Photo Diode outside of the bread board, I used female/male jumper wires to connect the positive of the diode to A0 and the negative to ground.
3. The third step is for the IR LED. A simplifed explanation of how IR LEDs and Receivers work is that the IR LED emits Infrared Light that cannot be seen by the naked eye when turned on. Then, a photo diode can capture this light and will change its resistance while conductive voltage from this light. So, these two can be used to sense things or be assigned certain jobs when enough voltage is created.
There are two most common forms of using IR LEDS with a Photo Diode. One is putting them right next to each other so that objects near it can reflect the IR light into the photo diode and sense an object is near. The second is putting the two components directly in front of each other as a break beam so that it senses an object in between the line. We will be using the latter as an object/person detector.
So, in order to make this break beam, I needed the IR LED to be far away from the breadboard and on its own circuit. To do this, and not take up another breadboard, I used a scrap piece of PCB to solder the LED, 100 ohm resistor, and the battery holder to create its own circuit. Pay attention to which side is meant to be soldered on and which side is for the components or you will burn the PCB. I soldered the resistor straight onto the positive sides of the of the batter holder and LED. And I used a solid core wire to create the connection between the negative sides.
4. The final step is assembly! I used two cardboard boxes for the enclosure: one for the photo diode and another for the IR LED. In order to make the break beam, I measured out and placed holes at the exact height and length away from the same edge facing each other. I hot-glued the photo diode to the hole and taped the PCB to the other box.
In testing each step of the Burglar alarm and fixing minor details, it worked great because I wasn't testing the range of the IR LED and the photo diode. But, when I assembled the whole project, I only got the beam to be 5-10 inches long before the photo diode did not catch the IR light. This was a bummer because it makes the alarm a lot less discrete but I am actively looking for the solution and will update the project when I find a fix.
That's all! If you have any questions, you can ask me msthomas8@cps.edu :)
Comments