1

I want to take input from a clock for a specific time and respond to it.

I am taking alarm as input because it will send some signal to a buzzer and I want to decode it through Arduino.

I am using Arduino Uno.

The program I used is as follows:

int b = 0;

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

void loop() {
    b=digitalRead(8);
    Serial.println(b);
    if(digitalRead(8) != 0)
    {
        Serial.println("input in 8");  
    }
    else
        Serial.println("not");

    delay(500);    
}

I have removed the buzzer from the clock and connected the terminals to Arduino pin 8 and GND.

But the output is always random (i.e. 0 & 1), no matter if my alarm is on or off.

I cannot find if my program has a flaw or if my approach is just wrong.

4

It is likely that the alarm clock does not provide any voltage level (I mean GND) to the buzzer when it does not have to ring, the circuit is just left "open" then; it will provide a voltage level (depending on your clock power supply) only when the alarm has to ring.

On the other side, your Arduino pin 8 must have a voltage level that can be mapped to a 0 (anything between GND and 5V/3) or a 1 (anything between 2x5V/3 and 5V).

However, in the absence of alarm, the input is left "dangling" (no voltage level at all). In CMOS technology, leaving an input pin dangling will make it randomly take 0 and 1 levels as you described.

Fortunately, the solution to this problem should be easy: you just have to force a 0 level to pin 8, by connecting it to GND through a resistor. I generally use 10K or 15K for that resistor. This is called a "pulldown" resistor:

  • when the alarm does not provide any voltage, the input pin level will be "pulled down" to GND, ie 0.
  • when the alarm provides a 5V (see important remark below) to the input pin, then it will be seen as 1.

IMPORTANT: you have to make sure that your alarm clock, when ringing, provides a voltage that is not higher than 5V (it would grill your UNO, or more precisely the ATmega328 of your UNO) and is at least ~3V to be "recognized" as 1.

NOTE: it is likely that solving this first issue will not be enough to make your complete program work, because your alarm clock probably does not send a continuous voltage to your buzzer but and alternate one to make it ring, hence you will get successive 1 and 0 at high speed (between 100Hz and 100Hz I would say) in your program. If that is the case please open another question as the solution for that specific issue is disconnected from the current one (random 1 and 0).

  • A 10k pull-down resistor should also help to stabilize the signal. – Dat Ha Oct 29 '16 at 16:33
  • A capacitor could help smooth the 100 Hz (or whatever) signal when the alarm is on. – Nick Gammon Oct 29 '16 at 21:44
  • If you have access to an oscilloscope, it would be beneficial to take a reading of what output the clock makes when the alarm is on. (ie whether it is AC or DC and what voltage it is). – sa_leinad Nov 2 '16 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.