65Views1Replies

Author Options:

Arduino alarm clock help! Answered

Hello I am trying to make a pressure switch for my alarm clock where when I stand on it for a certain amount of time the alarm will stop. I've never done any arduino work before so I was wondering what board would best suite me for this project. I found this one but I don't know if it will work. https://www.gearbest.com/development-boards/pp_629... I also found some code online that I think would work. Here is the link for the code: https://arduino.stackexchange.com/questions/1193/a... Also would this be how I would set the entire thing up?Do I need any resistors? What type of power supply would I be able to use?

Discussions

0
None
PKM

8 months ago

There are two ways of "pressing a button" on an alarm clock that should work on almost any clock: use a servo to physically press the button, or use a relay to connect the two contacts together. The servo can be more fiddly but means no electrical work on the alarm clock at all, the relay is an electrical solution that needs a bit more work.


If you're using a servo, just physically attach it to the clock somehow with a horn positioned to press the button when you move it to a certain position. If using a relay, you'll want to connect the normally open (NO) and common terminals to the two wires on the button you are replacing.

To drive a relay from an Arduino I think you'll need a transistor to drive the coil, a resistor for the transistor's base pin and a diode connected backwards across the relay coil to prevent flyback from harming the transistor or Arduino. There are probably many Instructables on driving a relay with an Arduino - the Aruidno website has a circuit diagram here http://playground.arduino.cc/uploads/Main/relays.p...

Regarding making the Arduino wait for some time before pressing the button, you will want a main loop that continually checks whether the button is pressed. If it is, it can keep checking how much time has elapsed while the button is pressed until the desired time is reached, or reset the elapsed time if the button is no longer pressed. The code you linked only cares if the button is pressed when the timeout is reached and won't reset if the button is released during that period.

You shouldn't need any kind of special power supply, if you are only driving a single relay you could probably do it with USB power from a phone charger as long as the relay is one that will switch with a 5V supply.

------

More general Arduino advice: If I was building a new project like this I'd try to break it down into parts. Write some code that will turn on an LED when you hold down a button for more than five seconds. Glue a servo to your alarm clock so the servo sweep code will press the button, or wire up a relay to turn on and off so you can flash an LED with that. Once you have all the parts, you can combine them into the complete project you want to make, and if you have problems with any individual part you can look for help with eg. relay control without involving the timing part of the code as well.