Hi guys,
I'm very new to all this electronics lark, but really wanting to try to expand my knowledge to try to advance my University project that is ending in the next month.
I have been attempting to work with sound sensitive light systems, but most are gimmicky DJ lights and this is not the desired effect.
I therefore bought myself a sound sensitive microphone (http://www.ebay.com/itm/High-Sensitivity-Sound-Microphone-Sensor-Detection-Module-For-Arduino-AVR-PIC-/310917761903) and am attempting to assemble this with my Arduino which I currently use for a lighting project involving strobe effect. I have transistors, capacitors, resistors, LEDs and all the cabling I should need, but I am absolutely baffled as to where to start with the coding side of things for the arduino, and the layout of the components on a breadboard.
If anyone is able to advise me on the possibilty of this working, and if any advice on layout and coding is availble I would be truly grateful, as I am finding myself in a bit of a electronics knowledge gap that I need to climb out of very quickly
Thanks either way in advance,
Nick
Yes.
What are your Design Criteria ?(specifications)
Research is how all projects should start.
Google is a good research tool. I used the terms 'Arduino Microphone LED' and got a number of good leads, including this one:
Mr. B,
I have been attempting to work with sound sensitive light systems
Doesn't that sound like the color organs of the 60's ?
Doesn't that sound like the color organs of the 60's ?
That it does! I had about forgotten the '60's except for flashbacks
There should probable be some "black light" Arduino projects!
Ray
I was thinking mmore along the lines of a Laser Light show to Voodoo Child.
PS-The Flashbacks are Freebees...
along the lines of a Laser Light show to Voodoo Child.
Hendrix! Yes.
...then, there was Blind Faith.
CREAM/CROSSTOSDSV
If you want help post your Criteria
Thanks for the help so far, but the post that was supplied (although seems good for the wiring that I'm still a bit stuck with) the outcome is not to have a visual LED panel of sound, but to project the light like a light bulb would but through the use of numerous LEDs. The project is to react to people talking in a small space, or clapping etc with a light that would fill the room.
I have that microphone, but I am confused as to how to wire it to the arduino and then how I would wire the output of the LED in (I have wired output LEDs a few times before to use a strobe which was a just a simple set up using LEDs and resistors going into pin 3 and grounded, I just wish I understood more about the pin 3 pin 13 situation...)
As you can probably tell I'm only weeks into Arduinos and not much longer into any electronics to be honest...
The microphone has 4 pins unlike the ones in the links that have three and I only really know the positive due to the plus. The others are a bit lost on me...
Anyway any help is very much appreciated as I previously said. Sorry if I seem a bit clueless but to be honest I am, although the help that I gain will be going towards my final project for my degree so thats why its a bit of a steep learning curve at the moment.
Many thanks
It is in the first post mate. The exact microphone. The problem is the fourth pin on the microphone as it just seems to have two 00 together or maybe two DD... then of course there is A0 which I plug straight in, then pos and ground.
I am using a found code at the moment but it doesnt seem to work. Heres the code I'm using.
/*
This is the code to make a LED blink with the music.
You have to set the threshold so it' sensible enough to make the led blink.
You connect an LED to PIN13 and the Sound Sensor to Analog Pin 0
*/
int led = 13;
int threshold = 500; //Change This
int volume;
void setup() {
Serial.begin(9600); // For debugging
pinMode(led, OUTPUT);
}
void loop() {
volume = analogRead(A0); // Reads the value from the Analog PIN A0
/*
//Debug mode
Serial.println(volume);
delay(100);
*/
if(volume>=threshold){
digitalWrite(led, HIGH); //Turn ON Led
}
else{
digitalWrite(led, LOW); // Turn OFF Led
}
}
Thanks again
Sorry mate, I don't know how I missed that.
Anyway , here is a description of how to use your board:
High sensitivity; The module has two outputs: AO, analog output, real-time output of the microphone voltage signal / DO, when the sound intensity reaches a threshold, the output high and low signal threshold
- Sensitivity potentiometer adjustment. Uses 5V DC power supply; with power indicator Dimensions: 1.69 in x 0.63 in x 0.51 in (4.3 cm x 1.6 cm x 1.3 cm) Weight: 0.18 oz (5 g)
The potentiometer sets the threshold digital output level. I've never used it but if I had to guess , I would say that if you want to record or measure low level sound you set the pot lower. If you want to measure louder sound you set it higher. The purpose of the digital output D0 is to tell the uC that the sound is at the chosen level , hence it is a trigger line out to tell the uC when to begin sampling and storing the sampled data to an SD card.
You need to calibrate you setup mate.
Get a radio or cassette and increase the volume while you play with the pot. Set the radio to a level equivilent to the level you want to trigger the lights and leave it at that level, then gradually increase the pot on the board CW until the led lights up.
Then it should be ready to run code. If your code works when you start the program with the volume turned down, nothing should happen. When the volume gets to the calibrated threshold , the D0 (dee zero) should go high and your arduino should start turning on lights or whatever. Give that a try.. Here's the link:
http://insanesupply.com/Insane-505135533
The chip is an LM393 dual comparator used for the level detector. That chip can't supply very much current so the code you're using would be fine except for the fact you are not using the D0 output for a digitalRead. You need to let the board tell you when
the level is high enough instead of using the analog to look for 2.5V, First of all mate, it's audio. You can't connect to it directly.
you need a 1uF cap and I didn't see that. I saw 6 resistors , four of which are probably part of the threshold detector circuit and the other two look like they are current limits for the leds (if that's what those are (low level and high level ).
Put a 1uF cap between A0 out from the board and the arduino A0 in. Audio is going to be very low level , maybe 1V pk to pk. I didn't see an amplifier on that board the chip is a comparator not an amplifier so good luck measuring 500 with your analog input. I estimate the highest value you'll see is 200. If you decide to build an audio pre-amp with op amps I can help you with that. I have a schematic I can post if you need it. Or you could get this:
http://www.ebay.com/itm/LM386-Audio-Amplifier-Module-for-Arduino-Raspberry-Pi-/221423330883?pt=LH_DefaultDomain_0&hash=item338ddbe643
or this:
http://www.ebay.com/itm/LM358-op-amp-operational-amplifier-signal-amplification-module-for-Arduino-/270955305006?pt=LH_DefaultDomain_0&hash=item3f1631d82e
Hi again mate,
Sorry for the late reply, been in the thick of a building project for the piece of work and the logistics have been a nightmare!
Right, I have bought a couple things since the last post. I bought the amplifier as you previously posted, but I havent really tested it properly as of yet as I found a new thing to give a go, which is this SparkFun Electret Microphone Breakout - BOB-12758 - SparkFun Electronics but having just as much problems with this as before, As although I have used some code to find the output, it seems very unreactive especially to sound from a distance of anything more than about a foot or 2, away from loud sounds like slamming doors that seem to work...
The first thing I really need to know is whether the microphone is sensitive enough to pick up the signal of voices within an 8ftx8ft wooden cube, with the microphone due to be at the top of the cube facing downwards from the roof... I've tried using a few different codes to see but they all seem to be reactive to only louder/sharper sounds (in the same way the microphone alone was before using an amp with it originally...) I know have two microphones, an amplifier and this Sparkfun breakout board, and I will be trying the amplified microphone in a few minutes, but I have to say I'm starting to panic a bit. I have to get it sorted asap for my final show and am beginning to worry as I am trying to learn quickly with the arduino.
Coding wise I found a couple of codes that should essentially work, one that seems ideal but, although reactive in the way that I would like (the light going on when noise is present close to it and at a relatively similar level and length of time as the voice) it instead blinks instead of just turning the light on fully or gradually in accordance with volume... the reason I went sparkfun was due to this code and the explanation on this website Inkling but I have no idea why it would blink instead of just turn on... In regards to the sensitivity and this coding issue, it leaves me with two massive worries lol I'll past the code below to show you what I mean:
/*
microphone sketch
SparkFun breakout board for Electret Microphone is connected to analog pin 0
*/
const int ledPin = 13; //the code will flash the LED in pin 13
const int middleValue = 512; //the middle of the range of analog values
const int numberOfSamples = 128; //how many readings will be taken each time
int sample; //the value read from microphone each time
long signal; //the reading once you have removed DC offset
long averageReading; //the average of that loop of readings
long runningAverage=0; //the running average of calculated values
const int averagedOver= 16; //how quickly new values affect running average
//bigger numbers mean slower
const int threshold=400; //at what level the light turns on
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
long sumOfSquares = 0;
for (int i=0; i<numberOfSamples; i++) { //take many readings and average them
sample = analogRead(0); //take a reading
signal = (sample - middleValue); //work out its offset from the center
signal *= signal; //square it to make all values positive
sumOfSquares += signal; //add to the total
}
averageReading = sumOfSquares/numberOfSamples; //calculate running average
runningAverage=(((averagedOver-1)*runningAverage)+averageReading)/averagedOver;
if (runningAverage>threshold){ //is average more than the threshold ?
digitalWrite(ledPin, HIGH); //if it is turn on the LED
}else{
digitalWrite(ledPin, LOW); //if it isn't turn the LED off
}
Serial.println(runningAverage); //print the value so you can check it
}
Then I found another example that didnt work at all originally, which is the following code:
/*
This is the code to make a LED blink with the music.
You have to set the threshold so it' sensible enough to make the led blink.
You connect an LED to PIN13 and the Sound Sensor to Analog Pin 0
*/
int led = 13;
int threshold = 500; //Change This
int volume;
void setup() {
Serial.begin(9600); // For debugging
pinMode(led, OUTPUT);
}
void loop() {
volume = analogRead(A0); // Reads the value from the Analog PIN A0
/*
//Debug mode
Serial.println(volume);
delay(100);
*/
if(volume>=threshold){
digitalWrite(led, HIGH); //Turn ON Led
}
else{
digitalWrite(led, LOW); // Turn OFF Led
}
}
The above was from this website which has a youtube showing a similar thing (seems to be minus amplifier) but reacts to music perfectly well... Feel like I'm a bit cursed with this project at the moment lol
I then modified the two codes to make them work just by pasting in the second part of the second code into the first, but then I lost all output on the serial, and any adjustment that does all of the sums in the first one... Heres that horrible hybrid mess ha:
/*
microphone sketch
SparkFun breakout board for Electret Microphone is connected to analog pin 0
*/
const int ledPin = 13; //the code will flash the LED in pin 13
const int middleValue = 512; //the middle of the range of analog values
const int numberOfSamples = 128; //how many readings will be taken each time
int sample; //the value read from microphone each time
long signal; //the reading once you have removed DC offset
long averageReading; //the average of that loop of readings
long runningAverage=0; //the running average of calculated values
const int averagedOver= 16; //how quickly new values affect running average
//bigger numbers mean slower
const int threshold=800; //at what level the light turns on
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
sample= analogRead(0); //the microphone takes a reading from analog pin A0
if (sample > threshold)
{
digitalWrite (ledPin, HIGH); //if the reading is greater than the threshold value, LED turns on
delay (250); //LED stays on for a half a second
digitalWrite (ledPin, LOW); //LED turns off
}
else{ digitalWrite(ledPin, LOW); }
}
The above made it work without the blink, but as mentioned I lost all serial output (I have since tried to write it in with no joy) and also added a delay, which just isnt what I was looking for to be honest. I wanted the flicker to work with peoples voices, so in accordance with a soundwave kinda thing, so the louder and longer the person speaks the brighter and longer the brightness lasts...
I apologise again for being so lacking in knowledge with this, but I really am trying as you can probably tell so hopefully that should negate some of my relative stupidity lol For all of the above, I tried changing the threshold to suit the average between the numbers, but either the light just stayed constantly on when lowering the value below 500, or went even less sensitive to the sound when moving the value toward 1000 to test it out...
This is the last bit of code I'll post, as this was my attempt at seeing if the serial monitor could sense any sound (minus output) from the breakout board from about 8ft away, but the numbers barely moved unless clapping into the microphone, or again things like doors shutting make a difference but that's not really what I'm going for...
int sensorValue;
void setup()
{
Serial.begin(9600); // sets the serial port to 9600
}
void loop()
{
sensorValue = analogRead(0); // read analog input pin 0
Serial.println(sensorValue, DEC); // prints the value read
delay(100); // wait 100ms for next reading
}
All seemed to be within the 400 and 600 values but fluctuating even when quiet...
Here is a list of all the bits I have for the arduino just so we know what I'm working with...
http://www.ebay.co.uk/itm/351020212990?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
http://www.ebay.co.uk/itm/281169092289?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
http://www.ebay.co.uk/itm/191126721706?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
I have done a bit of reading and wonder if it would help and make any difference to bite the bullet and go for something which seems to be a little more comprehensive... Lots of things about sound pressure being mentioned in the posts I'm searching through and this seems to detect it, but its costly and I dont think I'd have the foggiest idea how to adapt a code for it as it seems pretty complex and of course as we have figured I'm not very good at this kind of thing yet...
Either way, any advice or help is much appreciated as it has been so far. Thanks again!
If you read my last post I said this:
Audio is going to be very low level , maybe 1V pk to pk. I didn't see an amplifier on that board the chip is a comparator not an amplifier so good luck measuring 500 with your analog input. I estimate the highest value you'll see is 200. If you decide to build an audio pre-amp with op amps I can help you with that. I have a schematic I can post if you need it. Or you could get this:
or this:
But instead, you bought a microphone with no amplifier so your back to the same issue I was addressing with the above comments. You need an amplifer. You should have got the one I suggest with the LM358 amplifier chip. Sorry Mate , but you haven't gained anything with your latest purchase.
Mate, third link down at the bottom is an amplifier... http://www.ebay.co.uk/itm/281169092289?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649 thats the one I bought, pretty sure the one you said to lol
I have had a bit of a breakthrough though since. I plugged this one in straight through the A0 (http://www.ebay.co.uk/itm/191126721706?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649) and when adjusted, the green light that indicates input works perfectly, any low voice flashes the input light, exactly as I wish I could get the LED to flash. Picks up my voice from over 8 ft away so would be perfect for my box... Obv a better model than the original one I bought. Is there any coding that would allow the pin 13 LED to just copy that of the input light on the microphone? I have resistors, capacitors etc and really want it to flash at the same rate and intensity as the input light directly on the microphone, without having to obey any kind of threshold as I believe that would limit the light to being either on or off, and turn it on at a certain volume rather than have it adjust to the volume of the voice... I can post a vid of what I mean if you like, as I'm hoping there will be a simple code that can just copy the input, either using the amplifier or not either way...
Thanks again
The cleanest way is to put a on the led , with the + lead on one end of the led and the - lead on GND. You're looking for the forward voltage of the led so if you put the meter on the cathode you won't get much but on the anode you should get 1.3V to 2V. Now look at the traces going to the led and find the current limiting resistor for the led. If it is connected to the cathode then the other end of that resistor would go to GND. In that case the voltage across the led should be close to +5V and you can solder a wire to the Anode of the led and bring that out to the arduino and connect that to a digital input and do a digitalRead.
If (ledval==HIGH)
{d13= digitalWrite(OUTPUT,HIGH);}
If the current limiting resistor is connected to the Anode of the led on the breakout , then the voltage you want to tap is on the other end of that resistor (about +5V) and that's where you connect your wire. The breakout already has GND connected so you only need the one wire. Either way , you are looking for the signal that drives that led, to read with your digitalRead and turn on
whatever based on that condition. The longer way is find the analog threshold that is set by the trim pot on the breakout and that's more complicated.
raschemmel:
If (ledval==HIGH)
{d13= digitalWrite(OUTPUT,HIGH);}
And the return type of digitalWrite is . . ?
(Not to mention the pin number parameter)
Yeah yeah, I was in a hurry. I meant
digitalWrite(d13,HIGH);
It was a poor choice of name (ledval) for a digital input signal from the breakout led.