杏吧原创

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鈥檚 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 鈥淕ND鈥, 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鈥檚 0 pin and ground. Go to the 鈥淢usic鈥 menu in the online micro:bit editor and find 鈥渞ing tone (Hz) Middle C鈥. Clip that into the 鈥渇orever鈥 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鈥檚 room.

Just kidding. We are actually going to use the micro:bit鈥檚 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鈥檚 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 鈥渘ote鈥. Grab 鈥渟et note to 0鈥 and clip it into 鈥渇orever鈥. Using 鈥渕ap鈥︹ from the 鈥淢ath鈥 menu and 鈥渓ight level鈥 from 鈥淚nput鈥, we can write a line that says 鈥渟et 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 鈥渞ing tone (Hz) Middle C鈥, but change the default 鈥Middle C鈥 to your variable, 鈥渘ote鈥.

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