Hey all instructable goers! This is my first project. Yes, I know those words usually get the stereotype "This isn't going to be a good project" attitude, but I have been waiting a long time for a project that is worthy of possibly breaking the first project attitude- at least for a while anyway.
This project would be about medium level for a novice, but *hopefully* still provide somewhat of a challenge for more experienced users, as they get into the code and work on improving this. "This" that I have mentioned multiple times, is an Arduino clock, based off of a 4 digit display. I have named this project the "TimeDuino". Its a simple 4 digit clock, driven with Arduino and transistors. Well, enough boring you with the introduction, lets get to the project!
Well, a few more things actually :)
1. In the spirit of instructibles and the growing DIY world, feel free to use this project, hack it, open it, tear the code apart, and in any way you want destroy/hack/DIY it to your hearts content. I want everyone to be able to access the project, and not have to worry about proper permissions. I really like the quote from MAKE: Magazine, which states "If you cant open it, you dont own it". So OWN this project! Open it, hack it, tear it apart and make it your own. Go beyond the step by step instructions and really customize it! I really enjoy electronics, and i want to share that enjoyment with others.
2. Feedback is appreciated. Tell what you do or do not like! What needs upgraded and what needs reverted to a previous version? These things (though I might not be able to complete all of them) really help and make it easier to create something that is liked by the community. Have a question? Ask it in the comments, or PM me. I'd be happy to help as much as I can.
Many thanks, and on to the project! :)
Step 1: Parts Needed:
1x Arduino. I used an UNO (but any version should work). Make sure it has a 16MHZ timer chip on it, otherwise timer functions will be off (until I update with an RTC [Real Time Clock]. To tell if it has the timer, it should have a silver oblong piece on the PCB, with 16.000 printed on it.
1x Power supply for Arduino (not shown)
1x Breadboard. A half size board will work, but a full sized one is easier to work with (I'm using 2 half size boards together.
Breadboard Jumpers - quite a few are needed.
7x 2N3904 NPN type transistors (maybe 8 for AM/PM support, working on that)
8x resistors. Try for a value greater than 200 ohms and less than 1k. I'm using 220 ohms. (10x if I get AM/PM support)
7x 1k ohm resistors. These will keep your Arduino from overheating (8x if i get AM/PM)
1x 4 digit 7 segment display. I used a common anode display (but a common cathode would work with editing the code). Make sure it has a colon! One used in project- Sparkfun COM-09481
also available in red, green, and yellow (blue costs 50c more than the other colors. I got 2 just in case [but these are almost unbreakable if you remember to use resistors])
*Note that if you want to just build it w/out testing, you don't need the breadboard and jumpers. I wanted to test mine first but I'm gonna build a finished up prototype when I get some other parts.
Step 2: Laying out the transistors
Possibly the most crucial element of this project is laying out the transistors correctly. The transistors allow a connection to ground to be made using positive voltage. Start spreading the legs of the transistors a little bit, making sure they fit into their respective holes (as shown in pics). Make sure there is at l east one empty row between the transistors. Double check to make sure the FLAT side is facing you, otherwise it will not work. Do this for all 7 transistors. Lay out an extra one if you will be doing AM/PM support
Step 3: Start wiring up all of the transistors
Ah, the first real wiring job of this project. Use jumpers to connect the collectors of the transistors (in picture below) to the ground rail on your breadboard. Connect a jumper from the ground rail on your breadboard to a ground pin on the Arduino board. As you can probably see, paint is not my strong suit :)
***WARNING!! The following section may contain science relating to electrical components and how to use them. Continue at your own risk. Thank you.***
Basic transistor lesson. To use an NPN transistor, placing current on the base pin lets proportional current through the collector pin to the emitter pin. Very basic, as transistors have different minimum currents, maximum ratings, and different current capabilities, along with much else. Luckily, a 2N3904 is very kind to us, and perfect for small scale, high frequency switching with a low power source, such as an Arduino. Yay!
Step 4: Add resistors to your transistors. Say that 5 times fast!
Now you must add resistors to the emitter of the transistors, else you might accidentally fry your display when you hook it up. We wouldn't want that, would we?
Connecting is simple, go from the emitter, jump over the center of the board, and connect it to the other side.
Depending on your resistors, the display might be dimmer when you hook it up, the higher value your resistors are.
Step 5: Even more resistors
By adding these resistors, it will keep the Arduino from using to much current and then overheating. You need to connect a 1k resistor from the base (middle pin) of each transistor to the empty row to the left of your transistors.
Step 6: Now for the harder part (connecting the display)
Connecting the transistor output to the display is harder. Make sure you have your display's datasheet ready, because you'll need to look at the pinouts there. For my display, I connected the transistors in order from segments A to G, using the farthest left transistor for A, and the farthest right as G (and an extra one for my AM/PM, ill call that one segment H from now on). It helps keep things a little more organized. Which transistor goes to which pin depends on your display and its pinout.
Step 7: Connect the display to Arduino
For our first test, you will need to connect the Arduino output pins to the specific transistors.
For segment A: connect pin 12 (on Arduino) to the first (leftmost) 1k resistor (connected to transistor base [middle pin])
For segment B: connect pin 11 (on Arduino) to the second leftmost 1k
For segment C: connect pin 10 (on Arduino) to the third 1k
For segment D: connect pin 9 (on Arduino) to the fourth 1k
For segment E: connect pin 8 (on Arduino) to the fifth 1k
For segment F: connect pin 7 (on Arduino) to the sixth 1k
For segment G: connect pin 6 (on Arduino) to the seventh (rightmost) 1k
For segment H: connect pin A3 (on Arduino) to the 1k on your H segment transistor. This is not actually used in the test.
Step 8: Almost there!
Connect the digit power pins (1, 2, 6, 8 on my display respectively) to pins 5, 4, 3, and 2 on the Arduino. Goes as follows:
Digit 1: pin 5 on Arduino
Digit 2: pin 4 on Arduino
Digit 3: pin 3 on Arduino
Digit 4: pin 2 on Arduino
Colon: pin 3 on Arduino (not used in test)
PM dot (apostrophe) connected to pin 2 on Arduino, and its respective ground pin to ground)
Step 9: Test the display!
The time has finally come! Time to test your display and it's transistory goodness!
Download and run the code posted below. Note that if it downloads an a .tmp file, it's ok, just rename it as a .pde file and run it in Arduino on your computer.
You should see a variety of patterns and tests go on the digits. If anything seems out of place, check your wiring. Here's a video showing you what an ideal test should look like. UPDATE: I got video embed to work :) My thanks to user Burf for guiding me to the right page.
If all goes well, skip the next step and continue on. If it doesn't seem to work, go to the next step.
Step 10: Troubleshooting :(
Troubleshooting. Even a mere mention of the word can strike fear into the hearts of people everywhere. If your display doesn't work, there are a few things to check.
Make sure your transistors are oriented correctly, the flat side should face you. Make sure the resistors are connected to the leftmost pins of the transistors, and that the jumpers from the resistors to the display are hooked to the corresponding pins. Lastly, make sure you connected the displays jumpers to the correct Arduino pins. I once had a dim, flickering segment, it turned out only to be a loose resistor. If nothing works and everything is connected right, check your display, maybe some segments are burned out. Hope this helps!
Step 11: Finally! The clock part!
Well if all the test went ok, it's time to make your clock a clock. We have to re-arrange the pins from the display and the pins on the Arduino (so I can have some extra pins for possible PWM control later)
*Note. Its best to blank your Arduino, it makes it easier to upload the next sketch (sometimes it freezes). To do this, go to File>Examples>Basics>BareMinimum (or equivalent) and upload it to your Arduino.
So here goes.
Seg A to pin 12 on Arduino
Seg B to pin 8 on Arduino
Seg C to pin 7 on Arduino
Seg D to pin 5 on Arduino
Seg E to pin 4 on Arduino
Seg F to pin A0 on Arduino
Seg G to pin A1 on Arduino
Seg H where it is
Digit power pins:
Digit 1 to pin 11 on Arduino
Digit 2 to pin 10 on Arduino
Digit 3 to pin 9 on Arduino
Digit 4 to pin 6 on Arduino
Colon where it is. Make sure to connect your colon ground pin to ground! Mine had a different pin than the rest of the digits outputs.
Step 12: Upload the clock code
Update: Version 1.4! This update includes AM/PM support, as well as a much simpler code.
To use the code, download the file included below. It should download as a .tmp file, just rename it as a .zip file. Unzip the file into your arduino sketch folder. In arduino, go to Sketchbook>TimeDuino_v1.4 and open it. It should have a program with 3 tabs in it. Go to the third tab to set your variables. Make sure to read the comments!
When uploaded, it should display 9:42, with the PM dot on.
Step 13: Possible updates/improvements
I have some updates for this clock that should be posted if I can get them to work...
v1.1 - AM/PM time using a decimal and apostrophe on display
v1.2 - Adding buttons to set time
v1.3 - Blinky colon support, will blink the colon every second (like some clocks)
UPDATE! Blinky colon support (read through code to see how)
v1.4 - 24 hour clock configuration
UPDATE! 24 hour clock supported. Read code for details
v1.6 - Possible seconds addition, using another 2 digits, making it a 6 digit display
v1.8 - RTC support (I have a DS1307 clock chip on order, as well as the needed extra components to get it to work, but it will take me a while to get it and make it work) This will (hopefully) eliminate the timing problems (the display goes a bit fast, testing to try to lessen the effect)
another few updates would maybe include common cathode display support, thus eliminating the need for a specific display, and adding an alarm and snooze.
Step 14: Thanks to: (and final note)I just wanted to thank the people here for posting the code which I based my clock on. Also to instructables for letting everybody post their projects here :)
Thanks to user Burf for helping me get to the right page to figure out my video embed problem.
Also many thanks to users maewert, stevastrouk, and rickharris for helping so much with the overheat problem!
If you wish to use your Arduino for another project, it helps to remove all the wires from it, and then upload your desired sketch. If you don't remove all the wires, it sometimes freezes up and won't let you load anything.