CS250 Lab 5
Implementing a Digital Alarm Clock
Goal
In this lab you will use the Arduino Board and the 7-segment display
to implement a digital alarm clock with clock and alarm set, melody
selection etc.
Step 1. Using the 7-segment display with the Arduino
Read the "Arduino
Inventor's Kit" documentation circuit 5 (page 16). You will
use a similar circuit to turn on the segments of the 7-segment
display but instead of using LEDs you will use the segments of the
display. Remember to use the limiting resistors from lab3. Also
remember that the 7-segment display is "common anode", so it will
need a 0 to turn on one segment instead of a 1. You will use
the 74HC595 Shift Register to provide more outputs to the Arduino.
Intially you can only wire DIG1 by connecting pin 1 to +5V.
Write a function display7seg(int num); that will display the
corresponding number 0 to 9 in the 7-segment display and test it.
Step 2. Displaying Digits in Multiple Positions
Now connect the digital outputs 5, 6, 7, and 8 to the terminals
DIG1, DIG2, DIG3, DIG4 of the 7-segment display. These outputs will
be able to select a digit at a time. For example, if you set DIG3 to
1 and DIG1, DIG2, DIG4 to 0 then only digit 3 will display the umber
when calling display7seg(int num);.
To display all the digits you will have to select and display one
digit at a tiime. Look at the example code:
void setup() {
// Setup pins 5, 6, 7, 8 as outputs.
....
}
void loop() {
while(1) {
// Display digit 1
digitalWrite(5,LOW); digitalWrite(6,LOW);
digitalWrite(7,LOW);digitalWrite(8,LOW); // Turnoff display
display7seg(1); // Display 1 at ditgit 1
digitalWrite(5,HIGH); digitalWrite(6,LOW);
digitalWrite(7,LOW);digitalWrite(8,LOW); // Turnon digit 1
// Display digit 2
digitalWrite(5,LOW); digitalWrite(6,LOW);
digitalWrite(7,LOW);digitalWrite(8,LOW); // Turnoff display
display7seg(2); // Display 2 at ditgit 2
digitalWrite(5,LOW); digitalWrite(6,HIGH);
digitalWrite(7,LOW);digitalWrite(8,LOW); // Turnon digit 1
// Display digit 3
digitalWrite(5,LOW); digitalWrite(6,LOW);
digitalWrite(7,LOW);digitalWrite(8,LOW); // Turnoff display
display7seg(3); // Display 3 at ditgit 3
digitalWrite(5,LOW); digitalWrite(6,LOW);
digitalWrite(7,HIGH);digitalWrite(8,LOW); // Turnon digit 1
// Display digit 4
digitalWrite(5,LOW); digitalWrite(6,LOW);
digitalWrite(7,LOW);digitalWrite(8,LOW); // Turnoff display
display7seg(4); // Display 4 at ditgit 4
digitalWrite(5,LOW); digitalWrite(6,LOW);
digitalWrite(7,LOW);digitalWrite(8,HIGH); // Turnon digit 1
}
}
Step 3. Implementing the clock.
Arduino has a Time
library that you can use. You can try running the sketch that
is given in the example. Display the hours and minutes in this
library in your 7-segment display by reading in the main loop the
minutes and seconds and updating the digits.
Step 4. Set Hours and Minutes in your clock.
Add 4 buttons to your clock and implement an interface to set the
hours and minutes in your clock as well as set the alarm clock. Use
the code in the push button example circuit you did in last lab.
Step 5. Add Alarm.
See how to generate music with the Arduino in circuit 6 of the
"Arduino Inventor's kit". You will connect the speaker in series
with the 100uf capacitor and ground. Make sure that the negative
side of the capacitor is connected to the ground.
To submit
For next PSO bring steps 2, 3 and 4. For the PSO in two weeks bring
your finished alarm clock.
Your clock should:
- Show the time with hours and minutes.
- You should be able to set hours and minutes with the push
buttons.
- You should be able to set the alarm with the push buttons
- The alarm should ring when it is time.
- Also you may add extra features like sound selection, use the
potentiometer for data input etc.