t r o n i x s t u f f

fun and learning with electronics

Moving Forward with Arduino – Chapter 15 – RFID Introduction

Learn how to use RFID readers with your Arduino. In this instalment we use an RDM630 or RDM6300 RFID reader. If you have an Innovations ID-12 or ID-20 RFID reader, we have a different tutorial.

This is part of a series originally titled “Getting Started with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.

Updated 21/02/2013

RFID – radio frequency identification. Some of us have already used these things, and they have become part of everyday life. For example, with electronic vehicle tolling, door access control, public transport fare systems and so on. It sounds complex – but isn’t.

To explain RFID for the layperson, we can use a key and lock analogy. Instead of the key having a unique pattern, RFID keys hold a series of unique numbers which are read by the lock. It is up to our software (sketch) to determine what happens when the number is read by the lock.  The key is the tag, card or other small device we carry around or have in our vehicles. We will be using a passive key, which is an integrated circuit and a small aerial. This uses power from a magnetic field associated with the lock. Here are some key or tag examples:

In this tutorial we’ll be using 125 kHz tags – for example. To continue with the analogy our lock is a small circuit board and a loop aerial. This has the capability to read the data on the IC of our key, and some locks can even write data to keys. Here is our reader (lock) example:

As you can see from the 5mm graph paper, the circuitry is quite small, and the loop is somewhat fragile. For installation and use, it would be wise to mount the loop aerial inside something strong and protective.

Our use for the RFID equipment is to have our sketch make a decision based on the unique tag number. For example, it could be used as a switch to turn on and off something, perhaps an alarm system or a computer. It could control an electric door strike (lock), or activate a series of lights to one’s personal preference. The possibilities are only limited by your imagination. I hope that with your existing knowledge you can implement this RFID equipment into your next prototype or product.

Example 15.1

First of all, let’s do a basic test – what happens when we read a tag?  To do this we need to connect our reader to the Arduino or compatible board, and see what comes out when we read a card. The connections are quite simple:

Note that all the GND pins are connected together.

Upload the following sketch (download):

// Example 15.1
int data1 = 0;
void setup()
{
 Serial.begin(9600);
}
void loop() 
{
 if (Serial.available() > 0) {
 // read the incoming number on serial RX
 data1 = Serial.read();
 // display incoming number 
 Serial.println(data1, DEC);
 }
}

You may need to remove the wire from the RFID reader to Arduino before uploading the sketch, then replacing it after the upload. From the reader data sheet.pdf (our version is the TTL model), the reader sends out serial data from the TX pin at 9600 bps. We will read that data using the serial input (digital pin zero on the board) and display it on the serial monitor box to see what it looks like. The LED activates (rather dimly) when reading is taking place. Here is the sketch to use.

Once the sketch has been uploaded, open your serial monitor box, and wave a tag over the antenna. You should have a reading similar to the video below, however your tag number will be different.

Excellent – simple numbers that we can work with. For example, one of my tags returns: 2,51,69,48,48,49,65,51,53,70,50,69,51,3 and another returns 2,51,67,48,48,67,69,49,48,68,53,51,55,3. Note that both start with 2 and end with 3, so the unique tag details are the 12 integers between the 2 and 3. One could read the data as characters or hexadecimal numbers by altering the data type in the sketch from int to byte, but for simplicity I am working in integers.

Now all we need to do is fashion sketches to recognise the tag number(s) we want to use, and perform an action based on which tag number is used (or do something when a tag is read, but not the tag you want).

Example 15.2

In the following example, (download) the sketch reads the 14 integers returned from the card reader when a tag is swiped. These integers are placed into a fourteen element array, which is then compared against arrays holding the numbers my “allowed” tags. If an allowed tag is read, the green LED comes on, if a disallowed tag is read, the red LED comes on. Of course you could have the digital outputs controlling other things using a switching transistor or a relay. Below is the schematic:

And a short video in action:

Excellent – now we are getting close to something useful. The example above could make a simple door control, or an over-engineered cookie jar.

Now for some more practical uses of RFID and Arduino. In the past we have worked with real time in many chapters, and also have stored data using a microSD card shield

Example 15.3

