Hi everybody.
I have set up the following circuit seen on the image. My problem is that when i try to read the values on analog input A0, the serial monitor returns the pin value of A0, which in my case is 14. My arduino is a Arduino UNO.
I have tried all kinds of ways to define the analoginput, but with the same results.
The code i executing is this simple program:
#define soundpin A0 // reads the power from the light sensor from Analog input 0
#define LED1 2 // 4 Leds LED's on Digital output pins 3,4,5,6
#define LED2 3
#define LED3 4
#define LED4 5
int sound;
void setup()
{
// initialize the serial communications:
Serial.begin(9600);
// Provide power by using the analog inputs as normal digital pins.
pinMode(soundpin, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
}
void loop()
{
sound=analogRead(soundpin); // this samples the sound constantly
if((sound)>150)
{
digitalWrite(LED1,HIGH); // set the LEDs on
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH);
}
else if((sound)>100)
{
digitalWrite(LED1,HIGH); // set the LED on
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,LOW); // set the LED off
}
else if(sound>50)
{
digitalWrite(LED1,HIGH); // set the LED on
digitalWrite(LED2,HIGH);
digitalWrite(LED3,LOW); // set the LED off
digitalWrite(LED4,LOW);
}
else if(sound>25)
{
digitalWrite(LED1,HIGH); // set the LED on
digitalWrite(LED2,LOW); // set the LED off
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
}
else
{
digitalWrite(LED1,LOW); // set the LEDs off
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
}
Serial.println(sound); //output for serial monitor
delay(500); // And a shot delay
}
Why is it that i don't get a value on the serial monitor equal to the volume my PC is outputting?
Thanks in advance, Lasy92.
