arduino based clap switch

soham's picture


Joined: Sep 30, 2018

Replies: 0
arduino based clap switch
September 30, 2018 - 5:41pm

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.

tedder's picture


Joined: Oct 01, 2018

Replies: 2

You didn't say what you are using as a 'sensor', but you are probably failing to use a pullup/pulldown.

Jayant's picture


Joined: May 19, 2015

Replies: 213

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.