We will build on our previous example by adding time and date logging for all accesses to the system, successful or not. This could be used again for door access, payroll calculations as a modern-day punch-clock, or even a simple logging device to see what time the children arrive home when you aren’t around to check. So we will need a microSD shield, and some sort of DS1307 breakout board or shield.

When using more than one shield together, be mindful of the pins you will need to use. For example, my DS1307 shield uses analogue 4 and 5 (for I2C interface), and the microSD shield uses digital 10 to 13.

The sketch for this example is quite simple – the good thing about programming for Arduino is that just like the hardware shields, sketch procedures and functions can be very modular and reused quite easily. If you are unsure about the microSD shield, please read my instructional review. Most of the code can be copied from that microSD shield article’s demonstration sketch, which I have done for this example. The sketch writes the time, date, tag number, and read status (accepted/rejected).

However there is one caveat when using the microSD shield – the file needs to be closed before the card can be removed for examination. In practical use, our RFID system would be usually on most of the time, so a method will needed to activate the card write function. This has been implemented with a function bossMode() that is called when a certain tag is read – one may call this the supervisor’s card. Once this particular tag is read, the file is annotated as closed, reading stops, and the LEDs blink alternately when it is safe to remove the card. A simple reset after the card is reinserted will start the reading again.

Here is the sketch. The schematic is the same as Example 15.2, with a few simple additions – the use of the microSD card shield, and the DS1307 real time clock shield. If you are using a DS1307 breakout board wired in separately, please use the following schematic as a guide:

Now here is a short video clip, with the addition of the ‘boss mode’ shutdown sequence:

And finally, here is an example of the text file that was produced from a recent test run:

As you can see, it is easy to reproduce expensive time-keeping systems with our own equipment and some time. We have some RFID projects in … the project section.

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.

August 18, 2010 Posted by | arduino, ELB149C5M, lesson, microcontrollers, RDM630, RDM6300, rfid, RFR101A1M, sensor, tronixstuff, tutorial | , , , , , , , , , , , , , , , , , , , , | 1 Comment

Review – Macetech Shiftbrite RGB LED module

Hello readers

Today we are going to examine the Macetech Shiftbrite modules. These are high-powered RGB LEDs that are mounted on a small PCB with a controller IC that you can control easily with an AVR or Arduino system, with a brightness of 8800 mcd per colour, and a viewing angle of 140 degrees. Ouch! In this review we will be using the Arduino system, however there is AVR instructions and a demonstration available here. First of all, here is one example:

You can order Shiftbrites with and without header pins. The IC on the bottom of the unit is an Allegro A6281 three-channel constant current LED driver with programmable pulse-width modulation control. For interest, here is the data sheet: Allegro 6281.pdf In other words, it takes care of which LED segment(s)to illuminate, their brightness, and for how long. It sounds like a lot but is easy to  understand.

The name Shiftbrite is a bit of a giveaway to how it actually works. It is very bright – looking at it directly during operation is dangerous, and the shift relates to how the control data is used by the modules.  To put it simply they are 32-bit shift registers with an RGB LED attached… so all you need to do is have 32 bits of data sent to them – in a similar method just like a 74HC595 shift register. The good thing about this is you can control more than one Shiftbrite using a daisy-chain method – with a catch. If you have, say, three in a row and you only want to change the second Shiftbrite, you need to send out data to refresh all three of them. But don’t panic, doing so is quite easy.

There are two concepts to understand to effectively use a Shiftbrite – pulse width modulation and how colours are represented digitally. PWM is quite easy with LEDs, it is a method of controlling the brightness by switching them on and off rapidly to give the illusion of brightness. For example, at full PWM, the LED is on… at 50 % the LED is on for 50% of the time, and off for 50% of the time. Below is a demonstration of PWM from another article:

Representing colours digitally is also easy. As you may know, colours can be created by mixing the primary colours red, green and blue. With the Shiftbrite each primary colour can have a value of between zero (off) and 1023 (full). Say for example, you only want red – so you set the data to be: red – 1023, green – zero, blue zero. And so on. For a very good explanation on how this works please visit this site. The Shiftbrite uses 10 bits of data for each colour, allowing a range of resulting colours in the billions. So let’s get blinking…

Here is an example sketch from the Macetech website: demo1.pdf. Connection to the board is very easy, just 5V and GND, and the four data lines:

