Student Projects

cancel
Showing results for 
Search instead for 
Did you mean: 

myDAQ Air Guitar

myDAQ Air Guitar

____________________________________________________0.png

Created By:

    • Jackie Leverett
    • Biomedical Engineer, The University of Texas at Austin
    • Engineering Leadership Program Intern

Introduction

The air guitar is an instrument men and women have been playing for centuries, but until now, no matter how hard you strummed, you just couldn’t wave your arms fast enough to make a sound.  Today, that all changes.  Using a myDAQ and LabVIEW, you will now be able to not only rock out to your own music, but also let other people hear it too!

Purpose

This tutorial will demonstrate how you can turn a myDAQ into an air guitar by programming it in LabVIEW.  This will help convey knowledge about accelerometers and sound output in LabVIEW.

Equipment

    • myDAQ
    • 2 Axis Accelerometer ($14.95 with breakout board)
    • 8 Push buttons ($0.30 each)
    • 8 Resistors: 12kΩ
    • Gloves

    Video Demonstration


  


0a.png

Setting up Hardware

This project uses 4 push buttons on each hand.  On the right hand, the 4 buttons determine which of 4 strings to play, and on the left hand, the 4 buttons choose which of 4 notes to play on each string.  Also on the right hand is an accelerometer which recognizes the strumming motion.  To begin setting up this hardware, solder a wire to each side of the push buttons.  One side of the button goes to a digital IO port, and the other side of the button goes to +5v.  Since there are 8 buttons, DIO ports 0:7 will be used.  Next, hot glue the push buttons to the bottom side of the fingers on each glove.  Bundle the mass of wires together so that it appears to be one long cord for ease of use. On the right hand, velcro the accelerometer to the top of the right glove.  Attach wires to the accelerometer and add them to the right hand’s cord of wires. The four wires attached to the accelerometer include: +5V, GND, XA, and YA.  XA and YA will be connected to Analog In pins 0+ and 1+, respectively. AI 0- and 1- are attached to ground.

1a.png1b.png

Figure 1: Left and right gloves with sensors

2.png

Figure 2: Bottom of left hand

3.png

Figure 3: Breadboard implementation

4.png

Figure 4: Multisim Schematic

Understanding A 2-Axis Accelerometer

An accelerometer is a device that can measure dynamic (vibration) and static (gravity) acceleration.  It is able to measure this acceleration using a sensor that is composed of a surface-micromachined polysilicon structure built on top of a silicon wafer.  Between the polysilicon and the silicon wafer are polysilicon springs that resist acceleration forces.  When acceleration is applied, the structure is deflected and measured with a differential capacitor, which outputs a voltage proportional to the acceleration.


Because this accelerometer can measure static acceleration (gravity), it can function as a tilt sensor.  The output of the accelerometer varies depending on its orientation. Look at Figure 5 below to see a few baseline output voltages based on orientation.  When your hand makes a strong strumming motion, the increased acceleration is converted into a change in voltage output in the X and/or Y directions.

5.png

Figure 5: Accelerometer output with different orientations.

Software Instructions


Part 1: Air Guitar.vi

6.png

Figure 6: Front Panel of Air Guitar.vi

At the start of the program, a function is called that will calibrate the accelerometer and set its baseline voltage in the x and y directions. During this calibration, keep your hand still in your resting position.  Once the voltages appear relatively constant, press the Accept Calibration Button. During each iteration of the while loop, the DAQ Assistant acquires the x and y voltages from the accelerometer and determines if there has been a strum.  A strum occurs when the voltage in the x or y direction varies by more than some set value (for example, +/- 1 Volt).  Also in each iteration, a DAQ Assistant determines which string and which notes have been chosen by the user.  The DAQ Assistant is reading in 1 bit for each push button (1 or 0).  The first 4 bits correspond to the left hand buttons (Selected Notes) and the last 4 bits correspond to the right hand buttons (Selected String).  The sets of 4 bits are extracted and converted to a numerical value ranging from 0 (0000 in binary) to 15 (1111 in binary).  These values are sent into the case structures.  The Strum Detected Boolean indicator is wired to the larger case structure, and the numeric value of Selected String determines the case of the inner case structure.  The Selected Notes numerical value determines which row in a predetermined array to output. This array holds all the combinations of notes for a particular string.  Each note is a type def Ring control called Music Notes.ctl, which connects a particular note (ex: A4, B4, C4) to the frequency of that note.  Once the set of notes has been chosen, the array of frequencies are generated by the Simulate Signal vi’s, filtered to smooth out the sound of the waveform, and sent to the audioOutput of the myDAQ. The block diagram can be seen in Figure 7.

7.png

Figure 7: Block Diagram of Air Guitar vi

Now that you understand the software, try it out!  You have to hold down one string and strum in order to play a note, but you can play that string open or play 4 other notes on it using the buttons on your left hand.  The notes that you can play are shown on the front panel of the vi.  This guitar is in the key of G major, but that can be changed by changing the arrays that control which notes to play.  Now try some chords!  If you press down more than one note button on your left hand, then multiple signals will be sent to the audio output.  If you don’t know what to play, and you want some inspiration, try playing the classic song “Mary Had A Little Lamb.”  The notes are shown in Figure 8 below.

Ma-ry had a lit-tle lamb, lit-tle lamb,

E   D    C  D  E E     E      D D     D


Lit-tle lamb, Ma-ry had a lit-tle lamb,

E   E     E      E   D   C   D E E     E


Its fleece was white as snow.

E      D      D      E     D     C

Figure 8: Mary Had A Little Lamb Notes

Part 2: Air Guitar_Songs.vi


Air Guitar_Songs_FP.png

Figure 9: Front Panel of Air Guitar_Songs.vi

If you want to sound like a pro guitar player with very little effort, then this vi is for you!  This program plays the National Anthem note by note, and all you have to do is hold down one button and strum.  The block diagram of this vi is shown in Figure 10.  This program loads in the contents of the text file called Note Files.txt. This file contains all of the file names of the wav files that contain the individual notes of the National Anthem in order.  The contents of the text file are converted into an array of strings so that the file names can be sent to the Play Sound vi.  In each iteration of the while loop, a DAQ Assistant determines if a strum has occurred and if the user is holding his/her “pick”, which is done by pressing the button on the index finger on the ring hand.  If both of these are true, then the program takes the next element in the array of file names and sends it to the Play Sound vi, which uses a windows dll function call to play the file.  The index is then incremented for the next iteration.  This continues until the program ends. 

Air Guitar_Songs_BD.png

Figure 10: Front Panel of Air Guitar_Songs.vi

Now that you’ve seen this vi’s code, have some fun!  Once you’ve got the basic strumming moves down, try honing your head banging skills as you rock out with your new air guitar like a pro.

song glyph.png

Comments
pedrorivera
Member
Member
on

soo cool, i wanna create a virtual harpsichord just for fun, so, how did you create the characteristic sound of a guitar?, when did you got it?, thanks for help and  congratulations the guitar is so awsome

.:. Pedro Rivera .:.
i love to work and develop on labview, this is real fun!!!
Photobucket
JackieNI
NI Employee (retired)
on

Thanks!  You can play this guitar with two vi's, which play sounds differently.  In Air Guitar.vi, the notes are played by sending signals with specific frequencies to the audio output of the myDAQ.  In Air Guitar_Songs.vi, .wav files with the characteristic sounds of a guitar are played through the computer speakers.  The notes to the National Anthem are in the download file.  If you like this characteristic guitar sound, then playing the .wav files might be the best option.  You can find these online or even in a guitar tuning app.  Good luck!

elcc024
Member
Member
on

.

Contributors