Simple keyboard using the tone() function using Arduino

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

 

Circuit

Arduino Simple 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

Arduino Simple 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.

Here’s the main sketch:

/*
keyboard

Plays a pitch that changes based on a changing analog input

circuit:
* 3 force-sensing resistors from +5V to analog in 0 through 5
* 3 10K resistors from analog in 0 through 5 to ground
* 8-ohm speaker on digital pin 8

created 21 Jan 2010
modified 9 Apr 2012
by Tom Igoe

This example code is in the public domain.

http://arduino.cc/en/Tutorial/Tone3

*/

[box color=”#985D00″ bg=”#FFF8CB” font=”verdana” fontsize=”14 ” radius=”20 ” border=”#985D12″ float=”right” head=”Major Components in Project” headbg=”#FFEB70″ headcolor=”#985D00″]

Hardware Required

  • 8-ohm speaker
  • (3) force sensing resistors
  • (3) 10k ohm resistors
  • (1) 100 ohm resistor
  • breadboard
  • hook up wire

[/box]


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

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

Scroll to Top