The only concern when running Shiftbrites is their power consumption. One unit will use 20 mA per primary colour, which is fine for an Arduino or compatible board. However if you are using two or more, you will need to supply an external power supply to the Shiftbrites, between 5.5 and 9 volts, and 60 mA per module. Moving on, here is a video of one Shiftbrite in action, just rotating between red, green and blue:

That is bright. The only thing better than one Shiftbrite is two, so here you are. In the second demonstration, we are using the same sketch as in the first. So the second Shiftbrite is reacting to the data as shifted out by the first when it receives new data:

So now for some more colours. Using the following sketch demo 2.pdf the Shiftbrite generates shades of primary colours, then all the colours randomly. This time to save my eyesight it uses the ping-pong ball diffuser from the blinky project:

Well I hope you found this review interesting, and helped you think of something new to make. In conclusion I would consider the Shiftbrite great for use in projects where you need the blinking and display fun of RGB LEDs, but with a greater brightness. You can purchase Shiftbrites and a range of fun stuff from Little Bird Electronics.

As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts. Or join our new Google Group.

[Note - The Shiftbrites were purchased by myself personally and reviewed without notifying the manufacturer or retailer]

Otherwise, have fun, be good to each other – and make something! :)

August 13, 2010 Posted by | arduino, microcontrollers, part review | , , , , , , , , , , , , , , | 2 Comments

Kit Review – adafruit industries TV-B-Gone

[Updated 17/01/2013]

In this review we examine an easy to build kit from adafruit industries that offers literally hours and hours of fun, if you like to get up to some mischief – the TV-B-Gone. This fascinating little device is basically an infra-red remote control for televisions and some monitors. It has a microcontroller programmed with the “off” code for a wide range of display brands, and four very strong infra-red transmitting LEDs, two with a wide beam, and two with a narrow but longer beam.

Here is the little culprit in standard assembled form:

It is a very easy kit to assemble, once again the team at adafruit have published an extensive amount of information, from assembly tutorials to how it works, and even the design itself as the kit is open-source hardware. So in this article you can follow the assembly, and use of this bag of fun.

As usual, this kit arrives in a resealable, anti-static bag. After ensuring I had the correct parts, from the documentation on the adafruit website, it was time to follow the simple instructions and start getting it together. Now this will be the second time I have built a TV-B-Gone… the first one is in the photo above, and had me removed from a department store (thanks Myer…) – so this time I am rebuilding it to fit inside a typical baseball cap.

Soldering it was quite simple, the PCB is solder-masked and has a very well detailed silk-screen:

Just following the instructions, and being careful not to rush is the key. Another feature of adafruit kits is that the are designed very well with regards to troubleshooting. For example, you have the opportunity to test it before finishing. So at this stage you can fit the AA cells and power it up, if the LED blinks you’re all good:

And we’re done… almost.

For installation into the hat, the button and the LEDs will need to be a distance away from the PCB. At this stage I was not sure where to put the button, so for now it can stay on the side of the cap:

Naturally you can use any momentary push button, however I will use the included example (above) with a length of wire. With this style of hat, especially a black one, slight bulges underneath the surface do not seem that apparent, however it is wiser to spread out the entire unit:

Although thinner AAA cells could be used for the power supply, for a good day’s action you will want the extra capacity of AA cells, so we’ll stick with them for now. The next step was to wire up the LEDs. They were connected individually to the PCB with lengths of wire, and heatshrink was used to insulate and darken the legs:

And finally the finished product, ready for insertion into a piece of clothing, or in our case – a cap:

At this point it was time to take it for a test toast. The quickest way to test an infra-red transmitter is to look at the LEDs through a digital camera – it can display the infra-red wavelengths whereas the human eye cannot see them. For example:

Those LEDs can get very bright (in infra-red terms), and is also how night-illumination for digital security cameras work. If you had a lot of those LEDs pointing at a security camera at night, you could blind it. That gives me an idea…

Anyway…

Assembling the kit in this format gives you lots of options for hiding it. For example, you could:

  • put the PCB and power in a jacket’s inside pocket, and have the LEDs poke out the neck;
  • place them in a cap as we are;
  • use a large ladies’ handbag, with the LEDs out the top, and the button underneath a handle;
  • sew the LEDs into the head-cover of a hooded jacket (with some longer leads) and have the PCB, power and button in the pockets

