Connecting leds to your raspberry pi using cayenne
The first component that I will cover is the humble LED. A right of passage for all Raspberry Pi owners is to get a LED to blink using a few lines of code and some simple circuit building. With the use of Cayenne, the LED can be connected to the PI without the need for a single line of code to be written, and then can be controlled from a computer or smartphone anywhere in the world! Smart, huh?
What you'll need:
- Raspberry Pi and Computer/Smartphone set up with Cayenne from myDevices. (Installation instructions here)
- LED (Any Colour)
- 270Ω Resistor
- Pi T-Cobbler (Optional) (Find one here)
- Breadboard (Find out more here, and recap how they work)
- 2x Male to Male Jumper Wires
As the T-Cobbler is simply a way of connecting all of the Pi's GPIO pins to a breadboard, this is completely unneccessary, however it makes it a lot easier to connect the components, and as the system gets more complex with other components, it becomes more and more useful. Without a T-Cobbler, male to female jumper leads can be used to connect the individual GPIO pins to the breadboard for use with the components.
How to connect an led to cayenne
- Connect your Pi Cobbler to your breadboard as shown on the right.
- Connect the GND pin on the Cobbler to the negative power rail on the breadboard with a Male-to-Male Jumper wire.
- Insert the 270Ω Resistor into the negative power rail and row 4 of the breadboard. Then insert the short leg of the LED into the same row, and the long leg into row 5.
- Connect row 5 of the breadboard to #16 on the cobbler.
- Finally, connect the ribbon cable to the socket on the Cobbler, and to the Raspberry Pi's GPIOs, ensuring that the cable leaves the Raspberry Pi facing outwards.
The circuit diagram below shows the layout of the circuit.
(Pictures from left to right, top to bottom)
(These instructions based on using a desktop PC, however a smartphone could also be used)
- Log onto Cayenne on your desktop computer, and ensure that your Pi is powered on and connected to the system, as shown here.
- Navigate to the 'Add new...' menu in the top left of the screen, then click on 'Device/Widget'. Your screen should look like the screenshot on the right.
- Then click on the 'Generic' option in the 'Actuators' section.
- Next, select 'Digital Output'.
- Fill in the boxes, ensuring to select 'Integrated GPIO' in the 'Connectivity' box, and '16' in the 'Channel' option. When complete, the options should look like the screenshot to the right.
- Once complete, click on the 'Add Actuator' button. You should now be taken back to your dashboard where a new widget, like the one shown below, will be shown. Clicking on the button will toggle the LED between on and off.