Hi there! I created this project for my Physical Computing class. In this instructable I hope you will find it easy to create your very own motion sensing lamp for your desk, room, or anywhere else you choose! I tried my best to make this project accessible and easy for everyone. Instead of using an expensive Arduino Ethernet Board or a hard-to-set-up wifi-shield, I used a regular Arduino Uno and connected it to my pc using a serial USB connection with a little help from the Cayenne IoT environment. Let's get started:
Step 1: Wiring
Wire up the PIR motion sensor and RGB Led as shown from the diagram above. Once done wiring the PIR motion sensor, it should be connected to GND, power, and pin 2. The RGB Led is a bit more tricky since each color actually connects to three separate pins and one lead connects to ground. The longest lead is called the common anode, this is the one that is connected to GND on the diagram. I have color coded the wires so that it is easier to keep track each color's assigned pin. After correctly wiring the RGB led, red should be connected to pin 6, green to 5, and blue to 3.
Step 2: Setting Up Arduino on Cayenne
Cayenne and your creativity will take over from now on, all you will have to do is set up an account here. After you have signed up for an account, Cayenne will prompt you to select your device. Once you select the option for Arduino, Cayenne will provide instructions. If you haven't done so already, you will need to download the Arduino IDE and then add the Cayenne library. Make sure you have selected the correct port for your Arduino and click next. Cayenne will proceed to ask what kind of Arduino you are using, select Arduino Uno from the list and then select Serial USB Connection as your form of connecting to Cayenne. We are using a serial USB connection since we aren't using a wifi-shield or ethernet board.
NOTE: Just because I have chosen to use an Arduino Uno doesn't mean you can't use an internet enabled Arduino. Cayenne will guide you through the set up process. I have opted for a simple USB connection because I was having trouble when trying to connect using a wifi-shield.
Step 3: Programming
When you select Serial USB Connection, Cayenne provides you with a sketch of the code you will need to upload from the Arduino IDE. This is an example of the code from github. Note that you will need to use the one Cayenne provides you since it includes your unique authentication token to allow your Arduino to connect to your account online.
Copy and paste the code into a sketch in the Arduino IDE. Cayenne controls your PIR motion sensor and RGB Led without you having to write code for what it should do. All you will need to assign are the pins. Add these to your sketch right now.
const int RED_PIN = 6;
const int GREEN_PIN = 5;
const int BLUE_PIN = 3;
const int MOTION_PIN = 2;
As a windows user I will go through the process for connecting through Windows, I tried making this work on a mac but I was out of luck.
Make sure you have uploaded your sketch and that you have set up all your pins. Read the instructions for connecting provided in the comments at the top of the sketch. All you have to do is open command prompt and typecd C:\Users\[YourUserName]\Documents\Arduino\libraries\Cayenne\extras\scripts to locate the scripts folder. Next, you will run the script by typing cayenne-ser.bat -c Port . Port will be the port your arduino is connected to, for example cayenne-ser.bat -c COM7. Once all this is run, the arduino will send all data to Cayenne. DO NOT CLOSE COMMAND PROMPT OR YOU WILL LOSE CONNECTION.
Step 4: Setting Up Widgets and Triggers!
Now that the complicated connection stuff is out of the way, it's time to tell Cayenne what to do! Feel free to experiment on your own or do what I did. First, you will want to click on "Add New.." in your dashboard. Then click on "Device/Widget." As you can see, Cayenne supports a great deal of devices. Search for motion sensor and then RGB led. Cayenne will guide you through setting these up, from adding graphs to show you motion activity to adding buttons to control your RGB Led. You can also add triggers. I created a trigger where the LED will shine red until I went ahead and reset the trigger through the Cayenne app. This is a very easy thing to do. You can also set it up so that you receive a text everytime the motion sensor detects motion. This can serve as a security feature that you can turn off when you leave home. These are just the few ways I chose to use triggers, let your creative self create new ways to interact with your lamp!
Step 5: Finalizing Your Lamp!
For my lamp, I decided to use a box to hold the encasing and a paper shell to hold the LED and motion sensor at the top. I am obviously not the most artistic person when it comes to creating lampshades so you can now let your imagination run wild and create a lamp that is unique to you! Good luck and thanks for creating with me.
Participated in the
Sensors Contest 2017