So here are the LEDs mounted under the brim of the cap.

If you are going to staple them in, be careful not to puncture the wires. The ends of the staple should come through to the top of the brim – in this case I covered them with black ink from a felt pen so they would blend in. The button lead’s position is down to personal preference, in my case the button is just poking out next to the strap on the back of the cap. So all I need to do is appear to scratch the back of my head to activate the TV-B-Gone.

And here is the finished product, with an unfinished author:

Well by now you want to see it working. So here you are… I went on a field trip wandering about the central business district of Brisbane, Australia:

My apologies for the shaky footage, doing this isn’t something you can really capture with a camera and a tripod. :) The problem was getting close enough, or most places had either covered their IR receiver, had a brand of TV not recognised by the TV-B-Gone, or used a large monitor instead of a television. But it was fun nevertheless.

In conclusion, this is an easy to assemble kit which is fun and certainly will get you into harmless trouble. Again, this is the type of kit that would be good for those who are being introduced to the fascinating world of electronics (etc) as it is quick to build, and does something with the “real world”  that young people love so much. Or anyone else for that matter.

As much fun as it is to switch off televisions and advertising monitors, I would hope that end users will still be responsible with their TV-B-Gone use. Please head into a department store, your favourite eatery, coffee shop or mall and switch off the TVs.  However, please do not turn off displays in railway stations, airports or other places where the authorities will take offence. You will get in real trouble. Or if you’re feeling suicidal, go switch off the TVs at the OTB.

[Note - this kit was purchased by myself personally and reviewed without notifying the manufacturer or retailer]

In the meanwhile 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? And join our friendly 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.

August 13, 2010 Posted by | kit review, learning electronics | , , , , , , , , , , , , , , , , , , , , , | 13 Comments

Introduction to the Inductor

Hello everyone!

Today we are going to explore the use of the Inductor. This is a continuation from the series of articles on alternating current. An inductor is a component that can resist changes in AC current, and store energy in a magnetic field from a current that passes through it. A changing current (AC) causes a changing magnetic field which induces a voltage that opposes the current produced by the magnetic field. This is known as the inductance.  One could think of an inductor as an AC resistor. But first of all, what is an inductor comprised of?

In simple terms an inductor is a coil of wire, wrapped around a core. The core forms a support for the coil of wire – such as ceramic cores, or in some cases can affect the properties of the magnetic field depending on the chemical composition of the core. These may include cores formed from ferrite (usually zinc and manganese, or zinc and nickel) or powdered iron (which has a tiny air gap allowing the core to store a higher level of magnetic flux (the measure of magnetic field strength)- allowing a higher level of DC current to flow through before becoming saturated.

So, the amount of inductance is influenced by several factors – the core material (as above), the size and shape of the core, as well as the number of turns of wire in the coil and its shape. The unit of inductance is the henry (H), however common values are usually in the millihenry (mH) or microhenry (uH) range.

Furthermore, there is an amount of DC resistance due to the properties of the coil wire, however this is usually negligible and kept to a minimum. For example, looking at a data sheet for a typical line of inductors – inductors.pdf – the DC resistance of a 10uH inductor is a maximum of 0.05 ohms. With inductors of higher values, the DC resistance will need to be taken account of. But more about that later.

This is the usual symbol for an inductor in a schematic:

However this may also be used:

And here is a variety of inductors in the flesh:

radial ferrite core, generally for PCB use, handles around 1.5 amperes

radial leaded, very low resistance, handles around 2.5 amperes

ferrite core, convenient for through-hole PCB

phenolic core

toroidal - handles large currents ~10 amperes depending on model

surface-mount, can still handle around 500 mA

All of the pictured inductors have an inductance of 10 uH.

Now let’s examine how inductors work with alternating current. Consider the following circuit:

Just like capacitors in AC circuits, an inductor has a calculable reactance. The formula for the reactance (X, in ohms) of an inductor is:


where f is the frequency of the AC and L is the value of the inductor in Henries (remember that 1uH is 10 to the power of -6).

QuestionWhat value is the inductor sold by Little Bird Electronics?

The formula to calculate the impedance of the above circuit is:

where Z is in ohms. And finally, the formula for AC Vout is

The formula for DC Vout is the usual voltage dividing formula. In this case, as we consider the inductor to not have any resistance, DC Vout = DC Vin.

So, let’s work through an example. Our DC Vin is 12 volts, with a 2V peak to peak AC signal, at a frequency of 20 kHz. The resistor R has a value of 1 kilo ohm, and the inductor L is 10 millihenries (0.01 H). A quick check of the data sheet shows that the 10 mH inductor has a resistance that cannot be ignored – 37.4 ohms. So this must be taken into account when calculating the DC Vout. Therefore we can consider the inductor to be a 37.4 ohm resistor when calculating the DC Vout, which gives us a result of 11.56 volts DC.

Substituting the other values gives us a reduced AC signal voltage of 1.24 volts peak to peak.

Another interesting fact is that there is a relationship between AC Vout and the frequency of the AC signal. In the video below, I have used a 10k ohm resistor and a 10 uH inductor in the circuit described above. The frequency counter is measuring the frequency of AC Vin, and the multimeter is measuring the AC Vout:

This is an interesting relationship and demonstrates how an inductor can resist alternating current, depending on the frequency.

Thus ends our introduction to the inductor. We will continue with the inductor in the near future. I hope you understood and can apply what we have discussed today. As always, thank you for reading and I look forward to your comments and so on. Furthermore, don’t be shy in pointing out errors or places that could use improvement, you can either leave a comment below or email me – john at tronixstuff dot com.

Please subscribe using one of the methods at the top-right of this web page to receive updates on new posts. Or join our Google Group and post your questions there.

Otherwise, have fun, be good to each other – and make something! :)

