Introduction: LED Lamp Controlled Through a Relay and Cayenne
This Instructables shows you how to turn on/off a lamp, or any other electrical device, with a Raspberry Pi, Cayenne, and a relay module.
Before we start note this: 120VAC IS DANGEROUS! DO NOT TOUCH WIRES FROM THE LAMP WHILE IT IS POWERED ON! Make sure the power is off when making your project. Also, make sure the wires do not short or touch anything flammable or they could start a fire.
Step 1: What You Need
You will need the following:
- Raspberry Pi (I used the 3rd one)
- Laptop or smartphone to use Cayenne app
- Relay Module (I used a '2 Module Relay')
- Some female to female wires
- Thing to control (Lamp in this case)
Step 2: Putting It Together
Connect the components as shown in the picture or as written below:
- GND on raspberry pi <> GND on relay
- 5v on raspberry pi <> VCC on relay
- GPIO13 on raspberry pi <> IN1 on relay
- COM on relay <> 1 hotwire from 120VAC
- NO or NC on relay <> 1 wire from lamp
- Other hotwire from 120VAC <> other wire from lamp
And most importantly!
Step 3: Setting It Up in the Cayenne App
Make sure Cayenne is connected to your Raspberry Pi first.
In the Cayenne home dashboard hit the plus sign up top to add a new project and put a name for it in.
Next, hit 'Add new" on the left side and select 'device/widget'.
Then select 'Light' > 'Lightswitch' and use the settings in the second picture shown above.
Now you should see a clickable widget on your dashboard that you can toggle on and off.
Step 4: And You're Finished!
Make sure you have:
- Cayenne linked to your Raspberry Pi
- A toggleable light switch button on your Cayenne dashboard
- Your Raspberry Pi, Relay, and Lamp connected
Once everything is in place just power your Rasberry Pi on (you don't need a monitor) and wait about 30 seconds for it to turn on.
Now try pressing the light switch toggle button and see that magic happen!
Here is a gif of it in action http://imgur.com/a/RpUnO
Thanks for checking this project out! Leave and questions in the comments.