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

75K11240

Intro: 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

40 Comments

Sir,

I got some problem that date and time not show properly and cannot setup .kindly please advise and see my attached file.

Regards,

Soe

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

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

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.

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.

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

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

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.

Thanks, and good luck with the build!

error: 'RTC_DS1307' does not name a type

what should i do?

sorry i'm newbie

Sounds like you need to load the RTC library.

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

alisoneletricista@hotmail.com

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

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.

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?

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.

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?
More Comments