91ɫƬ

How to make a theremin with a light sensor

Hannah Joshua shows how to make a theremin with an easy microbit program and light sensor

New stuff you need
If you have the parts for previous projects, you will have everything required.

NOW that our circuits are getting smart, it is easy to think that just using a micro:bit microcontroller is as good as it gets. But while it does have an impressive range of components, we can augment it with extras.

The micro:bit’s gold strip is where the magic happens. It is split into 25 bands, called pins, which are connection points to the internal electronics. Extra components are usually linked to one of these, along with the part in the corner marked “GND”, or ground, making a circuit through the micro:bit. The device directs the electricity flowing through the pins to control your addition.

Take your piezo buzzer, and use a couple of crocodile clips to attach it to the micro:bit’s 0 pin and ground. Go to the “Music” menu in the online micro:bit editor and find “ring tone (Hz) Middle C”. Clip that into the “forever” block in the workspace, so it plays continuously, and upload the program to your device. Unplug it from the computer and attach the 3-volt battery. This way, it will be easier to hide the noisy gadget in a housemate’s room.

Just kidding. We are actually going to use the micro:bit’s light sensor to make a – a musical instrument that you play without touching. Sensors take an input from the environment and convert it into electrical impulses. The micro:bit’s light sensor is made of a material that changes electrical resistance according to the light level. This adjusts the current flowing through it. We can use the output of the light sensor to pick a note for the buzzer to play.

Trouble is, the readings on the light sensor go from 0 (total darkness) to 255 (full brightness). We want to shift this range to correspond to note frequencies.

In the code editor, start a new project and create a variable called “note”. Grab “set note to 0” and clip it into “forever”. Using “map…” from the “Math” menu and “light level” from “Input”, we can write a line that says “set note to map light level from low 0 high 255 to low X high Y”, where X and Y are the frequencies of the lowest and highest notes you want your theremin to play. Mine goes from 262 hertz (around middle C) to 523 hertz (an octave above). Try those numbers as your X and Y. Beneath this block, add another “ring tone (Hz) Middle C”, but change the default “Middle C” to your variable, “note”.

Once you have onto the micro:bit, you can play your theremin by moving your hand to block out more or less light, or by shining a torch towards it. You could also reverse the scale or add more octaves.

You could even try a different sensor. For instance, a sonar sensor allows you to use distance rather than light. Let us know what you come up with.

To download a printable version of this page click here

Thanks to Imperial College Advanced Hackspace for use of their facilities


For next week

Continuous rotation servo (The 6-volt kind is fine, see website for details)

Sound sensor

Disco ball

Next in the series

1 Introduction

2 Electric candle

3 Toast notifier

4 Desktop traffic light

5 Propeller car

6 Magic 8 Ball

7 Theremin

8 Sound-sensitive disco ball:It rotates when the music starts

9 Rubbish sweeper

10 Biscuit bot

Projects so far and a full list of kit required are at
Email:maker@newscientist.com

Article amended on 18 June 2019

We corrected which pins of the micro:bit circuit board the piezo buzzer should be connected to

Topics: Electronics