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.

In this tutorial we’ll 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:

example10p1schematicsmall

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):

pullersmall

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:

worksbarebonessmall

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:

worksftdismall

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.

ic-border

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:

example10p2

example10p2boardsmall

 

 

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 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

LEDborder

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

The following two tabs change content below.

John Boxall

Founder, owner and managing editor of tronixstuff.com.

17 Responses to “Getting Started with Arduino – Chapter Ten”

  1. Marcel says:

    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.

  2. James says:

    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.

  3. John says:

    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.

    • John Boxall says:

      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

  4. John Boxall says:

    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.

  5. Fairul Izham says:

    Do you have simple schema using ATmega328 with I2C bus? You said here, there is need more circuitry. How much complicated is that?

  6. Garry says:

    hi
    barebones blinking leds sketch does not download as the right one
    seems something to do with the clock sketch
    garry

  7. Peter Newman says:

    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.

Trackbacks/Pingbacks


Leave a Reply

Receive notifications of new posts by email.

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

Buy and support Silicon Chip - Australia's only Electronics Magazine.

Use of our content…

%d bloggers like this: