Skip to main content
shopping_basket Basket 0
Log in
PLAY MUSIC? No, execute sound!

Parts list

Qty Product Part number
1 Arduino Starter Kit with UNO board 761-7355
1 Parallax Inc 28015, PING))) Ultrasonic Distance Sensor Module 781-3020
1 RS Pro 8Ω 0.08W Miniature Speaker 22.5mm Dia. , 6mm Lead Length 22.5 (Dia.) x 8.5mm (LxWxD) 724-3100
1 Ultimaker 3 3D Printer 124-9474

Arduino Based Air Guitar


Music is an important element of modern society. Many people love music but they feel hesitant in trying those instruments. So, why don't we lower the level of skill required to pick up a tone using string, woodwind, bronze, or wind instruments, or even, using a keyboard?

This guitar only requires that people love electronics and have two hands. It is not a keyboard, it's a motion instrument with no strings or keyboard. We use a different level of height to manage the sound. Its outlook is a stand with the marks of note.



Ping sensor-ultrasonic sensor used the sound wave to determine the distance of the object and the sensor between 30mm to 3m.



This uses Arduino IDE as the main platform.

Mechanical software - a 3d concept helper

It is really easy to use! For more information, please refer to this link.aaa_7a22bd3cd4ea87dbd2af4b3ef6248fd4d38c41c1.png



Firstly, we include LiquidCrystal for our LCD display control and the pitches. Here is the demo of scaling the note of sound.

The melody array is the tone frequency, and the note durations array is the time of the tone, 4 is crotchet and 8 is a quaver.

The period of the note is controlled by a PWM based program behind the Tone() function.

We have to wire the LCD display, Speaker, LED, Button, and Ping sensor to the Arduino by following digital pins.

LCD display rs is linked to pin 12, en is linked to pin 11, d4 is linked to pin 5, d5 is linked to pin 4, d6 is linked to pin 3, d7 is linked to pin 2.

A 10k changeable resistor is linked to +5V and GND, and, the vo link to the 10k  output. A 220ohm resistor is linked from 5v VCC to d15, d2 is linked to VCC also, and, d1, d5 and d16 are linked to the ground.

Ping sensor is linked to pin7, and 5v VCC and Ground.

Button is linked to pin9 with a 110ohm resistor connected to VCC and a pin of the button is linked to the Ground.

#include <LiquidCrystal.h>
#include "pitches.h"
int melody[] = {
int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int pingPin = 7;
const int buttonPin = 9;  
const int ledPin = 13; 
int ledState = HIGH;          
int buttonState;            
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;  
unsigned long debounceDelay = 50;

Here is the setup of the LCD display and the pin mode of the led and button pin.

The pin mode is set the Arduino digital pin as output or input.

void setup() {
  lcd.begin(16, 2);
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, ledState);

Here is the main program, we are setting up a debouncing button.

If we are not pressing the button the melody will not be given out and the led state will not be changed.

When the button is pressed the melody will be played and the led state will be changed.

void loop() {
  int reading = digitalRead(buttonPin);
  if (reading != lastButtonState) {
    lastDebounceTime = millis();
  if ((millis() - lastDebounceTime) > debounceDelay) { 
    if (reading != buttonState) {
      buttonState = reading;
      if (buttonState == HIGH) {
        ledState = !ledState;
          for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    // stop the tone playing:

We are now calling the function of the ping sensor.

The ping sensor is the crux of this share, and we set up the cursor from column one, row one.

  long duration, inches, cm;

  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  digitalWrite(pingPin, HIGH);
  digitalWrite(pingPin, LOW);
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);

  lcd.setCursor(1, 1);

  lcd.print("in, ");
  lcd.print("cm           ");

  digitalWrite(ledPin, ledState);
  lastButtonState = reading;
    lcd.setCursor(0, 0);

Here we scale the stand height and divide it in 2 full melody platform.

  int note_Duration =2000/4;  
  if (cm>34)  {noTone(8);lcd.print("Welcome"); }  
  if (34>cm&&cm>=32)  {lcd.print("NOTE_C6");tone(8, NOTE_C6, note_Duration);}
  if (32>cm&&cm>=30)  {lcd.print("NOTE_B5");tone(8, NOTE_B5, note_Duration);}
  if (30>cm&&cm>=28)  {lcd.print("NOTE_A5");tone(8, NOTE_A5, note_Duration);}
  if (28>cm&&cm>=26)  {lcd.print("NOTE_G5");tone(8, NOTE_G5, note_Duration);}
  if (26>cm&&cm>=24)  {lcd.print("NOTE_F5");tone(8, NOTE_F5, note_Duration);}
  if (24>cm&&cm>=22)  {lcd.print("NOTE_E5");tone(8, NOTE_E5, note_Duration);}
  if (22>cm&&cm>=20)  {lcd.print("NOTE_D5");tone(8, NOTE_D5, note_Duration);}
  if (20>cm&&cm>=18)  {lcd.print("NOTE_C5");tone(8, NOTE_C5, note_Duration);}
  if (18>cm&&cm>=16)  {lcd.print("NOTE_B4");tone(8, NOTE_B4, note_Duration);}
  if (16>cm&&cm>=14)  {lcd.print("NOTE_A4");tone(8, NOTE_A4, note_Duration);}
  if (14>cm&&cm>=12)  {lcd.print("NOTE_G4");tone(8, NOTE_G4, note_Duration);}
  if (12>cm&&cm>=10)  {lcd.print("NOTE_F4");tone(8, NOTE_F4, note_Duration);}
  if (10>cm&&cm>=8)   {lcd.print("NOTE_E4");tone(8, NOTE_E4, note_Duration);}
  if (8>cm&&cm>=6)    {lcd.print("NOTE_D4");tone(8, NOTE_D4, note_Duration);}
  if (6>cm&&cm>=4)    {lcd.print("NOTE_C4");tone(8, NOTE_C4, note_Duration);}
  int pauseBetweenNotes1 = note_Duration * 1.30;

This is the function of the ping sensor. We could find the following program code in the Arduino example. 

long microsecondsToInches(long microseconds) {return microseconds / 74 / 2;}
long microsecondsToCentimeters(long microseconds) {return microseconds / 29 / 2;}

Future Development

This is an engineer's musical instrument. We love music and we love electronics, why don't we combinate both elements to make something fun to play?

It is just a concept of an air motion instrument, there is room for improvement in sound quality, notes capacity and the art of delivery.

Hope you all enjoy this little tool as the base for new ways to love music.


Brian0925 has not written a bio yet…
DesignSpark Electrical Logolinkedin