To increase access to education I made a simple, easy to flollow arduino project for newcomers that will allow them to learn more about programming. Using the arduino microcontroller's internal timer and Infared sensors, this remote control alarm clock, is fully functioning from across the room.
Final Project with Enclosure
There are two parts to this project, the elctronics/arduino part and the wooden enclosure. The wooden enclosure is designed to be made using a laser printer, in this case it is not accessible to many people, but the instructions and files are there.
This tutorial will walk you through some of the design obstacles I encountered while making this in order to help you understand how to program for arduino better.
The first issue encountered is how do we count time. Normally a RTC component will do the job, but I wanted to keep the build price down, so we will use the millis() and micros() functions built into the arduino. These functions will give you the milliseconds and microseconds that have passed since the arduino has started running. So we take that value and store it in a variable of great size, an unsigned long (a long stores 16 bits of binary data, and since this one is unsigned it does not use the Most Significant Bit [MSB] to store whether or not the value is negative.) to measure the change between loops of the arduino. This function needs to be called every so often to maintain the most accuracy. From there if statements keep track of what times to increment and when. Then we store the currentTime variable in a variable called previousTime to check for change later with. Figuring out how to code things without their components is a great way to save money, but is not always possible or worth it.
The code described above.
This is the first time you'll notice the use of the Serial Console. This will enable us to see whether or not the clock is running behind the scenes as our display does not show seconds. When we do display we will be using the library for the display's built in function to display time. It is important that we import this library properly and declare the object for the display with the right name for the version that contains the printTime() function. Using libraries is a great way to save time and energy while coding and your arduino comes with many of them already.
The code described above.
When using an IR remote you have to figure out your remote's values. The included IR Test program will output your IR remotes valid cases when you press on the buttons. Ignore the 0xFFFFFFFF case, that is most likley an error. Try each button multiple times and record what buttons mean which values.
A string is used when taking in the time to allow for easy manipulation of its contents.
The last issue I faced was when adding the alarm. Passive Buzzers and IR Sensors have the same timer on most arduinos and cannot be run together. So manipulation of the ir library was needed. Go to IRRemoteInt.h and edit the timer to be 1.IFYOUAREJUSTSKIMMINGTHROUGHTOGETTOTHECODETHISISIMPORTANT.
My Timers (NOTE: THE LIBRARY PROVIDED IS UNMODIFIED)
The enclosure will be added at a later date.