# Using fluctuating voltage as an input

I had an idea to hack a wireless doorbell so it could send notifications to my phone when someone rings the doorbell.

I pulled out the PCB from the doorbell and powered it using the +5v from the Arduino - so far so good

I used the (once was a wire to the speaker) as an analog input

The issue I have is that the voltage for the chime continues for a long time. eg its at 0 before push then it fluctuates for a second, then returns to 519 for a while, before eventually returning to 0.

Is there a smarter way to do this - I have included my code below.

``````void loop()
{
//detect a changing voltage
delay(500);

//if the voltage changed then +1 to the ring counter
if (val != oldVal) {
ringCounter = ringCounter+1;
}

if (ringCounter > 3 && pinDevid1State == false) // someone pressed the doorbell
{
if(DEBUG){Serial.println("pinDevid1 is HIGH");}
pinDevid1State = true;
Serial.println("DingDong");
digitalWrite(ledPin, HIGH);
delay(5000);

//reset vars
val = 0;
oldVal = 0;
ringCounter =0;
}

if (ringCounter < 3 && pinDevid1State == true) // the doorbell stopped ringing
{
if(DEBUG){Serial.println("pinDevid1 is LOW");}
pinDevid1State = false;
digitalWrite(ledPin, LOW);
Serial.println("DingDongEnd");
//Sending request to PushingBox when the pin is LOW
//sendToPushingBox(DEVID1);    //Here you can run an other scenario by creating a DEVID2 variable

//reset vars
val = 0;
oldVal = 0;
ringCounter =0;

}
``````
• What are you trying to solve/improve/create? Does this work the way you want it to? – JRobert Dec 20 '15 at 14:36
• Expecting two `analogRead()`s half a second apart not to differ at all isn't realistic, I think. Low order bits fluctuate a lot if there's any electrical noise at all in your system. – James Waldby - jwpat7 Dec 20 '15 at 20:17
• @jwpat7your right but the way the logic works is most of the time they are the same... Its only when the door bell is pressed that it then is consistently different for 30 seconds - hence the ring counter – Rob Dec 23 '15 at 20:19
• @JRobert It does do what I want it to do - I just wondered if there was a more intelligent way to trigger a notification from a change in voltage. I guess my issue is there will be positive voltage while the speaker wire tries to power the speaker. I wonder if there is another pin on the board I could read - I want the bell to responsive to people impatiently pressing = multiple notifications and fast so there is as little delay as possible – Rob Dec 23 '15 at 20:23
• I will try with an hysteresis, – Ôrel Dec 24 '15 at 6:11