RGB LEDs
Introduction
When construction the
virtual world demo we will use two different types of sensors
- an RGB color sensor giving us the color of a paper sheet
- an ultrasonic distance sensor determining the distance between the paper sheet and the sensor.
Before using this information however we will have to understand the sensors and their readout and as a preliminary experiment we will read the color of the paper sheet and light an rgb color LED with the same color. Switching to a paper sheet with a different color will also light the LED in the same different color.
There are quite a few different types of breakout boards implementing RGB LEDs on the market which have to connected to the controller in different ways. Most of them just consist of 3 LEDs of the base colors implemented in a single package. Some of the breakout boards however have the necessary current limiting resistors already on board while for others they must be provided externally.
There is also a type of "intelligent" LED where the RGB values are provided in a serial data stream.
 KY-009 SMD LED needing external resistors |
 LilyPad Tri Color LED |
 Standard 3 color LED with resistors on board |
 WS2812 "intelligent" LED |
For you information, here is the
WS2812 data sheet
Programming the LEDs
It is an excellent introductory exercise to try programming the LEDs and we will go about it in steps. First the device must be connected to the Raspberry Pi controller which is done through the cobbler and the bread board. Depending on the breakout board used we will need additional external 330 Ohm resistors on each of the color components (KY-009). Then we connect as follows:
- - -> Gnd
- red -> gpio 18
- green -> gpio 17
- blue -> gpio 22
This cabling is of course only true for the first 3 devices (not the WS2812). To check the device we can temporarily connect these pins to Vcc (make sure the current limiting resistor is there, either in the breakout board or externally added by you) in which case we should see the corresponding color come up on the LED. Once connected to the gpio pins we can start programming.
Making a LED light up is one of the most simple programming exercises possible and therefore ideally suited to get us going with Python program.
--
Uli Raich - 2018-01-30
Comments