August 11, 2010 Posted by | education, learning electronics, test equipment | , , , , , , , , , , , , , , , , , , , , , , | Leave a Comment

Moving Forward with Arduino – Chapter 14 – XBee introduction

Learn how to use XBee wireless data transceivers with Arduino. This is part of a series originally titled “Getting Started with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.

Updated 02/03/2013

We will examine the Series 1 XBee wireless data transceivers from Digi in the USA. Although in the past we have experimented with the inexpensive 315MHz transmit/receive pair modules (chapter 11), they have been somewhat low in range and slow with data transmission. The XBee system changes this for the better.

First of all, what is an Xbee module? It is a very small piece of hardware that can connect wirelessly with another using the Zigbee communication protocols. There are many different models, including aerial types and power outputs. In this tutorial we’re using Series One XBees.

From Wikipedia, Zigbee is:

ZigBee is a specification for a suite of high level communication protocols using small, low-power digital radios based on the IEEE 802.15.4-2003 standard for wireless home area networks (WHANs), such as wireless light switches with lamps, electrical meters with in-home-displays, consumer electronics equipment via short-range radio. The technology defined by the ZigBee specification is intended to be simpler and less expensive than other WPANs, such as Bluetooth. ZigBee is targeted at radio-frequency (RF) applications that require a low data rate, long battery life, and secure networking.

Phew. For this chapter I will try and keep things as simple as possible to start off with. Here is an image of a typical Xbee unit:

Note that the pin spacing is small than 2.54mm, so you cannot just drop these into a breadboard. However for the purposes of our experimenting more equipment is needed. Therefore I am making use of this retail package from Sparkfun retailers:

A great starting point

This bundle includes two Xbee modules, an Xbee shield to connect one of the modules to an Arduino Uno-style board. When it comes time to solder the sockets into your shield, the best way is to insert them into another shield that is upside down, then drop the new shield on top and solder. For example:

Finally, the bundle also includes a USB Explorer board, which allows us to connect one Xbee to a personal computer. This allows us to display serial data received by the Xbee using terminal software on the PC. One can also adjust certain Xbee hardware parameters by using the explorer board such software.

Let’s do that now. You will need some terminal software loaded on your computer. For example, Hyperterminal or Realterm. Plug an Xbee into the explorer board, and that into your PC via a USB cable. Determine which port (for example COM2:) it is using with your operating system, then create a new terminal connection. Set he connection to 9600 speed, 8 bits, no parity, 1 stop bit and hardware flow control. For example, in Hyperterminal this would look like:

