Tuesday, March 15, 2016

A Musical Instrument with a Photoresistor - Scratch for Arduino (S4A) project

A project to make a musical instrument using the Arduino and Scratch for Arduino (S4A). The inspiration came from the theremin-like musical instrument project on s4a.cat

The version below uses a photoresistor. It is much simpler than the s4a.cat one and I have not used any LEDs either. I might add them in, as part 2 of the project.

A photoresistor (or light-dependent resistor, LDR, or photocell) is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits, and light- and dark-activated switching circuits. (Wikipedia)

By measuring the voltage drop across the photoresistor, and taking the corresponding reading on Analog0 sensor (A0), we can use the A0 values in our program. Adjust the amount of light falling on the photoresistor to change the A0 values - use a piece of paper or your hand to cover the photoresistor at different heights and angles. The idea is to write a program to play different musical notes corresponding to the different A0 value ranges.  

Wiring Diagram

The Program

The S4A code below uses the notes on the C Major scale - 8 notes from C to C, no sharps/flats. You can easily adjust the ranges for comparing the A0 values (use smaller ranges), and add in the sharps/flats also.


A short video of the musical instrument in action...

1 comment:

  1. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. John Anthony