This instructable is based on the Spark.io Photon, a "postage stamp-sized hackable WiFi module for interacting with physical things." And thanks to its AWESOME mobile UI "Tinker," you won't have to write a line of code!
Its the result of an "Instructables Build Night," with Soha Smart; where I am also a board member and teacher.
We are going to control a 12V Solenoid using one pin from this Arduino based device.
Step 1: Setup your Spark.io Photon
New Device with Tinker Firmware
If you're just taking your Photon out of the box you're going to need to name your core. The easiest way to do this is on your mobile device (I used an iPhone). I'm not going to go over how do this, since Spark.io documentation is fairly easy to follow.
So, to get up and running go to http://www.spark.io/start/
Restoring Tinker (recommended for this project)
To restore your device to use the "Tinker" firmware please follow the instructions located at http://docs.spark.io/tinker/#tinkering-with-tinker-the-tinker-firmware
Step 2: Wiring the circuit
Note: You're going want to setup your breadboard with a 12V rail (the side red and blue lines) and a 5V rail. The 12V is to run the solenoid and the 5V will power the Photon
Using a diode?
In the diagram, there is a diode parallel to the device we are powering. Any time you are powering a device with a coil, such as a relay, solenoid, or motor, you need this guy, and don’t leave home without it. What happens is when you stop powering the coil, a reverse voltage, up to several hundred volts, spikes back. This only lasts a few microseconds, but it is enough to kill our transistor. So this diode (only allows current to pass one way) is normally facing the wrong direction and does nothing. But when that voltage spikes comes flowing the opposite direction, the diode allows it to flow back to the coil and not the transistor.
...A transistor (TIP120) too?
Transistors are are 3 lead components that have 2 simple functions, to switch or amplify (this time it's setup as a switch). You basically have an "in" called theCollector, an "out" called the Emitter, and a "controller" called the Base. When you send a HIGH signal to the base (control pin), the transistor switches and allows current to flow from the collector (in) to the emitter (out).
So we connect it so that our solenoid is connected to V+ but not ground (V-). Ground is connected to the transistor’s collector. When our Photon sends a HIGH signal to the transistor’s base, it switches the transistor (connecting the collector and emitter) and completes the circuit for the solenoid.
We are using a 2.2K resistor to limit the current to the correct value to run the transistor.
Is the Solenoid pushy?
- To setup your solenoid to "Pull" connect the GREEN wire to V+ and the BLUE wire to the transistor's collector.
- To setup your solenoid to "Push" connect the GREEN wire to the transistor's collector and the BLUE wire to V+
- Basically, reverse the wires if the solenoid is working in the wrong direction...
Step 3: Tinkering with "Tinker" and the Photon - Unlocking a door!
Assuming that you can connect to your Photon from your mobile app. All that is left is to connect D6 in "Tinker" to write either HIGH or LOW.
- In "Tinker" tap on D6 and select "digitalWrite."
- Tap anywhere on the screen to confirm.
- Now tap on the D6 button. You should see the word "HIGH" next to the button indicating that the pin is "on."
Congratulations you just "Opened a door" with your Spark.io Photon!!! (assuming you attached the solenoid to a door's lock, that is...)
Step 4: Going further with your Photon!
Where do you go from here?
You might have noticed that the solenoid only either "pushes" or "pulls" based on how it is wired to the circuit. Creating an H-bridge within the current circuit will allow you to control both directions of the solenoid. Essentially, allowing you to "lock" AND "unlock" the door.
The possibilities are endless!