Make a dig­i­tal voice-pow­ered

Add a mi­cro­phone mod­ule and OLED panel to your Ar­duino Nano and make a voice-pow­ered os­cil­lo­scope. Dar­ren Yates ex­plains how.

APC Australia - - Contents -


The fact we can hear changes in air pres­sure and recog­nise dif­fer­ent fre­quen­cies is fas­ci­nat­ing. But what does sound look like? What can we see by look­ing at it? It’s likely a ques­tion asked in the early 1920s when the first reli­able cath­ode-ray tubes were de­vel­oped. For the first time, sci­en­tists could watch how sound cap­tured by a car­bon mi­cro­phone caused vari­a­tions in volt­age that could be seen on a new cath­ode-ray os­cil­lo­scope or ‘CRO’. This month, we’re repli­cat­ing that ex­per­i­ment with mod­ern-day com­po­nents, com­bin­ing an Ar­duino Nano, a 128 x 64-pixel OLED panel and a low-cost au­dio mi­cro­phone mod­ule to cre­ate a dig­i­tal voice-op­er­ated os­cil­lo­scope.


It’s prob­a­bly been one of the most re­quested top­ics for us to cover, how to add a mi­cro­phone to an Ar­duino. It’s tricky for a num­ber of rea­sons, but mostly comes down to whether you want to just de­tect sound or have ac­cess to ac­tual au­dio. You can buy mi­cro­phone mo­d­ules to do ei­ther task, but you have to choose care­fully — that’s be­cause sound de­tec­tion mo­d­ules de­liver a dig­i­tal ‘1 or 0’ volt­age out­put, whereas a gen­uine au­dio mi­cro­phone mod­ule must give you an ana­log au­dio out­put. We spent all of $1.50 pur­chas­ing a MAX9812 mi­cro­phone mod­ule from eBay, a com­plete mic setup with a fixed 20dB am­pli­fi­ca­tion fac­tor or ‘gain’ am­pli­fier and a small elec­tret mic on top. It re­quires 5VDC power, which you can take from the Ar­duino board.

To feed the mod­ule’s au­dio out­put into an Ar­duino board, you have to hook it up to one of the Ar­duino’s ana­log-to-dig­i­tal con­verter (ADC) in­puts. But there’s a catch — you must also bias the ADC in­put to half-sup­ply volt­age. The ADC in­puts of the Ar­duino Nano are de­signed to turn DC volt­age into a dig­i­tal num­ber be­tween 0 and 1,023. But au­dio from the MAX9812 out­put is AC volt­age only. To en­sure we cap­ture the full swing of that AC volt­age, we need to set or ‘bias’ the ADC in­put to half the sup­ply volt­age (half of 5VDC is 2.5VDC). This way, the au­dio sig­nal can swing equally above and be­low this ‘bias volt­age’ and we’ll cap­ture the full range of that sig­nal.

The eas­i­est way to cre­ate the bias volt­age is to con­nect up two 10kohm re­sis­tors as a volt­age divider con­nected be­tween a 5VDC sup­ply rail and ground (0V). Ohm’s Law en­sures the DC volt­age at the junc­tion of the two re­sis­tors is 2.5VDC and we con­nect this to the ADC in­put A0, along with the mi­cro­phone mod­ule au­dio out­put. If you don’t do this, you’ll lose the neg­a­tive-go­ing half of each au­dio cy­cle since the ADC in­put can’t go any lower than zero-volts.

We cheat and use ana­log in­put A3 as a dig­i­tal out­put to sup­ply 5VDC power — the mi­cro­phone needs lit­tle cur­rent, so this works just fine. the ADC in­put volt­age with a ref­er­ence volt­age. The de­fault on the Ar­duino Nano is 5VDC for stan­dard 5V/USB-pow­ered boards and the ADC has a 10-bit range, giv­ing a dig­i­tal value of be­tween 0 and 1,023. So if the in­put volt­age is 2.5VDC (ie, half the ref­er­ence volt­age), the ADC will cre­ate a dig­i­tal sam­ple of 512 (half the 1,024 range) and if it’s 1.25V (a quar­ter of Vref), the ADC sam­ple will be 256 (a quar­ter of 1,024). This con­tin­ues for ev­ery sam­ple. The ac­tual con­ver­sion process is known as ‘suc­ces­sive ap­prox­i­ma­tion ana­log to dig­i­tal con­ver­sion’ and you’ll find at least one ADC in ev­ery smart­phone turn­ing your voice into dig­i­tal phone calls.