Once you have established the connection, press “+++” (that is, plus three times, don’t press enter) and wait. The terminal screen should display “OK”. This means you are in the XBee configuration mode, where we can check the settings and change some parameters of the module. Enter “ATID” and press enter. The terminal window should display a four-digit number, which is the network ID of the module. It should be set by default to 3332. Unless you plan on creating a huge mesh network anytime soon, leave it be. To be sure your modules will talk to each other, repeat this process with your other XBee and make sure it also returns 3332. However as this is the default value, they should be fine.

Now for our first example of data transmission, insert one Xbee into the explorer module, and the other into the Xbee shield. With regards to the Xbee shield – whenever it is connected to an Arduino board and you about to upload a sketch, look for a tiny switch and change it to DLINE from UART. Don’t forget to change it back after uploading the sketch. See:

We are going to use the two Xbee modules as a straight, one-way serial line. That is, send some data out of the TX pin on the transmit board, and receive it into the terminal on the PC. Now upload this sketch into your Arduino board. This is a simple sketch, it just sends numbers out via the serial output. Then set the switch on the shield back to UART, and reset the board. If you can, run this board on external power and put it away from the desk, to give you the feeling that this is working :)

Note: More often that not one can purchase AC plug packs that have USB sockets in them, for charging fruity music players, and so on.

Or you might have received one as a mobile phone charger. These are great for powering Arduino boards without using a PC.

Now ensure your explorer module is plugged in, and use the terminal software to connect to the port the explorer is plugged into. After connecting, you should be presented with a scrolling list of numbers from 0 to 99, as per example 14.1 sketch:

How did you go? Sometimes I used to get the COM: ports mixed up on the PC, so that is something to keep track of. If you are powering both Xbees from your PC using USB cables, double-check the terminal software is looking at the explorer board, as an Arduino transmitting serial data through an Xbee shield will still send the same data back to the PC via USB.

Now that we have sent data in one direction, we can start to harness the true power of Xbees – they are transceivers, i.e. send and receive data.

Example 14.2

We will create an on-demand temperature and light-level sensor. Our arduino board will have a temperature sensor and a light-dependent resistor, and using the terminal on the computer, we can request a temperature or light-level reading from the remote board. More about temperature sensors in chapter two. First of all, the remote board hardware setup:

… and the schematic:

It never hurts to elevate your other Xbee:

For the PC side of things, use the explorer board and USB cable. Here is the sketch. It is quite simple. The remote board ‘listens’ to its serial in line. If it receives a “1″, it reads the temperature, converts it to Celsius and Fahrenheit, and writes the result to its serial out line, which is sent over our Xbee data bridge and received by the host computer. A “2″ will result in the analogue value of the photocell to be sent back as a “light level”. Once again we use the terminal software to control the system.  Here is a quick video of the terminal in action:

The speed is quite good, almost instantaneous. By now hopefully you can see how easy it is to end some data backwards and forwards over the ether. The range is only limited by the obstacles between the Xbee transceivers and the particular power output of each model. With example 14.2, there were two double-brick walls between them. Furthermore, we can build fully computer-independent systems that can talk to each other, such as more portable remote controls, or other data-gathering systems. In the next few chapters, sooner rather than later.

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.

August 6, 2010 Posted by | arduino, learning electronics, microcontrollers, tutorial, wireless, xbee | , , , , , , , , , , , , , , , , , , , , | 6 Comments

Blinky the one-eyed clock

In this tutorial you learn how to make a blinking clock with a difference!

Updated 18/03/2013

Followers of my website would realise that I tend to make too many clocks in those tutorials. Well, I like making clocks… so here is another one. However this time I have tried to make the most simple version possible. Usually projects will have many LEDs, or perhaps an LCD, buzzers, buttons, all sorts of things. Which looks great and will impress many. But the other day I thought to myself … “how few things do you need to show the time?”

So here is my answer to that question: Blinky the one-eyed clock …


It reminds me of the giant killer orb from The Prisoner… Using a minimal Arduino bootloader system, a DS1307 real time clock IC and an RGB diffused LED … we can make a clock that blinks the time, using the colours of the LED to note different numerical values. For example, if the time is 12:45, the clock will blink red 12 times, then show blue for a second (think of this as the colon on a digital clock) then blink four times in green (for forty minutes), then blink three times in red for the individual minutes. If there is a zero, blink blue quickly. Then the clock will not display anything for around forty seconds, then repeat the process. Here he (she, it?) is blinking the time:

