This might seem trivial compared to some of the fancy things I have seen here (I'm still learning!) but it was fun.
I got a spare Atmega328 chip, a spare 4-digit 7-segment display, a spare prototyping board, and a few miscellaneous parts, to make a fairly sophisticated alarm clock:
Here is a simple 7 Segment clock which displays the time, the date and device temperature. The index page of the final reports of the Academies' Summer Research Fellowship Programme 2017.
Full details, including the circuit and sketch are here:
Basically it sounds an alarm at a designated time, every weekday (but not weekends), automatically dims at night, and can be converted to daylight saving time by just sliding a switch. The built-in clock chip with battery means it survives power outages. It has a simple voltage regulator circuit because it needs to be powered by a wall-plug, as the LEDs drain a battery pretty fast.
By the time I finished I had used almost every pin on the processor. The sketch demonstrates:
- Multiplexing an LED display
- Generating sounds by manually pulsing a speaker
- An interrupt for handling the Cancel button
- Talking to the DS1307 chip using I2C
- Handling common-anode or common-cathode LEDs
- Timed events (turning the alarm off after 15 minutes)
Last time I showed You how to control 1 digit 7 segment LED display with Arduino. This time it's not 1, but 4 digits. To connect 1 digit to Arduino we had to use 8 ports, so to connect 4 digits we need to have 4×8=32? Not necessary. Where is a way to use much less ports, it's called multiplexing. Using multiplexing at one time only one digit is active(e.g. for 2ms). All digits is turned on is serial, but because human's eye is inert we have illusion, that all digits are lighting at same time.
As You can see form schematic bellow with multiplexing implemented we required only 4 additional ports compared to 1 digit circuit, total – 12.
7 Segment Led Clock Kit
Because at the same time only one digit will be on All 4 digits segments inputs are connected together. By connecting digits common cathodes to ground we are controlling which digit shall be turned on. Atmega 1280 µCPU port can drain(receive) maximum 40 mA current. If all one digits segments are on, we are having 20×8= 160 mA that is to much, so we can't to connect common cathodes directly to Arduino ports. Therefore I have used BC547 NPN transistors as switches. Transistor is opened, when positive voltage is applied at the base.
Let's see the code.
It's modified version of earlier commented code, so I'm lazy to explain some of the code again.
Indoor outdoor temperature and humidity. Modified code have definition of ports that(with transistors) are controlling digits.
Airtable adobe xd. #define GND1 52
Quartz digital clock.
#define GND2 53
#define GND3 50
#define GND4 51
And they are outputs
pinMode(GND1, OUTPUT);
pinMode(GND2, OUTPUT);
pinMode(GND3, OUTPUT);
pinMode(GND4, OUTPUT);
There new function to display all 4 digits. You can see it have 4 parts, to display 4 digits.
My new target is to make digital clock of these displays using timer for accuracy.
Arduino Alarm Clock 7 Segment
I got a spare Atmega328 chip, a spare 4-digit 7-segment display, a spare prototyping board, and a few miscellaneous parts, to make a fairly sophisticated alarm clock:
Here is a simple 7 Segment clock which displays the time, the date and device temperature. The index page of the final reports of the Academies' Summer Research Fellowship Programme 2017.
Full details, including the circuit and sketch are here:
Basically it sounds an alarm at a designated time, every weekday (but not weekends), automatically dims at night, and can be converted to daylight saving time by just sliding a switch. The built-in clock chip with battery means it survives power outages. It has a simple voltage regulator circuit because it needs to be powered by a wall-plug, as the LEDs drain a battery pretty fast.
By the time I finished I had used almost every pin on the processor. The sketch demonstrates:
- Multiplexing an LED display
- Generating sounds by manually pulsing a speaker
- An interrupt for handling the Cancel button
- Talking to the DS1307 chip using I2C
- Handling common-anode or common-cathode LEDs
- Timed events (turning the alarm off after 15 minutes)
Last time I showed You how to control 1 digit 7 segment LED display with Arduino. This time it's not 1, but 4 digits. To connect 1 digit to Arduino we had to use 8 ports, so to connect 4 digits we need to have 4×8=32? Not necessary. Where is a way to use much less ports, it's called multiplexing. Using multiplexing at one time only one digit is active(e.g. for 2ms). All digits is turned on is serial, but because human's eye is inert we have illusion, that all digits are lighting at same time.
As You can see form schematic bellow with multiplexing implemented we required only 4 additional ports compared to 1 digit circuit, total – 12.
7 Segment Led Clock Kit
Because at the same time only one digit will be on All 4 digits segments inputs are connected together. By connecting digits common cathodes to ground we are controlling which digit shall be turned on. Atmega 1280 µCPU port can drain(receive) maximum 40 mA current. If all one digits segments are on, we are having 20×8= 160 mA that is to much, so we can't to connect common cathodes directly to Arduino ports. Therefore I have used BC547 NPN transistors as switches. Transistor is opened, when positive voltage is applied at the base.
Let's see the code.
It's modified version of earlier commented code, so I'm lazy to explain some of the code again.
Indoor outdoor temperature and humidity. Modified code have definition of ports that(with transistors) are controlling digits.
Airtable adobe xd. #define GND1 52
Quartz digital clock.
#define GND2 53
#define GND3 50
#define GND4 51
And they are outputs
pinMode(GND1, OUTPUT);
pinMode(GND2, OUTPUT);
pinMode(GND3, OUTPUT);
pinMode(GND4, OUTPUT);
There new function to display all 4 digits. You can see it have 4 parts, to display 4 digits.
My new target is to make digital clock of these displays using timer for accuracy.
Arduino Alarm Clock 7 Segment
And full code goes here: