100 Yard Paper Rocket Launcher

Embed Size (px)

Citation preview

  • 8/12/2019 100 Yard Paper Rocket Launcher

    1/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    Food Living Outside Play Technology Workshop

    Arduino Audio Inputby amandaghassaeion July 25, 2012

    Table of Contents

    Arduino Audio Input ............................................................................................................

    Intro: Arduino Audio Input ....................................................................................................

    Step 1: Preparing audio signals for Arduino .......................................................................................

    Step 2: Prepare audio jack ...................................................................................................

    Step 3: Non-Inverting Amplifier ................................................................................................

    Step 4: DC Offset ..........................................................................................................

    Step 5: Simple Analog In .....................................................................................................

    Step 6: Sampling rate of ~40kHz ............................................................................................... 1

    Step 7: Interrupt ........................................................................................................... 1

    Step 8: Clipping Indicator .................................................................................................... 1

    Related Instructables ........................................................................................................ 1

    Advertisements ............................................................................................................... 1

    Comments ................................................................................................................ 1

    http://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=titlehttp://www.instructables.com/tag/type-id/category-workshop/http://www.instructables.com/tag/type-id/category-technology/http://www.instructables.com/tag/type-id/category-play/http://www.instructables.com/tag/type-id/category-outside/http://www.instructables.com/tag/type-id/category-living/http://www.instructables.com/tag/type-id/category-food/
  • 8/12/2019 100 Yard Paper Rocket Launcher

    2/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    Author:amandaghassaei uh-man-duh-guss-eye-dot-com

    I'm a developer here at Instructables, I work on the website and iOS app.

    Intro: Arduino Audio InputSend sound into your Arduino. This Instructable will show you how to prepare audio so that it can be sampled and processed by an Arduino to make sound responsivprojects and audio effects. (This article is a companion to another Instructable I've written about building an audio output circuit for an Arduino, find that here)

    Some ideas that come to mind include:

    beat detection- trigger lighting effects, build a set of turntables that beat match themselves, or make a robot that dances along with the music you play for itamplitude detection- make a simple vu meter with LEDSfrequency analysis- you could make a project thatreacts to different frequenciesin different ways, recognizes certain melodies, turns audio into MIDI data, ortranslates incoming frequencies into square waves with the tone() librarydigital effects boxes/digital signal processing- check out what I did with my vocal effects box(all processing done with Arduino), lots of possibilities here: pitchbending, distortion, sampling, delay, reverb, granular synthesis, mixing, and much more... I've provided code in this Instructable that lets you sample at up to 38.5kHHereis another instructable describing how to set up a simple audio out circuit with Arduino.digital recorder- with the addition of an SD card of course (the Arduino has very limited memory by itself), this opens up the possibility of looping large samples anddoing lots of other digital manipulations to pieces of stored audio The circuits and code provided here are compatible with SD card shields that communicate via SPI.graphical representations of sound- Arduino oscilloscope/visualizer

    Feel free to use any of the info in this Instructable to put together an amazing project for the DIY Audio Contest! We're giving away an HDTV, some DSLRcameras, and tons of other great stuff! The contest closes Nov 26.

    Parts list:(x1) Microphone Radioshack 33-3038(x1) TL072 Digikey 296-14997-5-NDor TL082 Digikey 296-1780-5-ND(TL081/TL071 are fine too) I used a tl082 in my examples(x2) 9V battery

    (x2) 9V battery snap connector Radioshack 270-324(x1) mono audio jack 1/4" Radioshack 274-340or Radioshack 274-252or 1/8" Radioshack 274-333or Radioshack 274-251(x1) LED Digikey C513A-WSN-CV0Y0151-ND(x1) 10kOhm potentiometer linear Digikey 987-1301-ND(x3) 100kOhm 1/4watt resistors Digikey CF14JT100KCT-ND(x1) 10uF electrolytic capacitor Digikey P5134-ND(x1) 47nF ceramic capacitor Digikey P4307-ND(x1) Arduino Uno (Duemilanove is fine too) Sparkfun DEV-09950

    Additional Materials:22 gauge wiresolder

    Step 1:Preparing audio signals for ArduinoIf you've ever recorded audio on your computer, you may have seen it represented as a waveform like the one in fig 1. If you zoom in on this wave (as in fig 2) you willsee that the shape is made of thousands of tiny oscillationsback and forth. This is called an audio signaland when we are dealing with audio signals in electronics, th

    oscillations represent oscillating voltages over time.

    When we look at an audio signal with an oscilloscope, we see a similar picture (fig 3). Notice how the audio signal in fig 3 oscillates around a center voltage of 0V; thistypical of audio signals. The amplitudeof an audio signal is the distance between its center voltage and its high or low peak. The amplitude of the wave in fig 3 is 2V: ireaches a maximum voltage of +2V and a minimum voltage of -2V. This is a problem if we want to measure the audio signal with one of the Arduino's analog inputsbecause the Arduino can only measure voltages between 0 and 5V. If we tried to measure the negative voltages in the signal from fig 3, the Arduino would read only 0and we would end up clippingthe bottom of the signal. In this Instructable I'll show you how you can amplify and offset audio signals so that they fall within this 0-5Vrange. Ideally you want a signal with an amplitude of 2.5V that oscillates around 2.5V (like in fig 7) so that its min voltage is 0V and its max voltage is 5V (see thecalculations below).

    Min voltage = Center Voltage - AmplitudeMin voltage = 2.5V - 2.5V = 0V

    Max Voltage = Center Voltage + AmplitudeMax Voltage = 2.5V + 2.5V = 5V

    Fig 4 shows the signal coming straight out of the microphone on an oscilloscope. The signal is relatively weak, with an amplitudeof only 200mV, you may find that sig

    http://en.wikipedia.org/wiki/Amplitudehttp://en.wikipedia.org/wiki/Clipping_%28audio%29http://en.wikipedia.org/wiki/Amplitudehttp://www.instructables.com/id/Oscilloscope-How-To/http://en.wikipedia.org/wiki/Audio_signalhttp://en.wikipedia.org/wiki/Oscillationshttps://www.sparkfun.com/products/9950http://www.digikey.com/product-detail/en/ECK-F1E473ZVE/P4307-ND/4660http://www.digikey.com/product-detail/en/ECA-1CM100/P5134-ND/244993http://www.digikey.com/product-detail/en/CF14JT100K/CF14JT100KCT-ND/1830399http://www.digikey.com/product-detail/en/P160KN-0QC15B10K/987-1301-ND/2408878http://www.digikey.com/product-detail/en/C513A-WSN-CV0Y0151/C513A-WSN-CV0Y0151-ND/1922948http://www.radioshack.com/product/index.jsp?productId=2103453http://www.radioshack.com/product/index.jsp?productId=2062461http://www.radioshack.com/product/index.jsp?productId=2103454http://www.radioshack.com/product/index.jsp?productId=2103223http://www.radioshack.com/product/index.jsp?productId=2062218http://www.digikey.com/product-detail/en/TL082CP/296-1780-5-ND/277630http://www.digikey.com/product-detail/en/TL072IP/296-14997-5-ND/563039http://www.radioshack.com/product/index.jsp?productId=2123173http://www.instructables.com/contest/audio/http://www.instructables.com/id/Arduino-Audio-Output/http://en.wikipedia.org/wiki/DJ_mixerhttp://en.wikipedia.org/wiki/Granular_synthesishttp://en.wikipedia.org/wiki/Reverbhttp://en.wikipedia.org/wiki/Delay_%28audio_effect%29http://www.instructables.com/id/Arduino-Vocal-Effects-Box/http://arduino.cc/en/Reference/Tonehttp://www.instructables.com/id/Send-and-Receive-MIDI-with-Arduino/http://www.instructables.com/id/Arduino-Frequency-Detection/http://en.wikipedia.org/wiki/VU_meterhttp://www.instructables.com/id/Arduino-Audio-Output/http://www.amandaghassaei.com/http://member/amandaghassaei/http://member/amandaghassaei/
  • 8/12/2019 100 Yard Paper Rocket Launcher

    3/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    from other sources (ipods, guitars, record players...) also produce audio signals with small amplitudes. These signals need to be amplified to get them up to the amplitwe want (2.5V). Amplificationmeans increasing the amplitude (distance between the center point and max or min) of a signal. Amplification also buffers the audio sou(in my case this was a microphone) from any loads that you may put on it later in the circuit, which is a good thing because it prevents distortion.

    Fig 5 shows the same microphone signal after amplification, you can see how the height of the peaks has increased so that the wave has an amplitude of 2.5V. But sithe center voltage of the wave is still 0, the wave is oscillating between -2.5 and +2.5V. It will need to be DC offset to correct this. DC offsetmeans changing the centevoltage that the wave oscillates around (the average voltage of the wave). Fig 6 shows the signal after i t has been DC offset; it still has an amplitude of 2.5V, but thecenter voltage is 2.5V instead of 0V, so the wave never drops down below 0V. (Note- the slight change in shape between the signals in figures 5 and 6 is dues tochanges in my voice between the two pics, it has nothing to do with the circuit). The signal in fig 6 is ready to go to an Arduino analog input pin.

    Image Notes

    1. zoomed in from fig 1 shows individual oscillations of signal

    Image Notes1. 0V2. volts/div = 2V Image Notes

    1. signal directly from microphone has a relatively small amplitude2. volts/div = 2V

    http://en.wikipedia.org/wiki/DC_biashttp://en.wikipedia.org/wiki/Amplifier
  • 8/12/2019 100 Yard Paper Rocket Launcher

    4/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    Image Notes1. microphone mono input2. amplifier3. DC offset

    Step 2:Prepare audio jackIn this Instructable, I'm only going to talk about how to route one channel of audio into an Arduino. It is possible to copy the same circuit I've proposed here many timeadd multiple channels, but it can complicate/slow things down in the code and at some point you will probably have to lower your sampling rate. I'll leave it up to you tofigure out the details, but please post what you learn in the comments! Almost all microphones and electronic instruments are mono, meaning they only have onemicrophone element or pickup which is generating a signal (as opposed to stereo). You can tell for sure by looking at the plug and comparing it to the image above. Mmicrophone has a 1/4" plug on it so I used a 1/4" jack for this instructable, you may find that you need a 1/8" jack, but the main ideas here still apply.

    Solder a black wire to the ground pin of the mono jack. The ground pin is usually the larger pin on the jack, test for continuity with the threaded portion of the jack to msure that you have located the ground pin correctly (see fig 3). Solder a green wire to the signal pin of the mono jack. Test for continuity with the clip that extends out fthe jack (fig 3).

    If you have an oscilloscopehandy, connect the reference to the black wire, connect the probe tip to the green wire, plug the microphone in the jack and look for a sign(fig 5). The signal from my microphone has an amplitude of about 200mV.

    Image Notes1. stereo plug2. mono plug

    Image Notes1. the ground pin will be electrically connected to this portion of the jack2. The signal pin will be electrically connected to this portion of the jack3. ground pin4. signal pin

    http://www.instructables.com/id/Oscilloscope-How-To/http://en.wikipedia.org/wiki/Stereophonichttp://en.wikipedia.org/wiki/Monophonic
  • 8/12/2019 100 Yard Paper Rocket Launcher

    5/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    Image Notes1. volts/div = 200mV

    Step 3:Non-Inverting AmplifierThe amplifier is the first step in the circuit, it increases the amplitude of the signal from around + or - 200mV to + or - 2.5V (ideally). The other function of the amplifier iprotect the audio source (the thing generating the audio signal in the first place) from the rest of the circuit. The outgoing amplified signal will source all its current fromamplifier, so any load put on it later in the circuit will not be "felt" by the audio source (the microphone element in my case). Do this by setting up one of the op amps inthe TL072 or TL082 package in a non-inverting amplifier configuration.

    The datasheet of the TL072 or TL082 says that it should be powered with +15 and -15V, but since the signal will never be amplified above + or - 2.5V it's fine to run thop amp with something lower. I used two nine volt batteries wired in series to create a + or - 9V power supply.

    Wire up your +V(pin 8) and -V(pin 4) to the op amp. Wire the signal from the mono jack to the non-inverting input (pin 3) and connect the ground pin of the jack to the reference on your voltage supply (for me this was the junction between the two 9V batteries in series). Wire a 100kOhm resistor between the output (pin 1) and invertiinput (pin 2) of the op amp. In this circuit I used a 10kOhm potentiometer wired as a variable resistorto adjust the gain(the amount that the amplifier amplifies) of my ninverting amplifier. Later in this Instructable, I'll show how you can add an LED indicator to Arduino pin 13 to let you know when you have this pot turned up too high(resulting in clippingof the incoming signal by the Arduino); this way you know when you should turn the pot down and get the signal back in the range you want(amplitude of ~2.5V). Wire this 10K linear taper pot between the inverting input and the 0V reference.

    The following equation describes the relative amplitudes of the signal before and after the non-inverting amplifier:

    Vout =~ Vin * (1 + R2/R1)orVout/Vin =~ 1 + R2/R1where R2 is the feedback resistor (between the output and non inverting input), R1 is the resistor to ground, Vout is the amplitude of the outgoing signal (the output frothe amplifier), and Vin is the amplitude of the incoming signal (the input to the amplifier)

    In this circuit R2 is a 100kOhm resistor and R1 is a 10kOhm potentiometer (variable resistor). By turning the pot you can change the resistance of R1 from 0Ohms to10KOhms. Here are some example calculations:

    When the pot is turned all the way to the left the resistance of R1 is 10kOhms and the ratio of Vout to Vin is about:1+ 100/10 = 11A signal coming out of the microphone with an amplitude of 200mV (which is fairly loud on my microphone) will be amplified to:200mv * 11 = 2200mV = 2.2Vthis is right in the range we want (amplitude close to 2.5V without going over)

    Turning the pot to its halfway position will give it a resistance of 5kOhms, we can calculate the ratio of Vout to Vin again:1+ 100/5 = 21now the amplitude gets multiplied by 21this is too much amplification for the 200mV signal:200mV * 21 = 4200mv = 4.2V >> 2.5Vbut this amplification would be perfect for a 100mV signal:100mV *21 = 2100mV = 2.1V =~ 2.5V

    Turning the pot farther to the right will keep decreasing the resistance of R1 and increase the amplification (also called gain) of this amplifier theoretically to infinity.Obviously at some point the amplifier will not be able to power a signal with a huge amplitude, but you get the idea. By adjusting the potentiometer you can adjust thegain of the amplifier and tune the sensitivity of the microphone while still keeping it in a range that the Arduino likes.

    Note: As you can see in the circuit above, this project only uses one of the two available op amps in the TL072/TL082 package. I used this chip because they are easisourced (you can even buy the TL082 at Radioshackthese days), they are basically the same price as the single op amp packages (TL071 and TL081), and you maywant to use the extra op amp somewhere else on your circuit (another channel of input, an audio out circuit...). But if you have a TL071 or TL081, it will do fine for thisproject.

    http://www.radioshack.com/product/index.jsp?productId=2062594http://en.wikipedia.org/wiki/Gainhttp://en.wikipedia.org/wiki/Clipping_%28audio%29http://en.wikipedia.org/wiki/Gainhttp://www.instructables.com/id/Wire-a-Potentiometer-as-a-Variable-Resistor/http://en.wikipedia.org/wiki/Operational_amplifier#Non-inverting_amplifier
  • 8/12/2019 100 Yard Paper Rocket Launcher

    6/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    Image Notes1. non-inverting amplifier2. unused op amp in dual package3. microphone input

    Image Notes1. signal directly from microphone has a relatively small amplitude2. volts/div = 2V

    Image Notes1. amplified signal oscillates between -2.5 and 2.5 V2. volts/div = 2V

    Image Notes1. 9V2. 0V reference, both audio in ground 10k pot ground connect here. Arduinoground will reference here as well, more info in the next step3. -9V

    Image Notes1. -9V to 082 pin 42. 9V to 082 pin 83. signal pin from mono jack to pin 3 of 0824. ground pin from mono jack5. battery snaps

  • 8/12/2019 100 Yard Paper Rocket Launcher

    7/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    6. battery snaps7. battery snaps8. 100k bridges pins 1 and 2 of 0829. 10k pot bridges pin 2 of 082 and 0V reference between two 9V batteries inseries

    Step 4:DC OffsetThe next portion of the circuit DC offsets the output from the amplifier. As I explained in step 1, this +2.5V DC offset causes audio signal to oscillate around 2.5V so thstays within the acceptable range for the Arduino's analog inputs (0-5V). Compare the non dc offset signal is fig 2 with the dc offset in fig 3. Specifically, notice how thesignal in fig 3 always stays within the 0-5V range.

    The DC offset circuit has two main components: a voltage divider and a capacitor. The voltage divideris made from two 100k resistors wired in seriesfrom the Arduin5V supply to ground. Since the resistors have the same resistance, the voltage at the junction between them equals 2.5V. This 2.5V junction is tied to the output of theamplifier via a 10uF capacitor. As the voltage on the amplifier side of the capacitor rises and falls, it causes charge to momentarily accumulate and repel from the sidethe capacitor attached to the 2.5V junction. This causes the voltage at the 2.5V junction to oscillate up and down, centered around 2.5V.

    As shown in figs 3-8 and the schematic, connect the negative lead of a 10uF capacitor to the output from the amplifier. Connect the other side of the cap to the junctiobetween two 100k resistors wired in series between 5V and ground. Also add a 47nF capacitor from 2.5V to ground.

    http://en.wikipedia.org/wiki/Series_and_parallel_circuits#Series_circuitshttp://en.wikipedia.org/wiki/Voltage_divider
  • 8/12/2019 100 Yard Paper Rocket Launcher

    8/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    Image Notes1. DC offset

    Image Notes1. amplified signal- oscillates between -2.5V and 2.5V2. volts/div = 2V

    Image Notes1. amplified and dc offset signal- oscillates between 0 and 5V

    2. volts/div = 2V

    Image Notes1. to Arduino Vin

    2. to Arduino 5V3. to Arduino A04. to Arduino ground5. 47nF6. 100k resistors7. 0V reference- junction between two 9V in series8. 9V

  • 8/12/2019 100 Yard Paper Rocket Launcher

    9/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    Step 5:Simple Analog InLoad the following code onto the Arduino. This code reads the voltage of the incoming audio signal using analogRead(A0)as a number between 0 and 1023 and storeas the variable "incomingAudio." From here you could store this value for later use, perform mathematical operations to it, or do any other manipulations you can think

    //Simple Audio In

    //by Amanda Ghassaei

    //http://www.instructables.com/id/Arduino-Audio-Input/

    //Sept 2012

    /*

    * This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by

    * the Free Software Foundation; either version 3 of the License, or

    * (at your option) any later version.

    *

    */

    int incomingAudio;

    void setup(){

    }

    void loop(){

    incomingAudio = analogRead(A0);//read input from A0

    //do stuff with the variable "incomingAudio"

    }

    In the images above I set up a really simple 8 bit digital to analog converter (read more about it here, or check out fig 4) so that I could visualize the data points that thArduino was storing as the variable "incomingAudio" and see how close it was to the original signal. You can see from fig 2 (zoomed in view of fig 1) that the Arduino itaking one sample every 125us from A0. We can calculate the sampling rate as follows:

    sampling rate = 1/125us = 1/0.000125s = 8000hz

    To give you a point of comparison, normal audio sampling rates are at least 40kHz. If a sampling rate of 8kHz or less is good enough for your purposes then you shouprobably go ahead and use analogRead() to measure your signal, as it keeps things very simple. You can see in fig 1 that it actually does a pretty good job of tracing othe path of the incoming 360hz signal. In order to get above 8kHz, we'll have to bypass the analog read function. It may sound daunting, but it's actually not too bad, jua matter of copying some setup() code that I've written in the next step.

    I also want to point out the behavior of the Arduino in response to a signal that rises over 5V and dips under 0V. In fig 3 you can see how the Arduino clips the incominsignal so that it is always bounded by 0 and 5V. This causes the tops of the peaks and the bottom of the valleys to get flattened. In step 8 I'll talk some more about thisand how to set up a clipping indicator light to let you know to turn the amplifier down.

    Some notes about the 8 bit digital to analog converter (DAC): I used the command "PORTD = " to send a value between 0 and 255 out of the Arduino and into the DAwhere it is converted back into a voltage between 0 and 5V. The code I used can be found below. I've written a whole instructable about the 8 bit DAC here.

    //Simple Audio In w output to 8 bit DAC

    //by Amanda Ghassaei

    //http://www.instructables.com/id/Arduino-Audio-Input/

    //Sept 2012

    /*

    * This program is free software; you can redistribute it and/or modify

    * it under the terms of the GNU General Public License as published by

    * the Free Software Foundation; either version 3 of the License, or

    * (at your option) any later version.

    *

    */

    int incomingAudio;

    void setup(){

    for (byte i=0;i

  • 8/12/2019 100 Yard Paper Rocket Launcher

    10/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    if (incomingAudio

  • 8/12/2019 100 Yard Paper Rocket Launcher

    11/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    the most significant 8 bits of the 10 bit ADC to save time in the code). I set the ADC counter to 500kHz because the ADC takes 13 clock cycles to read a new analogvalue. 500/13 =~ 38.5kHz which gets me pretty close to 40kHz (standard audio sampling rate) without introducing extra noise. As you can see in fig 2, this gives me osample every 13/500000 = 26us. A lot of the ideas here (prescalers and counters) are similar to the setup for Arduino timer interrupts, and you can read more about hthat works here.

    //Audio out with 38.5kHz sampling rate

    //by Amanda Ghassaei

    //http://www.instructables.com/id/Arduino-Audio-Input/

    //Sept 2012

    /*

    * This program is free software; you can redistribute it and/or modify

    * it under the terms of the GNU General Public License as published by

    * the Free Software Foundation; either version 3 of the License, or

    * (at your option) any later version.

    **/

    int incomingAudio;//storage for A0 data

    void setup(){

    //set up continuous sampling of analog pin 0 (you don't need to understand this part, just know how to use it in the loop())

    //clear ADCSRA and ADCSRB registers

    ADCSRA = 0;

    ADCSRB = 0;

    ADMUX |= (1

  • 8/12/2019 100 Yard Paper Rocket Launcher

    12/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    Image Notes1. volts/div = 2V2. time/div - 500us3. input to A0 shown in yellow, output from Arduino D0-D7 in blue

    Image Notes1. one sample every 26us2. time/div = 25uS3. volts/div = 2V

    Image Notes

    1. when input signal (yellow) drops above 5V the Arduino clips it as it measures it.This clipping is reflected in the outgoing signal from the Arduino (blue)2. when input signal (yellow) drops below 0V the Arduino clips it as it measures it.This clipping is reflected in the outgoing signal from the Arduino (blue)3. volts/div = 2V4. time/div = 500us

    Step 7:InterruptIn this piece of code, I set up the Arduino to continuously monitor pin A0 at 38.5kHz, but now I've added a piece of code that automatically updates the variable"incomingAudio" each time a new value from A0 has been calculated. Instead of putting the line:

    incomingAudio = ADCH;

    in the loop() function of the Arduino sketch, I've put it in a special function called an "interrupt routine." The interrupt routing looks like this:

    ISR(ADC_vect) {incomingAudio = ADCH;

    }

    Think of it as a normal sketch, the Arduino first goes through the setup() function then it starts the loop(), but every 26us (when a new value is ready from A0) the Ardustops what it is doing in the loop and does whatever is encapsulated in the interrupt routine (in this case just the line "incomingAudio = ADCH;"). Once the interruptroutine has finished, the Arduino picks up again where it was in the loop() for another 26us. Then the interrupt routine executes again.... this goes on repeating foreveyou want, you can read more about Arduino interrupts here.

    This interrupt code generally a better way of reading the incoming signal than the way I wrote it in the last step because you are only updating the variable incomingAuonce each time a new value comes in. Updating the variable multiple times, before the value has even had time to change is redundant. Also, if you want to record thevalues you can put the storage code in the interrupt routine so you know that your storage sampling rate is exactly 38.5kHz.

    //Audio out with 38.5kHz sampling rate and interrupts

    //by Amanda Ghassaei

    //http://www.instructables.com/id/Arduino-Audio-Input/

    //Sept 2012

    /*

    * This program is free software; you can redistribute it and/or modify

    http://www.instructables.com/id/Arduino-Timer-Interrupts/
  • 8/12/2019 100 Yard Paper Rocket Launcher

    13/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    * it under the terms of the GNU General Public License as published by

    * the Free Software Foundation; either version 3 of the License, or

    * (at your option) any later version.

    *

    */

    int incomingAudio;

    void setup(){

    cli();//disable interrupts

    //set up continuous sampling of analog pin 0

    //clear ADCSRA and ADCSRB registers

    ADCSRA = 0;

    ADCSRB = 0;

    ADMUX |= (1

  • 8/12/2019 100 Yard Paper Rocket Launcher

    14/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    incomingAudio = analogRead(A0);//read input from A0

    //do stuff with the variable "incomingAudio"

    if (incomingAudio == 0 || incomingAudio == 1023){//if clipping

    digitalWrite(13,HIGH);//set pin 13 high

    clipping = 1;//currently clipping

    clippingCounter = 5000;//reset clippingCounter

    }

    if (clipping){

    if (clippingCounter>0){

    clippingCounter--;//decrement clipping counter

    }

    else{//if clippingCounter has counted all the way down

    clipping = 0;//no longer clipping

    digitalWrite(13,LOW);//turn of clipping indicator

    }

    }

    }

    and below is the code for 38.5kHz with interrupts:

    //Audio in with 38.5kHz sampling rate, interrupts, and clipping indicator

    //by Amanda Ghassaei

    //http://www.instructables.com/id/Arduino-Audio-Input/

    //Sept 2012

    /*

    * This program is free software; you can redistribute it and/or modify

    * it under the terms of the GNU General Public License as published by

    * the Free Software Foundation; either version 3 of the License, or

    * (at your option) any later version.

    *

    */

    //variable to store incoming audio sample

    byte incomingAudio;

    //clipping indicator variables

    boolean clipping = 0;

    void setup(){

    pinMode(13,OUTPUT);//led indicator pin

    cli();//disable interrupts

    //set up continuous sampling of analog pin 0

    //clear ADCSRA and ADCSRB registers

    ADCSRA = 0;

    ADCSRB = 0;

    ADMUX |= (1

  • 8/12/2019 100 Yard Paper Rocket Launcher

    15/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    Image Notes1. when input signal (yellow) drops below 0V the Arduino clips it as it measuresit. This clipping is reflected in the outgoing signal from the Arduino (blue)2. when input signal (yellow) rises above 5V the Arduino clips it as it measuresit. This clipping is reflected in the outgoing signal from the Arduino (blue)3. volts/div = 2V4. time/div = 500us

    Image Notes1. when input signal (yellow) drops above 5V the Arduino clips it as it measuresit. This clipping is reflected in the outgoing signal from the Arduino (blue)2. when input signal (yellow) drops below 0V the Arduino clips it as it measuresit. This clipping is reflected in the outgoing signal from the Arduino (blue)3. volts/div = 2V4. time/div = 500us

    Related Instructables

    Arduino Vocal

    Effects Boxby

    amandaghassaei Lo-fi Arduino

    Guitar Pedalby

    kylemcdonald

    Girino - FastArduino

    Oscilloscopeby

    Caffeinomane

    Audio Delay

    Moduleby

    LargeMouthBass

    USB Headphone

    Hack!by

    babblin5

    ArduinoFrequency

    Detectionby

    amandaghassaei

    http://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Arduino-Frequency-Detection/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Arduino-Frequency-Detection/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Arduino-Frequency-Detection/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Arduino-Frequency-Detection/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/babblin5/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/USB-Headphone-Hack!/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/USB-Headphone-Hack!/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/USB-Headphone-Hack!/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/LargeMouthBass/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Audio-Delay-Module/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Audio-Delay-Module/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Audio-Delay-Module/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/Caffeinomane/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Girino-Fast-Arduino-Oscilloscope/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Girino-Fast-Arduino-Oscilloscope/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Girino-Fast-Arduino-Oscilloscope/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Girino-Fast-Arduino-Oscilloscope/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/kylemcdonald/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Lo-fi-Arduino-Guitar-Pedal/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Lo-fi-Arduino-Guitar-Pedal/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Lo-fi-Arduino-Guitar-Pedal/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Arduino-Vocal-Effects-Box/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Arduino-Vocal-Effects-Box/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Arduino-Vocal-Effects-Box/?utm_source=pdf&utm_campaign=related
  • 8/12/2019 100 Yard Paper Rocket Launcher

    16/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    vertisemets

    Comments

    50 comments Add Comment view all 186commen

    jiffymanagersays: Apr 25, 2014. 10:10 PM REPsuper

    calmlunchsays: Apr 20, 2014. 8:55 PM REPgood

    sheepbarssays: Apr 19, 2014. 2:28 AM REPthat's a good point about the op amp, I hadn't thought of that.

    creditrepairaidsays: Apr 3, 2014. 11:20 PM REPScaling from 10 bits to 8 bits may be quicker with bit shifting instead of that extra math:

    amandaghassaeisays: Apr 4, 2014. 11:27 AM REPyes it is! I just wanted it to be clear what was going on :)

    cmars4says: Mar 26, 2014. 7:07 PM REPis +5 - 0 ok too (the arduino power) for vcc+ and vcc- ? (if we want to amplify bigger input signals ?)

    amandaghassaeisays: Apr 2, 2014. 10:20 AM REPI don;t think that will work with the tl082, but you can try

    azalesovsays: Mar 27, 2014. 1:57 PM REPShould such scheme work with regular input from a mp3 player instead of mic? I constantly getting just 3 values 0 1023 and something around 512. I dont havan osciloscope but it obviously It does not look like a waveform. tripple checked the scheme.

    amandaghassaeisays: Apr 2, 2014. 10:19 AM REPyes it should work with any analog signal. is there a hackerspace near you where you can get on an oscilloscope?

    stupsi99says: Mar 8, 2014. 12:28 PM REPAwesome tutorial!!! Thank you very much, this helped me a lot! Now I already have an amplified signal, might have to apply DC Offset to it though (not a bproblem with your tutorial!) . I would like to record it to an sd card!I've searched the web and so far couldn't find the right information. The file needs to be able to be played on a computer later. Any idea how to get thisdone?

    amandaghassaeisays: Mar 9, 2014. 12:13 PM REPuse the sd library, here'san example of logging analog data to it.

    clickyummysays: Mar 8, 2014. 1:52 AM REPsuper

    raghavlitesays: Feb 28, 2014. 11:05 AM REPi tried the fast sampling code and it seems like the serial monitor gets struct up with these setup commands .for now i am testing with giving zero input at thA0 pin .I copied the whole of your code and executed it.is there anything else i am missing

    the code is .........

    int a;

    void setup()

    {

    http://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/raghavlite/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/raghavlite/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/clickyummy/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/clickyummy/?utm_source=pdf&utm_campaign=commentshttp://arduino.cc/en/Tutorial/Datalogger#.Uxy9JF5shkghttp://arduino.cc/en/Reference/SDhttp://arduino.cc/en/Tutorial/Datalogger#.Uxy9JF5shkghttp://arduino.cc/en/Reference/SDhttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/stupsi99/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/stupsi99/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/azalesov/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/azalesov/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/cmars4/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/cmars4/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/creditrepairaid/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/creditrepairaid/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/sheepbars/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/sheepbars/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/calmlunch/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/calmlunch/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/jiffymanager/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/jiffymanager/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/http://www.instructables.com/id/Arduino-Audio-Input/http://www.instructables.com/id/Arduino-Audio-Input/http://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#comments
  • 8/12/2019 100 Yard Paper Rocket Launcher

    17/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    Serial.begin(9600);

    Serial.println("started");

    delay(1000);

    cli();//disable interrupts

    //set up continuous sampling of analog pin 0

    //clear ADCSRA and ADCSRB registers

    ADCSRA = 0;

    ADCSRB = 0;

    ADMUX |= (1

  • 8/12/2019 100 Yard Paper Rocket Launcher

    18/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    foobar8675says: Feb 17, 2014. 1:42 PM REPThis is really excellent Amanda. thank you. I have a few questions

    Instead of the mic, I have an old USB mic. Can I use that instead?1.I'm having a hard time finding the 47nF cap. Can I use a larger one instead? Or is it not necessary as akellyirlsays? If it is, is there a rule of thumb2.that can be applied to the size of the capacitor to remove the signal noise?

    amandaghassaeisays: Mar 4, 2014. 9:57 AM REPyou should be fine w/o the 47nf cap. Does your mic output digital usb data? that will not work, you need to use an analog signal.

    mavrikscsays: Feb 28, 2014. 11:51 AM REP

    How is the 0V reference not a short?

    bearbluesays: Feb 25, 2014. 7:41 PM REPwonderful

    raghavlitesays: Feb 5, 2014. 12:34 PM REPhello amanda,that was a great tutorial,can you please tell me how to extend this sampling at 40khz to some other(say 3) analog pin of arduino.

    anyway thanks in advance

    amandaghassaeisays: Feb 13, 2014. 9:16 PM REPtry putting the line:

    ADMUX |= 3;

    in the setup

    ss1306says: Feb 11, 2014. 7:21 AM REPHi, this maybe a stupid question but how do we prepare the audio signal to be used in this project? can we use any audio signal? Thanks!

    amandaghassaeisays: Feb 13, 2014. 8:37 PM REPanything will work, you might have to adjust the gain of the amplifier depending on your audio source.

    chimplostsays: Jan 21, 2014. 9:36 PM REP

    that's a good point about the op amp, I hadn't thought of that.

    bowerymarcsays: Dec 21, 2013. 9:28 PM REP- you should never leave an op-amp unconnected, it'll oscillate or pick up the signal from the other side and clip and heat the package, draw lots of currentand cause the other one to misbehave. Hook it up as a unity gain buffer and ground the input.

    - the circuit could damage the arduino since it can drive the input past the arduino's rails. Better to run the op-amp off 0-5V (maybe something with RRIO).Create the VCC/2 bias with a bias network on the + input of the opamp, and AC couple the input and configure as an inverting stage. There's an example othat here: http://www.ecircuitcenter.com/Circuits/opinv_ss/opinv_ss.htm just don't need the output cap (or load R), just go to the Arduino from the opampoutput. Also putting a cap in parallel with R2 (from the linked schematic) will give you a bit of a low pass filter, to help with aliasing. with a 200K R, 100pFwould give you a corner of 8KHz, first order filter which would be a good start.

    amandaghassaeisays: Jan 13, 2014. 9:06 PM REPthat's a good point about the op amp, I hadn't thought of that.

    hilukaszsays: Dec 2, 2013. 10:09 AM REPhey sorry for the stupid question, but you mention you are wiring in series to get 9v, but wouldn't that actually give you 18v if you did series and not the 9vyou suggest?

    amandaghassaeisays: Jan 13, 2014. 9:04 PM REPit gives me +9 and -9, yes technically an 18v spread, but usually when you talk about the power supply for an op amp you talk about the +/-V, in this ca+/-9V

    http://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/hilukasz/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/hilukasz/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/bowerymarc/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/bowerymarc/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/chimplost/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/chimplost/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/ss1306/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/ss1306/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/raghavlite/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/raghavlite/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/bearblue/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/bearblue/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/mavriksc/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/mavriksc/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/akellyirl/http://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/foobar8675/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/foobar8675/?utm_source=pdf&utm_campaign=comments
  • 8/12/2019 100 Yard Paper Rocket Launcher

    19/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    steveazhocarsays: Dec 20, 2013. 7:16 PM REPyes it is automatically triggered every time a new analog measurement is complete.

    matteoM1983says: Nov 17, 2013. 5:24 AM REPHi Amanda, thank you for this excellent tutorial! I'd have a couple of questions about the circuit and will be very grateful if you could answer! :-)

    As in many other tutorials, the choice of resistors and capacitors seems to me (I'm very uneducated in hardware) a bit mysterious.

    Question 1) From what I understand, the choice of 100k/10k resistors for the opamp is arbitrary, all that matters is the 10:1 ratio. Is this correct? Similarly, tchoice of 100k/100k for the voltage divider is arbitrary: you could have used 10k/10k or 100ohm/100ohm

    Question 2) Somebody else already asked bout the 49nF capacitor. Interpreting your answer (reducing noise) I guess what this capacitor does is, basically

    trying to compensate (i.e., average) changes in the signal. Since this is a very small cap, it helps compensating changes in (what we could consider as) theleast important bits of the signal, which are what rumor is about (hopefully).

    Question 3) What about the 10uF capacitor? What does it do? Why 10uF? Could we eliminate it entirely from the circuit? What would change? And if not,why?

    It seems to me that, without the 10uF cap, the opamp (at the moment when it is emitting -2.5V) would receive some current from the +2.5 side (I guess(5/100k)A = 0.05mA having the 100k resistor). Is this correct?

    THANKS!!!!

    akellyirlsays: Dec 10, 2013. 2:44 AM REPHi Matteo,

    1) The resistor values can't be too small (100Ohms) because the op-amp has to drive that current e.g. 1V/100 = 10mA. It also can't be too big becauseop-amp leakage current will cause an offset voltage that gets gained up by the amplifier too.

    2) The 49nF cap is usually used to reduce high frequency noise. But it's ineffective in this circuit because it being driven by a 10uF capacitor.

    3) The 10uF cap is used to block DC. It forms a high-pass filter with the 100k resistors. It will pass frequencies above 1/(2*pi*R*C) i.e. 1/(2*pi*50k*10u)0.32Hz. The reason you need to block DC here is because you want to bias the Arduino Analogue input to Vdd/2 but you don't want that the DC currento flow into the op-amp.

    matteoM1983says: Dec 12, 2013. 1:34 AM REPThank you very much for the nice and instructive answer!

    A) Answer 1) is very clear! thanks!

    B) Could you please elaborate on answer 2) ?

    Which Cap value should be chosen in place of 49nF to effectively reduce high-frequency noise? And how this work precisely? I guess It should woas a Low-Pass filter, but where is the associated resistance? (I have this picture in mind:http://upload.wikimedia.org/wikipedia/commons/3/3b/RC_Divider.svg )

    C) shouldn't the expression be 1/(2*pi*100k*10u) = 0.16Hz ?

    It seems from your explanation that the value 10uF for the cap (which is anyway necessary to block DC as you explained) is chosen as a function o100kOhm, basically to allow all frequencies to pass.

    Is it correct to say that a 1F cap would work in this context even better? (but of course it would be much bigger and expensive and give just a verysmall better result in terms of filtering)

    Or perhaps a 1F cap would create problems, as it will allow the DC to pass (just after the circuit starts running) for a way too long time? Thank youvery much again!

    akellyirlsays: Dec 13, 2013. 7:55 AM REPB) The associated resistance is actually the reactance of the 10uF cap. Because there is no resistance involved there is no value of capacitancthat will make this arrangement work.

    C) It's actually 50k because the 100k resistors appear to be in parallel for AC analysis (because both GND and +Ve are GND from an ACperspective).

    As a rule you choose the smallest practical value of capacitance, even if a larger one might work.

    matteoM1983says: Nov 19, 2013. 2:27 PM REPSearching the web for ideas about question 3) above, I discovered this is probably a so-called "coupling capacitor".

    I only found very generic and not clear informations about how this work. Basically "stops DC and allow AC to pass". This is compatible with the idea ththe +2.5 stay fixed on the left, and the -2.5,..,+2.5 can pass making up 0..+5v.

    However I'd like to understand how this can happen, in a (relatively) precise way.Could you spend a few words on this please? It seems to me that this is a very interesting and possibly crucial part of the circuit :)

    THANKS!

    http://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/matteoM1983/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/matteoM1983/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/akellyirl/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/akellyirl/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/matteoM1983/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/matteoM1983/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/akellyirl/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/akellyirl/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/matteoM1983/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/matteoM1983/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/steveazhocar/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/steveazhocar/?utm_source=pdf&utm_campaign=comments
  • 8/12/2019 100 Yard Paper Rocket Launcher

    20/21

    http://www.instructables.com/id/Arduino-Audio-Input/

    arodriguez cuetosays: Nov 4, 2013. 3:35 AM REPhi amandaghassaei.Thanks a lot for this HQ tutorial!Could yo please expand on how hacking the A/D conversion rate works on a fundamental level?I thought its conversion rate was a fundamental aspect of A/D and could not be changed.What negative aspects does this bypassing carry?Thank you!

    amandaghassaeisays: Nov 4, 2013. 9:58 PM REPthe conversion from A to D takes a certain number of clock cycles (13), but the length of each clock cycle can be changed. That's essentially what I didhere. By speeding up the clock to 500kHz, 13 clock cycles takes less time and the analog to digital conversion happens faster. There are some trade-othough, it's best to keep the clock slow to give time for the analog pins to settle and minimize noise in your analog measurements. Hope that helps!

    kilianciuffolo says: Nov 3, 2013. 2:24 PM REPThanks so much Amanda!

    I have I question for you though, what is the purpose of the 10uF Cap? My understanding is that the output from the amp is -/+ 2.5V. Connecting it directly to t+2.5V wouldn't have the same result? (I know that the answer is no, but it would be nice to explain deeply the flow of electron for the DC offset and why weneed the cap).

    Also the cap will "store" 5V right? Delta V from +2.5V divider and -2.5V from the amp. Not sure how it works when it is discharging. Vout from the cap will be 5and DeltaV from cap to voltage divider will be 2.5V, will this create a 5V signal?

    If am correct, a cap with just 2.5V "stored" will not discharge at all since delta V would be 0 between Vcap and Vdivider, am I right?

    mjconversays: Oct 11, 2013. 5:04 PM REPDoesn't two 9 volts in series = 18 V? That's higher than 15, not lower.

    kilianciuffolo says: Nov 3, 2013. 1:55 PM REPIt's 18V but from -9V to +9V! The total input voltage allowed is 30V (+-15V).

    amandaghassaeisays: Oct 12, 2013. 4:31 PM REPit's +9 and -9 vs +15 and -15

    timmyadusays: Oct 26, 2013. 3:48 PM REPHi Amada, thanks for the awesome instructable.Quick question: you have set the ADC to be auto triggered. So what's the auto-trigger source?

    amandaghassaeisays: Oct 27, 2013. 2:05 PM REP

    yes it is automatically triggered every time a new analog measurement is complete.

    Alderinsays: Oct 1, 2013. 11:31 AM REPScaling from 10 bits to 8 bits may be quicker with bit shifting instead of that extra math:

    incomingAudio = (incomingAudio+1)/4 - 1;

    to

    incomingAudio = incomingAudio >> 2;

    True division is computationally expensive, so depending on how smart the optimizer is in the compiler, bit shifting for dividing by powers of two could save asignificant amount of processing time. This also avoids divide-by-zero protection requirements (+1/-1 in your original code). I would also do the negative numbprotection before bit shifting, as results of bit shifting negative numbers can be confusing.

    amandaghassaeisays: Oct 2, 2013. 2:19 PM REPgood call

    6400says: Sep 2, 2013. 8:57 AM REPThis method can be used to run a servo motor?please its support

    thank you

    http://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/6400/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/6400/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/Alderin/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/Alderin/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/timmyadu/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/timmyadu/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/kilianciuffolo/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/kilianciuffolo/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/mjconver/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/mjconver/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/kilianciuffolo/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/kilianciuffolo/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/arodriguez+cueto/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/arodriguez+cueto/?utm_source=pdf&utm_campaign=comments
  • 8/12/2019 100 Yard Paper Rocket Launcher

    21/21

    amandaghassaeisays: Sep 8, 2013. 9:09 PM REPyes, use the value returned by ADCH to control the servo.

    6400says: Sep 9, 2013. 3:43 AM REPMr. amandaghassaei Can you help how schema and scripts of the design?

    thx

    amandaghassaeisays: Sep 8, 2013. 9:09 PM REPhelps remove noise in the input signal

    asuba??says: Sep 1, 2013. 8:31 AM REPWhat does the 47nF capacitor do?

    amandaghassaeisays: Sep 8, 2013. 9:08 PM REPhelps remove noise in the input signal

    amandaghassaeisays: Sep 8, 2013. 9:08 PM REPyeah, you'll have to lower the sampling rate to free up more time to sample from two inputs.

    view all 174comments

    http://id/Arduino-Audio-Input/?comments=all&sort=OLDEST#commentshttp://id/Arduino-Audio-Input/?comments=all&sort=OLDEST#commentshttp://id/Arduino-Audio-Input/?comments=all&sort=OLDEST#commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/asuba%C5%9F%C4%B1/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/asuba%C5%9F%C4%B1/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/6400/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/6400/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/id/Arduino-Audio-Input/?utm_source=pdf&utm_campaign=comments#DISCUSShttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=commentshttp://www.instructables.com/member/amandaghassaei/?utm_source=pdf&utm_campaign=comments