Setting the clock is simple. It is set to start at 12:00 upon power up. So for the first use you have to wait until about five seconds before midday or midnight, then power it up. To save cost it doesn’t use a backup lithium battery on the real-time clock IC, but you could if you really wanted to. If you would like to follow my design process narrative, please read on. If you only want the sketch and schematic, :( head to the bottom of this article.

Design process narrative…

So let’s get started!

The first thing to do was test the RGB LED for brightness levels, so I just connected it to the digital output pins of my Eleven via suitable current-limiting resistors. Each LED is going to be different, so to ensure maximum brightness without causing any damage you need to calculate the appropriate resistor values. This is quite easy, the formula is: resistor (ohms) = voltage drop / LED current So if you have a 5 V supply, and LED that needs only 2 volts, and draws 20 milliamps (0.2 amps) , the calculation will be: resistor = (5-2)/0.02 = 150 ohms. To be safe I used a 180 ohm resistor. The LED was tested with this simple sketch:

/*
  blinky LED test
 */

int red = 2;
int green = 3;
int blue = 4;
int d = 300;
void setup()
{
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
}

void loop()
{
  digitalWrite(red, HIGH);
  delay(d);
  digitalWrite(red, LOW);
  delay(d);
  digitalWrite(green, HIGH);
  delay(d);
  digitalWrite(green, LOW);
  delay(d);
  digitalWrite(blue, HIGH);
  delay(d);
  digitalWrite(blue, LOW);
  delay(d);
}

It was interesting to alter the value of d, the delay variable, to get an idea for an appropriate blinking speed. Originally the plan was to have the LED in a photo frame, but it was decided to mount a ping-pong ball over the LED for a retro-style look.  Here is a short video of the result of the test:

If you are going to use a ping-pong ball, please be careful when cutting into it with a knife, initially it may require a lot of force, but once the knife cuts through it does so very quickly.

Now it was time to develop the sketch to convert time into blinks. The sketch itself is quite simple. Read the hours and minutes from the DS1307 timer IC; convert the hours to 12 hour time; then blink an LED for the number of hours, display another colour for the colon; divide the minutes by ten and blink that in another colour; then the modulus of minutes and ten to find the individual minutes, and blink those out. Here is the first sketch I came up with. Finally, the code was tested using the Eleven board and my DS1307 real time clock shield. It is best to use existing hardware while testing, before committing to purchasing new hardware and so on. So here it is on the breadboard:

And telling the time! In this example, the time is 3:45…

But perhaps that was a little bland. By using analogWrite() we can control the brightness of the LED segments. So now there are two more functions, whiteGlow() and blueGlow(); whose purpose is to make the display “glow” by increasing then decreasing the brightness. And scale back the amount of blinking, to increase battery life and make blinky less obvious. So now the display will glow white to announce the forthcoming display of time, wait a second, blink the time (with a blue glowing colon) then stay dark for ten seconds before repeating the process. Here is a quick demonstration of this display style:

Here is the sketch for the above demonstration, and the final one I will use with the hardware prototype. Once happy with the sketch, I put a fresh ATmega328 with Arduino bootloader in the board and programmed it with the blinky sketch, to be used in the final product.

Next was to build my own hardware. My last hardware unknown is the amount of current the circuit draws. Once I know this the correct voltage regulator and power supply can be decided upon. I had a fair idea it would be less than 100 milliamps, so I put a 6V battery onto supply duty via a 78L05 5V regulator (data sheet), and recorded the result:

So it varies, between 20.5 and 46 mA. As it only reaches 46 mA for a short time, we could consider the constant draw to be averaged out at 30 mA. I really want this to be able to run from a battery, but without having an external lead-acid battery lurking around, it will need a plug-pack with an output voltage greater than 7V DC. Another alternative would be to run it from a USB socket, a nice source of 5V. If doing so, there wouldn’t be a need for the 78L05 regulator. Which brings us to the  circuit diagram, which includes the power regulator:

It does not allow for programming in the circuit, so you will need to program the microcontroller on another Arduino or compatible board, then transfer it to the blinky circuit board as described above. At this stage I tested it again, but using a solderless breadboard. In doing so you can make final hardware checks, and  generally make sure everything works as it should. This is also a good stage to double-check you are happy with the display behaviour, default time and so on.

works, so hardware ok! Arduino for quick 5v supply

Time to solder up the circuit on some stripboard. Blank stripboard varies, but luckily I found this and a nice box to hold it in:

Stripboard does vary between retailers and so on, so you will need to work out the layout with your own board. In doing so, please double-check your work – follow the layout against the schematic and so on. Have a break, then check it again. There is nothing worse than soldering away to realise you are one strip too far over or something. My hand-eye coordination is not the best, therefore my soldering isn’t pretty, but it works:

One would say that there is a good argument for making your own PCBs… and I would start to agree with that. The LED is soldered to some short leads to give it a bit of play, and some heatshrink over the legs to keep them isolated:

And finally, to add a DC socket to feed blinky some power…

The last thing was to check the soldering once more under natural light, to check for bridges or shorts, then have a cup of tea. Upon my return I drilled out a hole in the enclosure lid for the LED, and one one the side for the DC socket, and fitted the lot together… and success! It worked :)

