Getting Started with Arduino – Chapter Ten
This is part of a series titled “Getting Started with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the index is here.
This week we will minimise an Arduino Uno board, use time to control, and then find some synergy between the two.
As time goes by, you will want to build projects to use away from the bench, or that are permanent. Although doing so is infinitely fun, it can become expensive if you keep buying Arduino boards for each project or proof-of-concept prototype, or even finished products. However, as always, the Arduino team have solved this problem for us as well. The actual microcontroller integrated circuit (e.g. ATmega328P-PU) can operate with a lot less circuitry than that is contained on your Uno or compatible board. In fact, you can have a functioning Arduino system with three components and a 5V power supply.
How?
To start, please download the Uno schematic from here. Upon glancing at it for the first time, there seems to be a lot of things required. However if you just want to use the digital and analogue pins, you can cut that schematic down to a lot less, however you need to make a couple of changes to how you upload the sketch. Here is what you can get away with:
X1 is the 16 MHz resonator. Using only the main circuit on the left, to upload your sketch you need to place the ATmega chip in your Arduino board, upload the sketch, then very carefully remove the chip and place it into your circuit, breadboard, etc. Please make sure to observe anti-static precautions, and always use a chip puller (below).
Furthermore, if you only have one chip, it would be very wise to have a second or third as a backup. A programmed ATmega with the Arduino bootloader can be had for less than US$6. Below is a shot of my barebones Arduino system at work. It is setup to run this basic example.
The blue and yellow wires run off to a 5 volt power supply. And here is it working:
To recreate this at home, you will need:
- One ATmega328P-PU microcontroller with Arduino bootrom
- solderless breadboard
- 10k ohm resistor
- 16 MHz resonator
- (optional – for USB cable) 6-pin header pin
- (optional – for USB cable) 0.1 uF ceramic capacitor
- (optional – for USB cable) FTDI cable (the 5 volt version!)
A note about the resonator. Your Arduino board will most likely have a metal crystal, however a resonator is a little cheaper and easier to use, as it has the capacitors in built. If you look at the Arduino schematic, they use a crystal and two 22 picofarad capacitors. So if you use the resonator, pins 1 and 3 go to chip pins 9 and 10, and resonator pin 2 goes to GND. Here is the data sheet for the resonator. They should be easily available, for example from here. The USB cable option will make life a lot easier. The cable is called an FTDI cable, and contains the electronics within to interface between the USB port on your computer and the TX/RX pins on the microcontroller. The wiring details are in the schematic above.
The cable also supplies power whilst programming, or leaving the cable plugged in. Here is my board with the extra wiring connected:
So if you have this kind of setup, you can just plug the cable into the computer USB port and upload sketches as normal. However there are some modifications that may need to be done with your computer’s operating system to make it work. If you are running Linux or MacOS, please visit here; if you are running windows of some sort, go to device manager, right click the USB serial port you are using, select properties, port-settings tab, advanced, and turn on set RTS on Close.
When purchasing an FTDI cable – make sure you get the 5 volt version!
So now you can integrate the Arduino chip into your prototypes much easier and cheaper. However, if you are going to use SPI or I2C devices, more circuitry will be required. We will examine creating these interfaces in more detail later. A good compromise in this situation is a miniature Arduino-compatible board such as the Freetronics LeoStick.
If you are interested in a project using such a barebones setup, please have a look at blinky the clock.
Next on the agenda is a small project to consolidate some previous learning. At the end of chapter nine, we made a (relatively) user friendly clock with an alarm. And in chapter three, we controlled a relay with our arduino. So now we have the ability to create our own on/off timer of which possible uses could be limitless.
In doing so, we can start by modifying the sketch from exercise 9.3. It has the ability to set an alarm time (let’s call it a start time from now on), so we can add the ability to set an end time – it just requires some more variable to store the end time data, and another menu function to set these. Finally, another function is required to check if it is time to turn off (basically identical to the checkalarm() function.
The hardware side of things for the example will be quite simple as well, below is my schematic, and the basic board:
I am using 12v relays as currently that is all I have in stock. The 12V power supply is just an LM7812 regulator from a 20V DC plugpack. For demonstration purposes any low-voltage relay would be fine. A 5V relay such as this would be perfect as you could run it from the Arduino’s 5V rail.
Note: From here on you understand that one can use an Arduino to switch a very high current and/or voltage with some relays. Please exercise care and consult a qualified, licensed person if you are working with mains voltage (100~250V AC… the stuff that comes out of power points/outlets). They can KILL you!
So for this example, I have modified the sketch as described earlier to accept a start time, end time, and display relevant data on the screen. It will switch on and off the relay, which controls a light globe drawing 100mA – 5 times the current an Arduino digital out pin can deliver. It only operates using 24-hour time, to save user confusion. You could control anything as long as you do not exceed the current and voltage maximums for your particular relay.
So here it is in action. The time has already been set previously, so you can watch the setting of the on/off time, and watch it in action. You can skip ahead from 01:03s to 01:48s to save time.
and here is the sketch for your perusal.
As as example the user interface wasn’t that flash, but naturally it can be worked on to be more intuitive. So now it is your chance to do so, with…
Exercise 10.1
Create a timing system for a hypothetical lighting system that controls two independent circuits. Each timer can turn on or off at a specified time, either daily, only on weekdays, only on a certain day of the week (e.g. only Fridays) or only on weekends. The menu system should be easy and quick to use.
For the purpose of the exercise, you can switch on or off an LED to represent each lighting circuit – you already know how to use the relays.
You will need:
- Your standard Arduino setup (computer, cable, Uno or compatible)
- Two usual LEDs of your choice
- 2 x 560 ohm 0.25 W resistors. For use as current limiters between the LEDs and ground
- 1 x 10k resistor
- one push button
- a breadboard and some connecting wire
- some water
- DS1307 timer IC circuit components (see this schematic from chapter seven) or a pre-built module
- one 10k linear potentiometer
- LCD module as per chapter two
Here are some videos of my interpretation. To save time I have not connected the LEDs, however timer running status is indicated on the second line of the display – an “!” is shown when a circuit has been activated. The first video shows setting the real time, timer data and displaying the results:
and the sketch.
How did you go? With a little more hardware this exercise could become a real product – you could control sprinkler systems instead of lights, thermostats, anything is really possible. Having a larger LCD screen would help with the user interface, perhaps a 20 character by 4 line unit. As long as such a screen has the standard HD44780 interface, you would be fine.
Now on to Chapter Eleven…
Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.











All very interesting. Thanks for your stimulating and informative posts.
Correct me if I’m wrong, but I understand that the ATmega chips already have a resonator (crystal?) built in – albeit running at 8MHz.
So it would be possible to remove that from the scheme of things too – just running at half speed.
Hello Marcel, thank you for your comment.
Yes, the ATmega328 does have an inbuilt oscillator (8Mhz?) that is not so accurate. However the Arduino libraries, etc., assume the chip is running at 16 MHz so the external resonator is necessary.
Cheers
John
Thanks John, I see… only really practical for Arduino Masters.
I see here… http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1163418637 …that it’s possible to run down to 1MHz for the purpose of reducing power consumption.
Interesting but technical.
Thanks again for your most excellent articles. They’re very informative and well presented.
You’re welcome Marcel, thank you for reading.
Altering the speed of the Arduino is also outside the scope of my knowledge as well (maybe later!).
Out of interest, people have also overclocked their Arduino! – Have a look here: http://www.freetronics.com/blogs/news/1663142-twentyten-overclocked-to-22mhz
Cheers,
John
Would the bare-bones arduino work with the wireless data link in chapter 11? Either the transmitter or reciever would be bare bones, and the other one would be an arduino.
Absolutely.
John
Hi John, I’ve attempted to program a standalone ATmega328 on a breadboard using the RX/TX lines from an Arduino Duemilanove (as per http://arduino.cc/en/Tutorial/ArduinoToBreadboard). The ATmega used was the original from the Arduino which I had pulled out, and is running with its internal 8MHz crystal.
I have changed the software files to recognise the change in clock speed but I have still been unsuccessful in uploading code. Do you think I would have to bootload it again due to the change of frequency (down from 16MHz on the Arduino to 8MHz on standalone)? Or is once enough and the problem lies elsewhere?
Perhaps off-topic but any feedback would be much appreciated.
Hello
If you pulled the ATmega328 from an Arduino Duemilanove/Uno or compatible nothing on the software front needs changing – it runs at 16MHz on a breadboard as well. Just wire it up as described in my chapter 10, and off you go. The best thing to do would be reload the bootloader on the ATmega328 and start again.
cheers
john
Hi,
Not a comment rather a call for help!
I duplicated the schematic but for replacing the resonator by a 16 MHz crystal and two 22pf capacitors (going to ground) I got the idea by looking at the schematic ARDUINO 2009. The Arduino rev 3 add a 1M resistor between the leads of the crystal, I did not try that yet…
I tried the part with the blinking LED and I cannot upload the sketch. I get:
Binary sketch size: 1050 bytes (of a 14336 byte maximum)
avrdude: stk500_getsync(): not in sync: resp=0×00
avrdude: stk500_disable(): protocol error, expect=0×14, resp=0×51
I then simplified the sketch to only address one LED:
void setup() {
pinMode(3, OUTPUT); // initialise the digital pin 3 as an output
}
void loop()
{
for (int wow = 1; wow <= 5; wow++) {
digitalWrite(3, HIGH); // turn on digital pin 3
delay(1000); // wait a moment
digitalWrite(3, LOW); // turn off digital pin 3
delay(1000);
// wait a moment
}
The ATmega328 is supposed to be an ATMega 328P-PU with UNO booloader
at least that's what is written on the package…
Thanks for any hints
Lionel
Do you have your board type set to Duemilaove?
Possibly there is am issue with the IC or the wiring. Here is my version using the crystal – http://db.tt/VEBDTOvn The six pins at the bottom of the schematic are for the FTDI cable, GND on the left.
Do you have simple schema using ATmega328 with I2C bus? You said here, there is need more circuitry. How much complicated is that?
The I2C bus is using pins 27 (data) and 28 (clock). For more information on Arduino and I2C bus please see this tutorial – http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/
hi
barebones blinking leds sketch does not download as the right one
seems something to do with the clock sketch
garry
Fixed. Here’s the link https://sites.google.com/site/tronixstuff/home/arduino-tutorial-series-files/example10p1.pde
Thanks
Hello John, congrats on a great series of tutorials. Have you done one (or know of a good one elsewhere) on scrolling text using two 8 x 8 LED matrices controlled by shift registers. Thanks from a fellow Aussie Pedro.
Thank you very much.
I haven’t seen one however it wouldn’t be too difficult.
However when stuff like this is $13:
http://www.dealextreme.com/p/jy-mcu-3208-lattice-clock-ht1632c-driver-with-mcu-support-secondary-development-104306
It’s easier to just buy it and move on.
Thanks John I’ll look into it,
Pedro