Light up dream jar

Light up dream jar

As a child Roald Dahl's the BFG was one on my favourite stories. If you're not familiar with the story: a Big Friendly Giant visits children in their sleep and blows dreams into their bedrooms at night using a long trumpet and a jar of dreams that he caught in Dream Country. The dreams are lights inside that jar that change colour.

I decided to recreate the dream jar using a micro:bit and some RGB LEDs. I used bubble wrap in the jar to create the effect of a "dream" and it looks awesome! Below are instructions for adding one light but I think more would look good too.


  • A glass jar (I bought from St John’s Hospice charity shop for 50p)
  • Some bubble wrap
  • micro:bit
  • 1 x CodeBug GlowBug
  • 3 x crocodile clips, preferably white.


  1. Connect the crocodile clips from the micro:bit to the GlowBug


micro:bit Glow Bug
3V 5V

The micro:bit can power 5V lights with its 3V pin. It can power up to 8 of them



Add the Neopixel package

Before putting everything in the jar, let's code it!

  1. Go to
  2. Add the Neopixel package
    1. Select Advanced
    2. Select Add Package
    3. Select Neopixel


Setup the lights

  1. Create a variable called lights
    1. Select Variable
    2. Select Create New Variable
    3. Type "Lights"
    4. Select OK


  1. From the Variables menu drag out "Set item to 0"
  2. Connect it under "On start"
  3. Change item to Lights
  4. From the Neopixel menu select the first block "Neopixel at pin 0.."
  5. Drag this out onto 0
  6. Change 24 leds to 1


Turn the lights on

  1. From Input select "on shake" and drag it onto the screen
  2. From Neopixel select "item show color red" and place it under on shake
  3. Change item to lights
  4. Change red to whatever colour you want
  5. Add a test block to make sure Shake has happened: select Basic
  6. Select "show icon" and choose an icon
  7. Put it in "On shake"


Download and test the code

  1. Plug in your micro:bit
  2. Select Download
    1. In Chrome the file will go to your Downloads folder. Go to your Downloads folder and drag your file onto the micro:bit
    2. In Internet Explorer it will ask you where to save your file to. Select "Save As" then select the micro:bit
  3. Shake your micro:bit
  4. Ta-da!


Plug the micro:bit into your computer using a USB cable then shake it - did it work?
1. Yes: Your battery pack isn't working - does it have an on/off switch? Does it need new batteries?
2. No:
1. Check your code - have you changed item to lights?
2. Check the connections from your GlowBug to your micro:bit. With the same colour crocodile clips it's very easy to get them mixed up.

Finish Assembly

Now your micro:bit is coded:

  1. Secure the crocodile clips onto the micro:bit using tape
  2. Plug the battery pack into the micro:bit
  3. Wrap the micro:bit and battery pack in bubble wrap
  4. Line the jar with bubble wrap
  5. Place the micro:bit in the jar
  6. Put some bubble wrap in the jar
  7. Place the light in the jar
  8. Put some more bubble wrap in the jar
  9. Test your setup to make sure it still works!

More Code

You can change the lights to lots of different colours, just add a pause between every time you "show color", e.g.

Or use loops to keep changing the lights over and over again

To turn off the lights you need to use lights clear followed by lights show:

What pattern are your dreams going to show? What does a nightmare look like?

Full Code

Full Code (MakeCode2)

Related Article