So there you have it. The journey from a daydream to a finished product… well a prototype anyway. But it works, and that is the best feeling of all.

Here is the schematic: (click to enlarge)… and the Arduino sketch blinky pde. I hope you enjoyed reading this post and hopefully felt inspired enough to make your own.

In the meanwhile 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? And join our friendly 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.

August 2, 2010 Posted by | arduino, clocks, ds1307, microcontrollers, projects, tutorial | , , , , , , , , , , , , , , , , , , , , , , , , , , | 17 Comments

Announcement – August Competition!

Hello everyone!

Winner for August is Neil S. who won the major prize! You have been emailed.

During July there was another competition which was quite fun, so from August and onwards we shall do it again. The winner ‘S.R.’ won the minor prize so the major prize jackpots into this month. Running these competitions are a way of saying thank you to my readers, and to generate some interaction. So …

All you have to do for a chance to win is the following:

  1. Read the blog posts and articles in August, as there will be four questions you will need to answer placed randomly amongst the posts. To keep track, subscribe using one of the methods on the right hand side of this page
  2. When you have answers for all four questions, email them to competition@tronixstuff.com
  3. If you follow me on twitter (@tronixstuff) and retweet one post in August, you will receive two entries, so put your twitter address in your email.
  4. On September the 1st, all the email addresses will be placed in a random draw and one selected. If the entry drawn has all four questions correct, they will win the major prize!
  5. If the first entry drawn does not have four correct answers, they will win the minor prize, and the major prize will carry over until September, to be combined with the new major prize.

The prizes!

Major prize

The major prize for August consists of the following:

  • One assembled, used JYE Tech Digital Storage Oscilloscope – from the kit review;
  • One new pair of 315 MHz wireless data modules, as used in Getting Started with Arduino – Chapter Eleven;
  • And something different, the new Texas Instruments MSP430 Launchpad kit, including evaluation board, two MCUs  and the USB cable.

Minor prize

The minor prize for August is John’s Fun with LEDs! pack, consisting of:

  • ten each of red, green, yellow and orange 5mm LEDs;
  • four RGB 10mm diffused LEDs
  • three 74HC595 shift registers
  • two Texas Instruments TLC5940 16-channel LED driver ICs
  • two LM3914 bar graph/dot driver ICs
  • 20 x 560 ohm 1% resistors (they missed the photo call)

Hopefully everyone can have some fun reading about electronics and learning along the way. As with any competition, there are a few rules:

  1. If you have won a previous competition, you cannot enter
  2. If you know me personally, you cannot enter
  3. The prizes carry no warranty, we accept no liability for anything at all that they may cause
  4. Prizes only include what is in the photograph, and will be sent via standard airmail free of charge
  5. My decision is final
  6. You can witness the draw in person with prior arrangement
  7. The time used is Australian Eastern Standard Time (GMT: +10)

If you cannot wait for a chance to win, the DSO and and a range of LEDs are available from our friends at Little Bird Electronics.

Congratulations to Neil S. who is the winner of the major prize!

The minor prize will jackpot into September, details to be posted shortly.

August 2, 2010 Posted by | competition | , , , , , , , , , , , , , , , , | 1 Comment

   

Follow

Get every new post delivered to your Inbox.

Join 4,007 other followers

%d bloggers like this: