£199.99 £139.99 for one year of Unlimited learning. Offer ends on 28 February 2023 at 23:59 (UTC). T&Cs apply

# Connecting sparkle lights using a crumble microcontroller

Learn how to connect a Sparkle RGB LED (which stands for Red, Green, Blue Light Emitting Diode) to a Crumble, and control it using code.

Using a Crumble gives you more control over your components than a simple switch.

In this article, we will show you how to build a circuit including a component that requires a microcontroller to use: a multi-coloured LED known as a Sparkle.

## How to use a Crumble Sparkle

Crumble Sparkles are multi-coloured lights made especially for the Crumble microcontroller.

A Sparkle contains an electrical component called an RGB LED, which stands for Red, Green, Blue Light Emitting Diode.

This means that the Sparkle can create nearly 17 million different colours by combining different amounts of red, green, and blue light. You can use the Crumble software to set how much red, green, and blue light the Sparkle will emit, to pick one of these colours.

To use a Sparkle, you need to connect it to your Crumble in the correct way. The Sparkle connects to the positive (+), negative (), and signal (D) terminals on the Crumble microcontroller.

### Connecting the Sparkle to a Crumble

1. Look at the Sparkle to see which way the two small arrows are pointing. The side the arrows are pointing to is the right side. Rotate your Sparkle so the D is at the bottom and the arrows are pointing right.
2. Use a cable with crocodile clips to connect the positive terminal (+) on the right side of the Crumble to the positive input (+) on the left side of the Sparkle.

1. Use another cable with crocodile clips to connect the negative output (-) on the right side of the Crumble to the negative input (-) on the left side of the Sparkle.

The positive and negative connections you have made so far create a circuit, which supplies power from the Crumble to the Sparkle.

1. Finally, make the signal connection, which is used by the Crumble, to set the Sparkle’s colour. Use another cable with crocodile clips to connect the D terminal on the right side of the Crumble to the ->D-> input on the left side of the Sparkle.

Note: The signal connection must always be to the D terminal on the Crumble. Sparkles don’t work if you connect them to any other terminal on the Crumble.

Great! Your Sparkle is now fully connected, and it is time to light it up.

The image below shows the Crumble software programming environment. It is a little like Scratch, but there are only six types of blocks, and only one starting block, which is called the program start block.

1. In the Crumble software, drag the program start block into the program workspace.

Every code block that you connect below the program start block is part of your program. When you click on the green triangle button, your program is sent to the Crumble and run.

Any blocks in your workspace that are not connected to the program start block are not part of your program.

1. Click on the Sparkles button to open the Sparkle code block palette and have a look at the Sparkle coding blocks.

There are three different types of Sparkle blocks that you can use:

• set sparkle to with a colour picker box

• turn sparkle off

• set sparkle to with three fields for red, green, and blue values

For each block type, there is a version for a specific Sparkle and another for all Sparkles!

1. Drag a set sparkle to block with a colour picker box into your workspace, and connect it below the program start block.

2. Click on the new block’s colour picker box (this is always red by default) to make a colour picker appear.

Note: The colour picker may look different depending on the type of computer you are using.

3. Choose a colour for your Sparkle and click on OK.

Your code should now be complete and ready to try. Click on the green triangle play button to run your code. At the top of the window, you should see the message Programming successful. If you don’t see this message, you need to check the USB connection between your Crumble and your computer and then try again. If your program is successful and your wiring is correct, the Sparkle will light up.

## Saving a program on the Crumble

Once you’ve got the Programming successful message, your program is stored on the Crumble and will remain there even when the power is disconnected. When you connect a Crumble to a battery pack, it will automatically run the program that is stored on it, regardless of whether the USB cable is connected. To change the program stored on a Crumble, you will need to connect it to your computer and use the green triangle play button in the Crumble software to send a new program to it.