Speaker analog values are printing different every time

hi im making a project that read the speaker values
White - A0
black - GND

const int doorbellPin = A0; 
const float thresholdVoltage = 0.05; 

void setup() {
  pinMode(doorbellPin, INPUT); 
  Serial.begin(9600); 
}

void loop() {  
  float dVoltage = analogRead(doorbellPin) * (5.0 / 1023.0);

Serial.println(dVoltage);
  delay(100); 
}

it is printing different values every time even I'm playing the same sound
so i can put it into if function to no and off the relay

The signal that you're reading is more than likely an AC signal. That signal varies in level and hence you're getting different values.

As said above by @sterretje, you're probably reading an AC signal.

Since it's a doorbell, it's also quite possible you're feeding a signal into the Arduino that exceeds its design limits. Can you show a circuit diagram/schematic of your setup, and a good photograph that shows how everything is connected?

Keep in mind that identifying a specific tune played by the doorbell in the way you have set this up will likely not be feasible. It will be feasible to detect if a tune is playing, or not. But not identifying a specific tune. Unless the tunes vary in duration, because then you might be able to determine how long each tune is and then use that information to work a relay etc.

1 Like

Hi, @ehrishita
Welcome to the forum.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

What do you expect to get from the input when you play a tune for the speaker to pick up.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

I don't think OP can as he/she is suspended.

Why?

Tom.. :smiley: :+1: :coffee: :australia:

Click on his name in the first post, to find out.

1 Like