Trying to print a value to serial port for a vu meter using arduino uno
i constructed simple vu meter circuit using mic, 8 led's, , arduino uno. mic output connected a0 , led's connected digital pins 2-9. understanding if prints serial port should see values 0-1024 depending on output of mic , should 0-5 volts. when run values -1 40 depending on volume of sound. how can change code print values can translate voltage?
any appreciated. thanks.
here code far.
any appreciated. thanks.
here code far.
code: [select]
#define numreadings 5 // number of readings (increase slow curve)
#define minsound 25 // min sound intensity
#define maxsound 125 // max sound intensity
const int firstled = 2;
const int lastled = 9;
int leds;
int readings[numreadings];
int index = 0;
int total = 0;
int average = 0;
int sound = 0;
int x = 0;
int y = 0;
void setup() {
serial.begin(9600);
(int r = 0; r < numreadings; r++) {
readings[r] = 0;
}
(int p = firstled; p <= lastled; p++) {
pinmode(p, output);
}
leds = (lastled - firstled) + 1;
}
void loop() {
total -= readings[index];
readings[index] = analogread(0);
total += readings[index];
index++;
if (index >= numreadings) {
index = 0;
}
average = abs((total / numreadings) - 338); // ((1024 * 300) / 1000) = ~338
sound = map(average, minsound, maxsound, 0, leds);
(int ledon = firstled; ledon < (firstled + sound); ledon++) {
digitalwrite(ledon, high);
}
(int ledoff = (firstled + sound); ledoff <= lastled; ledoff++) {
digitalwrite(ledoff, low);
}
digitalwrite(10, high);
digitalwrite(11, high);
serial.println(sound);
}
quote
from understanding if prints serial port should see values 0-1024 depending on output of mic , should 0-5 volts.
yes means not getting 5v on analogue input.
forget fancy averaging, raw output , print , see if full range. taking average of audio waveform should give value of 512. suggests audio signal not biased correctly on arduino input. can post schematic of have?
averaging audio waveform not give vu reading because positive peaks of audio cancel negative ones.
Arduino Forum > Using Arduino > Programming Questions > Trying to print a value to serial port for a vu meter using arduino uno
arduino
Comments
Post a Comment