the following code and circuit does not work , instead LED blinks continuously without clap, even blinks after removing all components with GND and pin 7 connection.
please help
const int analogInPin = A0; // Analog input pin 0
int sensorValue = 0;
void setup()
{
DDRD = 0xFF;
}
void loop()
{
sensorValue = analogRead(analogInPin); //read ADC value on channel 0
if (sensorValue > 60)
{
PORTD ^= (1 << 7); //If there is a peak toggle the LED on and OFF on pin7.
delay(250);
}
}
Hi Soham, welcome to Circuit Digest forums
As Tedder rightly pointed out the problem might be with the absence of pull up or pull down resistor.
When you are reading the analog values from a Analog pin of Arduino, the pin should always be connected to some voltage potential. If it is left free it is called as floating pin, and can give any random value to the ADC module.
One best feature in Arduino is with the ease of debugging ,so use serial monitor and print the value of sensorValue so that you yourself can debug your code. An image of the circuit will help you in getting more relevant answers.
tedder
PermalinkYou didn't say what you are using as a 'sensor', but you are probably failing to use a pullup/pulldown.
- Log in or register to post comments
Joined October 01, 2018 2Monday at 04:44 AM