Introduction: Motion Sensitive LCD Real-Time Clock/Alarm/Timer (Updated Program)

I needed a clock for my home office (where I spend weekend mornings building robots and such) and I wanted it to fit in with the decor of my electronics work bench. I decided to build one with all the "guts" exposed. The specs were:

- Real Time Clock
- LCD Display Date and Time
- Include Minute Timer (for timing things while building projects)
- Include Alarm (to remind me I've been in here too long)
- Motion Sensitive (save power by turning off LCD when I'm not in the room)
- Look Cool on my work bench!

Step 1: Materials

- Arduino Uno (from Radio Shack)
- LCD Keypad Shield for Arduino (from DFRobot)
- DS1307 Real Time Clock (from Adafruit)
- Enclosure Box (from Radio Shack)
- Piezo Buzzer (from Radio Shack)
- PIR (Passive Infra-Red) Motion Sensor (from Parallax)
- Female/Female Jumper Wires (from Adafruit)
- 2.1mm DC barrel jack (from Adafruit)
- 9V battery clip with 5.5mm/2.1mm plug (from Adafruit)
- 9V wall wart

Step 2: Assemble RTC Board

The Adafruit DS1307 Real Time Clock breakout board kit is just that; a kit. All components are included and it's very simple to assemble with a little bit of light soldering. Adafruit provides complete instructions at http://www.ladyada.net/learn/breakoutplus/ds1307rtc.html. The kit even includes a 3 volt lithium coin cell that will keep the clock running for years.

NOTE: Photos are from Adafruit's instruction document.

Step 3: Power Connector

I wanted to be able to remove the Arduino board easily for future tinkering, so I cut the battery connector off of the 2.1mm plug and soldered the wires to the barrel jack. Then, I drilled a hole in the enclosure box and super glued the jack to the box. Now I can easily connect and disconnect the Arduino as needed.

The 9v wall wart simply plugs into the back of the box.

NOTE: If you look closely at the photo, you'll see that I drilled an "extra" hole too close to the screw post and then covered it with black electrical tape when I figured out the jack wouldn't fit there.

Step 4: Attach Cables to All Components

Adafruit sells these really cool Female/Female Jumper Wires in a ribbon cable. I use them for everything I build these days. You just tear off the number of wires you need and they make a nice little pluggable cable for each device.

I attached cables to the RTC, the PIR sensor, and the Piezo buzzer so I can easily connect them to the LCD shield.

Step 5: Connect Everything to the LCD Shield

The LCD shield has 5 rows of pins corresponding to analog pins 1-5 of the Arduio board. There's a row for 5v, GND, and signal, so I used these pins to connect the other end of my component cables. I use the analog pins to interface with the RTC, sensor, and buzzer and of course the sensor and RTC need power and ground connections.

Step 6: Mount Everything in the Enclosure Box

The next step is to attach the Arduino board to the enclosure. I had to lay the cables into the box first and hang the LCD shield to the right while I attached it. Otherwise I would have had to thread the cables through after the fact. 

I attached the Arduino to the bottom right screw post on the box. It fit securely with just one screw because the board is exactly the same height as the inside of the box and it rests against the plastic rails inside the box (top and bottom).

Next, I plugged the LCD shield on top of the Arduino and routed the wires around the right side of the boards.

The RTC board fit nicely in the bottom left corner of the box. I attached it with one screw as well. After attaching it, I was able to plug the power plug into the 2.1mm jack of the Arduino.

I had to mount the PIR sensor so that it could be easily removed since it blocks the Arduino's USB port. So I attached it using a strong piece of wire and looped it around screws on the PIR sensor board and the upper left corner of the LCD shield.

Step 7: Programming the Clock (Updated 7/30/2012)

As I mentioned in the intro, I wanted it to display the date and time, but also have functions for a minute timer and alarm.

The LCD shield has 5 programmable buttons on the front, so I used them to set the different features of the clock. The piezo buzzer creates a beep on each button push and a series of beeps for other functions like the alarm.

Programming the Arduino Sketch

I started with Adafruit's Arduino sketch for the RTC and their RTClib, which is actually a fork of Jeelab's fantastic RTC library. You can find the code at https://github.com/adafruit/RTClib.

Then I added some code from DFRobot for the LCD shield (including the button controls) available at http://www.dfrobot.com/index.php?route=product/product&filter_name=lcd%20shield&product_id=51

And, finally, I added my own code to complete the project. The completed sketch is available on github at https://github.com/mikesoniat/MotionClock.git.

The photos show the LCD as I set the different options.

UPDATED: 7/30/2012
- Fixed noon showing as 12am
- Fixed displaying PMM when switching to PM
- Added alarm set indicator (asterisk after time)
- Validate alarm hours > 0 and < 13
- Fixed allow alarm minutes to be 0 (i.e. 8:00)
- Added setDateTime feature
- Added clearAlarm feature

UPDATED: 8/1/2012 Download Updated Source Code
- Fixed default day and hour settings on set date/time
- Added maxCount to getTimerMinutes
- Fixed alarm set PM

Step 8: Function Buttons

The LCD Shield contains six labeled buttons (see the photo). I programmed the first five as follows:

Button #1 (labeled SELECT) is my Menu button. This button displays a scrolling list of available functions (Minute Timer, Set Alarm)

Button #2 (labeled LEFT) is my Select button. Click to select the displayed menu option. NOTE: Also used to increment by 10s when entering hours, minutes, etc.

Button #3 & 4 (labeled UP& DOWN) are my Increment & Decrement buttons. Click these to increment or decrement hours and minutes while setting the timer or alarm. Also used to toggle AM and PM.

Button #5 (labeled RIGHT) is my GO button. Click to accept the value entered (such as minutes and hours).

Button #6 (labeled RST) is the Reset button which reboots the Arduino

Comments

author
Balu_Sk (author)2016-10-04

How to Make this without a LCD keypad shield....?

author
RobertoCarlos (author)2016-09-02

SHOW.

TKS.

author
FikriY2 (author)2016-04-13

hey sir how if my lcd no have keypad ?
but i have push button can give me tutor ? thankss ^_^

author
sohel.haidar (author)2015-05-31

Thanks Man, you did a great job

author
RenatoL made it! (author)2015-05-15

Great Project Mikesoniat, Congratulations for shared this!

photo - 02.JPG
author
Dogdude (author)2015-02-12

Mike,

I just wanted to tell you how much I enjoyed your project. I appreciate the amount of time that went into the coding especially. I built a modified version to suit my tastes, and not being much good at writing code, it took me an extra day to get things straightened out. I ditched the PIR and built a voice recorder around an ISD1730 module and also added a DS18B20 temp sensor. It was fun and without all of your efforts would have been impossible on my own.

IMG_20150208_194425[1].jpgIMG_20150208_195501[1].jpgIMG_20150210_222845[1].jpg
author

If you want to make this project work with one of the older key pad shields that do not have the pins on it like the one shown in the above project you will have to add pins as shown in photo. Then run a jumper from the ground pin to a small bread board to create a negitive rail and do the same with the +5 volt pin.
Attach jumpers like this
Your buzzer leads:
Buzzer (+) The positive lead on your buzzer connects to A1-S - Blue Dot
Buzzer (-) The negative lead from your buzzer connects to the ground rail (row) you created on the bread board with jumper from ground pin (either of the black dots with white centers)
Your motion detector leads:
PIR Motion Sensor (VCC) The positive lead connects to your 5 volt rail on your bread board
PIR Motion Sensor (GND) The negative lead connects to your negative (ground) rail on your bread board
PIR Sensor (OUT) This is the lead your motion sensor uses to send the signal to your clock and it connects to A-2 - the yellow pin
Your real time clock:
RTC (5V) Your Real Time Clock positive lead connects to the 5 volt rail on your bread board
RTC (GND) The negative lead connects to your negative (ground) rail on your bread board
RTC (SDA) connects to A4 - Where the pin in the white dot location is.
RTC (SCL) connects to A5 - Where the pin in the red dot location is.

And do not try to power this clock with a battery. You will get lots of errors in the function of the clock. Have fun, that's the point.

DSC00384.JPGkepadLARGEcolor-coded.jpg
author
Volthaus Electronics Laboratory made it! (author)2014-12-18

Turned out great. Not in an enclosure yet. I set it on my TV totally bare. One thing is if it does not get enough voltage expect severe instability. A DC power supply is the only way to go for sure. A battery will not power this project!

dtc-arduino-motion-clock.jpg
author
Sangskie (author)2014-12-03

Hello, Can i used RTC from DF Robot? Is there a big difference if we use DF robot instead of ADAFRUIT from RTC? Thanks.

author
mikesoniat (author)Sangskie2014-12-03

Any RTC should work, although you may have to change a little code. I would refer to DF Robot for details on their library.

author

Hello, I'm just starting to build this project. And thanks mikesoniat for taking the time to put this Instructable together. It's really nice work. I've been looking forward to putting it together for awhile, and the comments are very helpful as well. My LCD shield must be an older model because it doesn't have the 15 pins in the lower right hand corner. I'll have to find a datasheet for it. It's going to be displayed in a place of honor on top of my TV. I have a nice work bench where I do my soldering but it seems I do most of actual assembly on the footstool in front of my couch. Then if need be I watch how-to videos from YouTube via my Roku on my TV while I put together the project. :-) I'll let you know how it turns out. Really I think this part is the most fun! But the story about our fellow Instructabler arnefi (see below comments) is sad. I hope he made it and saw his finished project. It appears he made his last comment sometime in 2013 so I suppose he has passed on. Bless him and I hope he's making lots of solder smoke in that big workshop in the sky.

shield.jpg
author

Thanks, and good luck with the build!

author
arif.rashid.5 (author)2014-11-02

error: 'RTC_DS1307' does not name a type

what should i do?

sorry i'm newbie

author
mikesoniat (author)arif.rashid.52014-12-03

Sounds like you need to load the RTC library.

author
curitiba.designers (author)2014-08-20

can you help me using buttons and lcd 1602 and lm 35 in first step, without lcd shield e menu? thanks!

alisoneletricista@hotmail.com

author
ash124 (author)2014-07-18

hi!

i am facing problem in my next task which is to set the alarm time of rtc through my smart phone here is the code for this task ..
#include <Time.h>
#include <TimeAlarms.h>
#include <virtuabotixRTC.h>
virtuabotixRTC myRTC(6, 7, smiley-cool;
int led=13;
char h=8 ;
char m=30;
char s=0;
void setup()
{
Serial.begin(9600);
pinMode(led,OUTPUT);
setTime(8,0,0,16,7,14);
myRTC.setDS1302Time(00, 00, 8, 3, 14, 7, 2014);}
void loop()
{
myRTC.updateTime();

// Start printing elements as individuals
Serial.print("Current Date / Time: ");
Serial.print(myRTC.dayofmonth);
Serial.print("/");
Serial.print(myRTC.month);
Serial.print("/");
Serial.print(myRTC.year);
Serial.print(" ");
Serial.print(myRTC.hours);
Serial.print(":");
Serial.print(myRTC.minutes);
Serial.print(":");
Serial.println(myRTC.seconds);
Alarm.delay(1000); // wait one second between clock display
if (Serial.available() >0)
{ h= Serial.read(); //dont know how to make
m=Serial.read();// these three commands to
s=Serial.read();//work properly through proper programming command
Alarm.alarmRepeat(h,m,s, morningalarm); // alarm set through smartphone
}
else{
Serial.println('nothing have been sent');
}}
// functions to be called when an alarm triggers:
void morningalarm(){
Serial.println("Alarm: - turn lights off");
digitalWrite(led, HIGH);
}
plz do help me out in this ...how should i receive hour minute and seconds at a time serially and put them all together in alarm command so the alarm is set to a new time which is specified by the user through his smart phone

author
mikesoniat (author)ash1242014-08-12

Sorry for my delayed reaction. I don't check this project very often anymore. I really don't have any experience sending commands from a smart phone, but if you're able to have the Arduino receive the time, it should be very easy to send those values to the alarm function.

author
andrew.l.arth (author)2014-08-08

i really have no idea what im doing but you might be able to help.

Im working on a model train layout, what i want is for a kid to press a button the train goes for 2 min then stops. the child does this 4 more times. after the train stops for the 5th time it activates a cool down clock for 10 min. it would have to work with electricity from an out lit. Any ideas?

author
mikesoniat (author)andrew.l.arth2014-08-12

You could probably use a simple timing circuit and a relay to accomplish this. Just make sure the relay can handle the mains voltage/current.

author
jpontilar (author)2014-01-08

Hi is it possible to include remote access in this design? I mean the switches are there but is there any possibilities that remote control will be added. I am planning to consider the design of yours but my professor want it also to be operated by remote switch.. does the code may be affected? Is it possible?

author
florinc (author)jpontilar2014-03-24

You can easily add a Bluetooth module, as I do for most of my clocks.

Check out this post:

http://timewitharduino.blogspot.ca/2014/02/method-...

author
arcastaneda (author)2014-02-24

Hi! Can you give me the schematic diagram of this project? Especially on connecting the LCD pins to Arduino pins, PIR sensor pins to Arduino pins, also the DS1307 pins going to Arduino, Piezo Buzzer, etc. Appreciate a lot of your support.

author
Larry_Rose (author)2013-12-10

Hello, I am a arduino novice, how can I increase the number of seconds?

I enter printDigits (now.second ()); But no effect.

Thanks to answer.

author
dodge_richard (author)2013-11-28

Hi I tried to upload the sketch but it tells me a bunch of error codes. Such as:
error: 'RTC_DS1307' does not name a type
and
error: 'DateTime' does not name a type
is there a way to fix it?
Sorry I'm new at this stuff

author

lol nevermind had to add RTClib library. it compiled find. any other libraries it needs from else where?

author
mikesoniat (author)dodge_richard2013-11-30

Hi Dodge, that should be all you need. Let me know if you have any other questions.

author
vespa70 (author)2013-08-04

Hi!! I like this clock. I try to learn more about Arduino and programming,
so I like to use your code for learning to make an Alarm clock.
I have an Arduino Uno ,RTC,Buzzer and 16x2 LCD, but no LCD shield.
Is it possible to connect sperate buttons instead??
it´s easier to put in a box later..
And can I use 24h mode as well??
(I live in Sweden, that´s why.)
Best Regards! nice project.

author
mikesoniat (author)vespa702013-08-12

Yes, you can easily use separate buttons connected to the Arduino and just monitor the inputs for a button push. As far as 24h mode, just comment out the code that subtracts 12 from the hours and you should be good to go!

author
gtr_stitch (author)2013-06-20

Very nice! I like the sketch, too. Concise and tidy (my sketches always end up like my room when I was in high school...messy!) I just finished a post very similar to yours. Granted, not as feature rich (I don't have a time/date set feature), but similar. Very cool! I also like the finished product too. My projects always seem to never leave the breadboard :S

author
mikesoniat (author)gtr_stitch2013-06-22

Thanks, stitch! Believe me, I have lots of them then never leave the breadboard too!

author
Lord_Vek (author)2012-10-29

Can you write pin to pin what are the pin connections from RTC breakout board and buzzer to Arduino ? It is not clear from the photos. Thanks

author
mikesoniat (author)Lord_Vek2012-11-03

Sorry for the confusion. Here are the pinouts:

Buzzer (+) connects to A1-S
Buzzer (-) connects to A1-GND

PIR Sensor (VCC) connects to A2-5V
PIR Sensor (GND) connects to A2-GND
PIR Sensor (OUT) connects to A2-S

RTC (5V) connects to A5-5V
RTC (GND) connects to A5-GND
RTC (SDA) connects to A4-S
RTC (SCL) connects to A5-S

I hope this helps!

author
Lord_Vek (author)mikesoniat2012-11-04

Thank you, I'll try to make it without the PIR sensor and I have a makeshift RTC breakout board that's why I needed pin clarification. Your instructable is what I was looking for, I couldn't make an ALARM clock with my RTC, I just manage to make it show the time. Many thanks!!!

author
arnefl (author)2012-07-16

You have a "Set Date/Time in your menu, but where is the function to set Date/Time? This menu option seems to do nothing.

author
mikesoniat (author)arnefl2012-07-30

I finally updated the source code on this project. Sorry for the delay. I've been working on my "Solar Shrub" Instructable, which is entered in the Green Tech Contest. Please check it out and vote for me if you like it!

Anyway, I added the "Set Date/Time" function and a few other things. Plus I fixed a couple of bugs in the process. See the updated "Programming the Clock" page for details.

Here's link to the new source code: https://github.com/mikesoniat/MotionClock

author
arnefl (author)mikesoniat2012-07-30

It's getting better and better.

When I "set time" the month comes up as the default month (now 7), but date comes up with 0 and one have to click to 30 (today). It's easy with the 10xclick, but would be nice if the initial date came up.

In hour the default comes up with 16, which is correct in 24h format, but does not accept it - has to be changed to 4(pm) to accept.

The numbers entered are not limited within clock range, which also would be nice.
But you have improved it a lot!

author
mikesoniat (author)arnefl2012-08-02

Okay arnefl, how about this one? I've updated the code to address the things you mentioned plus another bug I found:

- Fixed default day and hour settings on set date/time
- Added maxCount to getTimerMinutes
- Fixed alarm set PM (alarm wasn't working for PM time settings)

BTW, thanks for all your feedback! It's definitely helped me improve the project.

author
arnefl (author)mikesoniat2012-08-02

Very good! I like this project, so it has been standing here beside one of my computers since version 1 :-) I just tested your new code and it works like a charm. I have not yet put the ir-detector on it, assuming it will work fine when I do.

Congrats' with a very good and cool project :-)

author
mikesoniat (author)arnefl2012-08-22

Looks like I introduced a new bug in that last update. I'm surprised you didn't find it! ;)

The noon hour was being displayed as "0". I only noticed it because I was in my office right after lunch on Saturday and looked at the clock and it said "0:45 PM".

Anyway, I fixed it and posted the updated code as usual:

https://github.com/mikesoniat/MotionClock

author
arnefl (author)mikesoniat2012-08-22

Good catch :-) I've been a bit occupied saying bye to a few people since my time is running out fast now, so if you don't hear from me it's just because I am dead. I really like your project :-)

author
mikesoniat (author)arnefl2012-08-26

Thank you and I'm sorry to hear about your situation, arnefl. I know I'm going to miss you!

About This Instructable

68,766views

107favorites

License:

More by mikesoniat:DIY Patio Umbrella Solar Charging StationHow to make your dream iPhone app a reality (no programming required)Solar Hurricane Lighting (and more)
Add instructable to: