Tag Archives: LEDS

Programming RGB LEDs in a primary school

RGB LEDs are great. They can produce a range of colours depending on the amount of power give to each LED bulb. Once you have access to the colour codes, you can produce 256 x 256 x 256 colours. Which is a lot of combinations.

We use Scratch For Arduino. This allows you to easily edit the analog power outputs. Put in a delay and a repeat and you’ve got a disco. As it’s Scratch based, it’s easy to do for primary children.

Using the Raspberry Pi and Scratch to make LEDs light up

Simon Walters at Cymplecy has modified Scratch so it can be used to control the GPIO pins.

In this tutorial, I will show you how to control the LEDs through Scratch and the Pi.

Install Scratch GPIO

Follow the instructions at Cymplecy to install Scratch GPIO on your computer. Once installed, start it up and you’ll see it looks similar to Scratch.

Equipment

Breadboard

Resistors (typically about 50  ohm)

LEDS

Wires – female to male

Wiring

singleLEDforworkshop_bb

Note that the long leg on the LED is positive and needs to be on the side where the wire comes from the output pins.

The Pi has a number of GPIO pins for OUTPUTS. You can use 11,12,13,15,16 or 18. The odd numbers are on the left and the evens are on the right.

The code

Scratch has a BROADCAST function. You can create a BROADCAST message for the pins.

BROADCAST PIN11HIGH

or BROADCAST PIN11ON

So when you connect a function such as

WHEN SPACE BAR PRESSED, BROADCAST PIN11HIGH

piswitch

The LED will light up. If it does not work, check your wiring. If you connect the wire from Pin11 to Pin1, this supplies 3.3V and the LED will light up.

To turn the LED off,

BROADCAST PIN11LOW

or BROADCAST PIN11OFF

You can also control Power by creating a VARIABLE

Create a VARIABLE called Power11.

You can then set the VARIABLE to a number between 0 and 100.

variablePi

You can connect multiple LEDs by using a common GROUND.

multipleLEDforworkshop_bb

Once you have control over the LEDs, you can link it to the Scratch program and make things happen.

Instead of LEDs, you can use simple buzzers as OUTPUTS. Don’t use motors as they need more power than the Pi can supply.

Video tutorial for the  Arduino