I receive the message "test" only if I comment out the line in loop(). Putting a delay in loop() doesn't help. I'm not sure what's wrong here, does anyone want to explain?
Ok. I did your code. The analog did read something, and it was going "nuts"...
So I change a bit, put a delay in loop() function, and I have a reading and the test did show. I simply place a piece of wire at analog pin 5. The reading was a floating value ( any values from 0 to 1024 ) which I was expecting.
I don't know what you did ( the hardware section ), but if you need to read a mic, you need some amplification and make sure the signal goes from 0 V to 5 V. Not in the minus range... it will damage your Atmega chip.
I have a Duemilanove, and I need to read the microphone faster than once per second (the faster the better). It just seems like the code never runs properly when I try this. I am sure the microphone is giving values from 0V to 5V, already tested.
I wonder whether the problem is caused by Serial.print() or analogRead(5).
Suggest you try printing an arbitrary int, and calling analogRead() (but not printing the result) and see whether either of them on their own is causing the problem.
That should work fine, as long you connect properly, like +5 to +5 of the Ardiuino, GND with the Ardiuno, and Out at analog pin 5. You should expect a reading value around half of 1024 , if the level of sound in your room is quiet. I use my code modification ( with the delay(1000); or Nick Gammon code, but add a delay(1000); because the serial display will go fast, ( fast scrolling ) Heh you can still use Nick' code and disconnect the Arduino so you see the result of the serial output.
I have a Duemilanove, and I need to read the microphone faster than once per second (the faster the better). It just seems like the code never runs properly when I try this. I am sure the microphone is giving values from 0V to 5V, already tested.
I am sure the code is fine. The way the code is, that the fastest you can get. It only got one line in loop()... it Serial.println(analogRead(5)); That it ! And you should have a reading about 300 to 700 <-- +/- 2.5 V, but on average close to 500.
void loop()
{
Serial.print(analogRead(5)); // reads from microphone
}
I receive the message "test" only if I comment out the line in loop(). Putting a delay in loop() doesn't help. I'm not sure what's wrong here, does anyone want to explain?
Step 1. Disconnect all external devices (eg. microphones) and cables, except the cable connecting the Arduino to your PC, and run the test again. You should see random values shoot by as the analogRead picks up noise.