Now for the fun bit — we need to cap­ture au­dio sam­ples at a set rate, so that we can re­pro­duce the wave­form on the dis­play. The OLED panel is 128 pix­els wide, so we set aside a 128el­e­ment byte ar­ray buf­fer called ‘buf’. We then cap­ture 128 sam­ples of au­dio and store those sam­ples in the buf­fer. As soon as that last sam­ple is cap­tured, we dis­play each sam­ple on the OLED panel set as a stan­dard X-Y Carte­sian plot, where the Y-axis cor­re­sponds to each sam­ple value, rep­re­sent­ing the volt­age on the ADC in­put at time of sam­pling. As soon as the last pixel is drawn, we grab the next round of 128 sam­ples and dis­play those. With a sam­ple rate of 22,050Hz, it takes just 5.8 mil­lisec­onds to grab 128 sam­ples and around an­other 15 mil­lisec­onds or so to dis­play them on the OLED panel. That means each pass or ‘sweep’ takes around 20 mil­lisec­onds, giv­ing us a vis­ual frame rate of roughly 50 frames per sec­ond or 50Hz. You can pick up a 0.96-inch 128 x 64p OLED panel for around $5 on eBay but make sure you get the four-pin ver­sion sup­port­ing the I2C (in­ter-in­te­grated cir­cuit) bus. And most im­por­tantly, if you’re fol­low­ing our over­lay di­a­gram, make sure you watch the VCC and GND pin po­lar­ity. The panel ver­sion we’ve used has the VCC pin on the out­side — there are older ver­sions with these two pins swapped. Plug an older mod­ule in with the volt­age pins re­versed and you’ll blow it up, so be very care­ful.


If you have an An­droid phone, head to Google Play, down­load Wave­form Gen­er­a­tor (­dv7una) and place your phone’s speaker near the mi­cro­phone. Press the power but­ton, change the fre­quency and see what ef­fect that has on the dis­play.

Un­for­tu­nately, 20dB isn’t re­ally enough gain to give a de­cent vis­ual out­put (you re­ally need nearer to 40dB), so we’ve in­creased the gain in code to boost the sam­ple level, a bit like us­ing dig­i­tal zoom on your phone cam­era — un­for­tu­nately, this also boosts the noise, which is why the os­cil­lo­scope line or ‘trace’ isn’t dead-flat with no in­put.


You’ll find the source code on our web­site at Down­load it, un­zip the file and copy the con­tents of the ‘li­braries’ sub­folder into the same of your Ar­duino IDE (get this free from ar­­loads). Open the voices­cope.ino source code, flash it to your Ar­duino Nano board, build the project and away you go.

It cer­tainly won’t worry pro­fes­sional os­cil­lo­scope mak­ers like Tek­tronix, but for a $10 os­cil­lo­scope, our VoiceS­cope fol­lows the same prin­ci­ples as the big mod­els. It’d even make a great science ex­per­i­ment, so why not give it a go!

HOW ANA­LOG-TO-DIG­I­TAL CON­VER­SION WORKS ADC sam­ples are cre­ated by com­par­ing

The Ar­duino Nano is the brains be­hind our VoiceS­cope.

This tiny OLED panel dis­plays the os­cil­lo­scope trace. This MAX9812 mi­cro­phone mod­ule will set you back $ 1.50 on eBay.

Use this over­lay di­a­gram to build your own VoiceS­cope.

The VoiceS­cope is built on a tiny 170-tie­point bread­board.

Wave­form Gen­er­a­tor turns your An­droid phone into a sig­nal gen­er­a­tor.

Newspapers in English

Newspapers from Australia

© PressReader. All rights reserved.