Simple keyboard using the tone() function using Arduino

keyboard

This example shows how to use the tone() command to generate different pitches depending on which sensor is pressed.

 

Circuit

keyboard

Connect one terminal of your speaker to digital pin 8 through a 100 ohm resistor, and its other terminal to ground.

Power your three FSRs (or any other analog sensor) with 5V in parallel. Connect each sensor to analog pins 0-2, using a 10K resistor as a reference to groud on each input line.

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic

keyboard Schematic

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Code

The sketch below reads three analog sensors. Each corresponds to a note value in an array of notes. IF any of the sensors is above a given threshold, the corresponding note is played.

 

Leave a Comment

Your email address will not be published. Required fields are marked *