The 555 Precision Timer IC
Hello readers
Today we revisit one of the most popular integrated circuits ever conceived – the 555 timer IC. “Triple-five”, “five-five-five”, “triple-nickel” … call it what you will, it has been around for thirty-eight years. Considering the pace of change in the electronics industry, the 555 could be the constant in an ever-changing universe. But what is the 555? How does it work? How can we use it? And … why do we still use it? In this introductory article we will try to answer these questions. If you would like to see some examples, visit here.
What is the 555?
The 555 timer is the solution to a problem found by the inventor – Hans Camenzind. He saw the need through his radio work for a part that could act as an oscillator or a timer [1]; and working as a contractor for Signetics developed the 555. (Signetics was purchased by Philips in 1975, and their semiconductor division was spun off as NXP in 2006). The 555 has to be one of the most used ICs ever invented. It is used for timing, from microseconds to hours; and creating oscillations (which is another form of timing for the pedants out there). It is very flexible with operation voltage, you can throw from 4.5 to 18V at it; you can sink or source 200mA of current through the output; and it is very cheap – down to around nine cents if you order several thousand units. Finally, the 555 can achieve all of this with a minimum of basic components – some resistors and capacitors.
Here are some examples in the common DIP casing:
Furthermore a quick scan of suppliers’ websites show that the 555 is also available in surface-mount packages such as SOIC, MSOP and TSSOP. You can also source a 556 timer IC, which contains two 555 ICs. (What’s 555 + 555? 556…) Furthermore, a 558 was available in the past, but seems rather tricky to source these days.
How does the 555 work?
The 555 contains two major items:
- A comparator – a device which compares two voltages, and switches its output to indicate which is larger, and
- A flip-flop – a circuit that has two stable states, and those states can be changed by applying a voltage to one of the flip-flop’s inputs.
Here is the 555 functional diagram from the TI 555 data sheet.pdf:
… and the matching pin-out diagram:
Don’t let the diagrams above put you off. It is easier to explain how the 555 operates within the context of some applications, so we will now explore the three major uses of the 555 timer IC in detail – these being astable, monostable, and bistable operations, in theory and in practice.
Astable operation
Astable is an on-off-on… type of oscillation – and generates what is known as a square wave, for example:
There are three values to take note of:
- time (s) – the time for a complete cycle. The number of cycles per second is known as the frequency, which is the reciprocal of time (s);
- tm (s) – the duration of time for which the voltage (or logic state) is high;
- ts (s) - the duration of time for which the voltage (or logic state) is low.
With the use of two resistors and one capacitor, you can determine the period durations. Consider the following schematic:
Calculating values for R1, R2 and C1 was quite simple. You can either determine the length of time you need (t) in seconds, or the frequency (Hz) – the number of pulses per second.
t (time) = 0.7 x (R1 + [2 x R2]) x C1
f (frequency) = 1.4 / {(R1 + [2 x R2]) x C1}
Where R1 and R2 are measured in ohms, and C1 is measured in farads. Remember that 1 microfarad = 1.0 × 10-6 farads, so be careful to convert your capacitor values to farads carefully. It is preferable to keep the value of C1 as low as possible for two reasons – one, as capacitor tolerances can be quite large, the larger the capacitor, the greater your margin of error; and two, capacitor values can be affected by temperature.
How the circuit works is relatively simple. At the time power is applied, the voltage at pin 2 (trigger) is less than 1/3Vcc. So the flip-flop is switched to set the 555 output to high. C1 will charge via R1 and R2. After a period of time (Tm from the diagram above) the voltage at pin 6 (threshold) goes above 2/3Vcc. At this point, the flip-flop is switched to set the 555 output to low. Furthermore, this enables the discharge function – so C1 will discharge via R2. After a period of time (Ts from the diagram above) the voltage at pin 2 (trigger) is less than 1/3Vcc. So the flip-flop is switched to set the 555 output to high… and the cycle repeats.
Now, for an example, I want to create a pulse of 1Hz (that is, one cycle per second). It would be good to use a small value capacitor, a 0.1uF. In farads this is 0.0000001 farads. Phew. So our equation is 1=1.4/{(R1 + [2 x R2]) x C1}. Which twists out leaving us R1=8.2Mohm, R2=2.9MOhm and C1 is 0.1uF. I don’t have a 2.9MOhm resistor, so will try a 2.7MOhm value, which will give a time value of around 0.9s. C2 in astable mode is optional, and used if there is a lot of electrical noise in the circuit. Personally, I use one every time, a 0.01uF ceramic capacitor does nicely. Here is our example in operation:
Notice how the LED is on for longer than it is off, that is due to the ‘on’ time being determined by R1+R2, however the ‘off’ time is determined by R2 only. The ‘on’ time can be expressed as a percentage of the total pulse time, and this is called the duty cycle. If you have a 50% duty cycle, the LED would be on and off for equal periods of time. To alter the duty cycle, place a small diode (e.g. a 1N4148) over pins 7 (anode) and 2 (cathode). Then you can calculate the duty cycle as:
Tm = 0.7 x R1 x C1 (the ‘on’ time)
Ts = 0.7 x R2 x C1 (the ‘off’ time)
Furthermore, the 555 can only control around 200mA of current from the output to earth, so if you need to oscillate something with more current, use a switching transistor or a relay between the output on pin 3 and earth. If you are to use a relay, put a 1N4001 diode between pin 3 (anode) and the relay coil (cathode); and a 1N418 in parallel with the relay coil, but with the anode on the earth side. This stops any reverse current from the relay coil when it switches contacts.
Monostable operation
Mono for one – one pulse that is. Monostable use is also known as a “one-shot” timer. So the output pin (3) stays low until the 555 receives a trigger pulse (drop to low) on pin 2. The length of the resulting pulse is easy to calculate:
T = 1.1 x R1 x C1;
where T is time in seconds, R1 is resistance in ohms, and C1 is capacitance in farads. Once again, due to the tolerances of capacitors, the longest time you should aim for is around ten minutes. Even though your theoretical result for T might be 9 minutes, you could end up with 8 minutes 11 seconds. You might really need those extra 49 seconds to run away… Though you could always have one 555 trigger another 555… but if you were to do that, you might as well use a circuit built around an ATmega328 with Arduino bootloader.
Now time for an example. Let’s have a pulse output length of (as close as possible to) five seconds. So, using the equation, 5 = 1.1 x R1 x C1… I have a 10 uF capacitor, so C1 will be 0.00001 farads. Therefore R1 will be 454,545 ohms (in theory)… the closest I have is a 470k, so will try that and see what happens. Note that it you don’t want a reset button (to cancel your pulse mid-way), just connect pin 4 to Vs. Here is the schematic for our example:
How the monostable works is quite simple. Nothing happens when power is applied, as R2 is holding the trigger voltage above 1/3Vcc. When button S1 is pushed, the trigger voltage falls below 1/3Vcc, which causes the flip-flop to set the 555′s output to high. Then C1 is charged via R1 until the threshold voltage 2/3Vcc is reached, at which point the flip-flip sets the output low and C1 discharges. Nothing further happens until S1 is pressed again. The presence of the second button S2 is to function as a reset switch. That is, while the output is high the reset button, if pressed, will set the output low and set C1 to discharge.
Below is a video of my example at work. First I let it run the whole way through, then the second and subsequent times I reset it shortly after the trigger. No audio in clip:
Once again, we now have a useful form of a one-shot timer with our 555.
Bistable operation
Bistable operation is where the 555′s output is either high, or low – but not oscillating. If you pulse the trigger, the output becomes and stays high, until you pulse reset. With a bistable 555 you can make a nice soft-touch electronic switch for a project… let’s do that now, it is so simple you don’t need one of my quality schematics. But here you are anyway:
In this example. pressing S1 sets the voltage at pin 2 (trigger) to below 1/3Vcc, thereby setting the output to high – therefore we call S1 our ‘on’ switch. As pin 6 (threshold) is permanently connected to GND, it cannot be used to set the output to low. The only way to set the output back to low is by pressing S2 – the reset button, which we can call the ‘off’ switch. Couldn’t be easier, could it? And that output pin could switch a transistor or a relay on or off, who knows? Your only limit is your imagination. And here’s one more video clip:
And there you have it – three ways in which we can use our 555 timer ICs. But in the year 2011, why do we still use a 555? Price, simplicity, an old habit, or the fact that there are so many existing designs out there ready to use. There will be many arguments for and against continued use of the 555 – but as long as people keep learning about electronics, the 555 may still have a long and varied future ahead of it.
Well that is all we have time for in this instalment. Stay tuned for more about the 555 in the near future, including some example circuits and so on.
In the meanwhile 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? 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.
References
[1] “The 555 Timer IC – An interview with Hans Camenzind” (Jack Ward – semiconductormuseum.com)
Various diagrams and images from the Texas Instruments NE555 data sheet.
Kit review: Freetronics KitTen Arduino-compatible board
Hello everyone
Within this article we are going to examine another new kit available from Freetronics, a company formed to provide many interesting Arduino-based products after the publication of the book “Practical Arduino” by Jonathan Oxer and Hugh Blemings – which in itself is a good read, there are many interesting projects to make and learn from.
Today we examine their answer to “is there a kit version of the TwentyTen Arduino Duemilanove-compatible board?” – by assembling their KitTen. Some people may be wondering why one would want to build a KitTen instead of an assembled unit. Personally I could think of the following reasons:
- It’s fun to make something and see it work;
- You can save over Au$10;
- There are a lot more smoothing capacitors in the KitTen design than normal boards;
- There is a dedicated 3.3V 100 milliamp power regulator (twice the current of the usual board’s 50mA supply) - ideal for running thirsty shields that need a native 3.3V;
- The board is for a project that needs to use a modified version of the TwentyTen/Duemilanove;
- You want a board with a native serial instead of USB interface;
- All that lovely prototyping area above the microcontroller;
- The power light and LED for D13 are always visible due to their location on the edge of the PCB;
- You could solder in your microcontroller to avoid theft – great for school and public use (Yes, this has happened)…
And so on. Moving forward, opening the KitTen package reveals the following:
Once again with a Freetronics kit, all instructions are included in colour, as well as the circuit schematic and another sheet explaining how the KitTen will work with Arduino systems and the specifications. The PCB is solder-masked and silk-screened with a very informative layout:
The rest of the included components shipped in an anti-static bag, including labelled resistors and an IC socket for the microcontroller:
By following the included detailed instructions, everything went well. The layout on the PCB is detailed with all component values, which makes life easier. Starting with the low-profile components:
… followed by higher-profile components such as the IC socket and capacitors:
… and finally the shield sockets. Instead of trying to balance them, it is a lot quicker to place the sockets on an existing Arduino shield, turn it over, drop the KitTen on top then solder the pins in:
Then finally we are finished:
There are a couple of things to watch out for when using your KitTen. The first is to make sure you have the power-select jumper fitted correctly:
Place it on the left pins (as above) to power your KitTen from the FTDI cable; place the jumper on the right pins to power from the DC socket. You should use a power supply of between 9 to 12 volts DC at one amp. The second item to take care with is the blue power LED. The supplied model was so bright it was like staring into the sun. You may wish to test your own one and possibly replace it for a duller version, or use some fine sandpaper to reduce the brightness of the included LED. To upload sketches to your KitTen you will need a 5 volt FTDI cable. As mentioned above, this can also power your board as well.
Overall, this is an excellent kit, and considering the price of doing it yourself – good value as well. To get your hands on this product– visit Freetronics’ website, or your local reseller.

Remember, if you have any questions about these modules please contact Freetronics via their website.
Higher resolution images available on flickr.
Otherwise, have fun, stay safe, be good to each other – and make something! ![]()
[Note - the kit assembled in this article was received from Freetronics for review purposes]
Review – Fluke 233 Remote Display True RMS Multimeter
Hello readers
Several followers of my website have noticed the use of an interesting multimeter in a few of my articles, and were curious about it. So in this article we will discuss it in more detail. It is certainly novel in design, and has proven to be very convenient in use – the Fluke 233 remote-display true RMS multimeter. It arrives in a cardboard box that is easily recycled:
Upon tearing open the packaging we are presented with the following contents:
The contents of the box are as follows:
- The meter itself;
- a long (~1.2m) pair of Cat IV leads with very sharp points;
- matching insulated alligator clip adaptors;
- a K-type thermocouple;
- a printed Getting Started manual, and the complete manual on CDROM;
- a single, universal getting started sheet – explains how to remove battery isolation tabs.
However, a carry case was not included. Considering the cost of the meter here (Au$550 + tax), one would have expected a case. On the other hand, if you/your workplace can afford a 233, you can pay for your own case. So there’s two angles to the case perspective.
It is good to see that there isn’t too much of a printer manual, the less paper used the better. As others have said, if you have one of these meters the manual isn’t necessary apart from checking the specifications, and the same applied to myself. Thoughtfully the meter is supplied and fitted with 5 x AA Duracell alkaline cells, three in the meter body and two in the display unit. All one needs to do is pull out the plastic tabs from the battery compartments, and you’re ready to go.
Physically the unit does not disappoint. Made in the USA. First class. Another solid Fluke design, clean lines, and a great fit and finish. Futhermore it is of a good weight, so you could always bang in a nail with it, or the pointy-head boss. The exterior has the rubber-moulded housing which is not removable, however this would be recommended for the target market – as the 233 would be more of a field work than a test-bench instrument. However, if you do sit it on the bench with the tilting bail, you can still operate it with one hand as it has enough friction to stay put. It is also good to see that the box and packaging are cardboard which is easily recycled.
After flicking the meter on the first thing to do was remove the display, plug in the thermocouple, and toss the body into the freezer:
Even with the meter in the freezer, I could still move the display around 1.5 meters away and it still received the data signal. Notice how the display is on the freezer door – it is magnetic. Immediately the benefits of the remote display come to mind. You can always have the display right where you want it, and the meter where it needs to be… it’s win-win. After showing it to my auto-electrician friend, she didn’t want to give it back. The ability to set up a meter in a less than perfectly safe environment and take the display away is almost priceless. Furthermore, the backlight is a nice even blueish colour, and times out after around forty seconds.
Whilst in the kitchen, I tested out the external temperature of my tea:
Using the meter in general is very simple, you can hold it in one hand and select all of the functions with your thumb. Having the yellow shift key makes changing between associated readings very simple, for example after reading AC voltage:
Then pressing the shift key changes to frequency:
The meter has several useful indication functions – while working with high voltages the triangular market is illuminated; when changing to temperature you are prompted with “OPEN” for the thermocouple, and changing to current you are prompted with “LEAD” to change sockets. It is obvious after a short period of time this was designed by engineers for engineers, and not made to a ‘price’. Although this is not an electronics multimeter, it still has quite a few ranges that would suit at a pinch. Plus the one-touch data hold, minimum and maximum functions are included as with other top-end Flukes. Hopefully someone at Fluke is working on a remote display version of their 87V.
Now that I have had this meter for just over five months, it has already become a worthwhile addition to my bench. For the kind of work I do, it has already replaced another multimeter, my old frequency counter and thermometer. The ranges are quite useful, and the continuity beeper is in the display not the body. According to the manual the 233 is rated for a one meter drop onto any of the six surfaces. Out of respect to the meter I will not throw it into a river or from a moving car. The other factor that prevents me from going to such extremes is the clear plastic over the LCD – there is a small amount of ‘give’ or flexibility in that area. Otherwise the 233 is as solid as they come.
The specifications can be found in detail in the manual here, however a quick glance shows:
Range Accuracy
AC voltage: 0.1mV ~ 1000V 1~2%+3
AC current: 1mA ~ 10A 1.5%+3
DC voltage: 0.1mV ~ 1000V 0.25%+2
DC current: 1mA ~ 10A 1.0%+3 ** no microamperes
resistance: 0.1 ~ 40 meg-ohm 0.9~1.5%+2
frequency: 0.01 Hz ~ 50 kHz 0.1%+2
capacitance: 1nF to 9999 uF 1.9%+2
temperature: -40 ~ 400 degrees Celsius 1%+10
And there is also a diode test and continuity beeper function. Interestingly enough, I discovered by accident that the frequency counter function was slightly underrated. Some more testing showed it was good for up to 99.48 kHz:
Not bad at all. However as with the many pros, there are a few cons to using this meter. The auto-zero time of the display is a little slow, sometimes it can take two seconds. That doesn’t sound like much, but when you’re measuring many components the time adds up. And the LCD is not protected as well as expected, you can push into it with your finger. For a Fluke meter, one would expect it to be much more solid – if the display unit fell from a height and landed on something pointy with the display facing down, it would be ruined. So be careful if you have one. Furthermore, the battery life is around eight to ten weeks of “daily use” (perhaps seven hours a week, usually with the backlight on). Some have said this is bad, however my opinion is that the convenience of the remote display makes up for the shorter battery life.
However at the end of the day – this is a great tool. Being able to measure something outside your field of vision, and having the results in front of you is incredibly useful. You could achieve the same functions by using a meter with a PC interface, but that can be overkill and time-consuming to set up. So if the specifications of the 233 meet your needs, this is a great tool that will serve you very well.
The Fluke 233 Remote Display True RMS Multimeter is available from your local element-14 (previously Farnell) or Fluke distributor.
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 Google Group.
[Disclaimer - the Fluke 233 is a review sample made available by Fluke via element-14]
Otherwise, have fun, be good to each other – and make something! ![]()
Kit review: Freetronics 16×2 LCD Arduino Shield
Hello everyone
This kit has now been discontinued, however Freetronics now have a great LCD+Keypad Shield.
Today we examine their latest kit, the “16×2 LCD Arduino Shield“. This is a very easy to construct, yet useful tool for those experimenting, prototyping and generally making things with their Arduino-based systems. The purpose of the shield is to offer easy access to a 16 x 2 character LCD module, and also the use of five buttons – connected to an analog input using the resistor ladder method. The kit comes packaged very well, and includes not only detailed printed instructions in colour, but also the full circuit schematic:
It is nice to see such a high level of documentation, even though most people may not need it – there is generally someone who does. Sparkfun – get the hint. All the parts are included, and for the first time in my life the resistors were labelled as well:
So being Mr Pedantic I followed the instructions, and happily had the components in without any troubles. The next step was the Arduino shield pins – the best way to solder these is to insert into your Arduino board, drop the shield on top then solder away as such:
And finally, bolting on the LCD whilst keeping the header pins for the LCD in line. Some people may find the bolt closest to D0 interferes with the shield pin, so you can insert the bolt upside down as I have. Remember to not solder the LCD pins until you are happy it is seated in correctly:
Once you are satisfied the pins are lined up and sitting in their required position – solder them in, tighten your nuts and that’s it:
The contrast of the LCD in real life is better than shown in the photo above – photographing them is a little difficult for me. However once assembled, using the shield is quite easy. If your LCD doesn’t seem to be working after your first sketch, adjust the contrast using the potentiometer. The LCD is a standard HD44780-interface model, and wired in to use a 4-bit parallel data interface. If using these types of LCD is new to you, perhaps visit this article then return. Our shield uses the pins: A0 and D4~D9.
One uses the standard Arduino liquidCrystal library with this LCD, and the function parameters to use are as follows:
LiquidCrystal lcd(8,9,4,5,6,7)
The buttons are read using analog pin A0. Use the following sketch to find the values returned by the analogRead function:
/* analogRead + button demonstration using Freetronics 16x2 LCD shield
John Boxall - http://tronixstuff.com/kitreviews - Jan 2011 */
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
int a=0;
void setup()
{
lcd.begin(16, 2);
} void loop()
{
lcd.clear();
a=analogRead(0);
lcd.setCursor(0,0);
lcd.print("analogRead()");
lcd.setCursor(0,1);
lcd.print("value = ");
lcd.print(a);
delay(200);
}
and a quick video of this in action:
Now that we know the values returned for each button, we can take advantage of them to create, for example, a type of menu system – or some sort of controller. In the second example, we have used a modified TwentyTen with a DS1307 real-time clock IC to make a digital clock. The buttons on the LCD shield are utilised to create a user-friendly menu to set the clock time.
You can download the demonstration sketch from here.
In general this is an excellent kit, and considering the price of doing it yourself – good value as well. To get your hands on this product in kit or assembled form – visit Freetronics’ website, or your local reseller.

Remember, if you have any questions about these modules please contact Freetronics via their website.
Higher resolution images available on flickr.
Otherwise, have fun, stay safe, be good to each other – and make something! ![]()
[Note - the kit assembled in this article was received from Freetronics for review purposes]
Kit review – Sparkfun Frequency Counter kit
Hello everyone
Today we examine a kit that is simple to construct and an interesting educational tool – the Sparkfun Frequency Counter kit. This is a revised design from a kit originally released by nuxie1 (the same people who brought us the original function generator kit). As a frequency counter, it can effectively measure within the range of 1 to a claimed 6.5 MHz. Unfortunately the update speed and perhaps accuracy is limited by the speed of the microcontroller the kit is based upon – the Atmel ATmega328. Arduino fans will recognise this as the heart of many of their projects.
Interestingly enough the kit itself is a cut-down version of an Arduino Duemilanove-standard board, without the USB and power regulation hardware. The ATmega328 has the Arduino bootloader and the software (“sketch”) is open source (as is the whole kit) and easily modifiable. This means you can tinker away with your frequency counter and also use your kit as a barebones Arduino board with LCD display. More about this later.
This becomes more obvious when looking at the PCB:
It was a little disappointing to not find any power regulator or DC socket – you need to provide your own 5V supply. However Sparkfun have been “clever” enough to include a cable with JST plug and socket to allow you to feed the frequency counter from their function generator kit. In other words, buy both. Frankly they might as well just have produced a function generator with frequency counter kit all on one PCB. Anyhow, let’s get building.
The kit comes in a nice reusable stiff red cardboard box. One could probably mount the kit in this box if they felt like it. The components included are just enough to get by. The LCD is a standard 16 x 2 character HD44780-compatible display. (More on these here). It has a black on green colour scheme. You could always substitute your own if you wanted a different colour scheme:
An IC socket is not included. You will need to install one if you intend to reprogram the microcontroller with another Arduino board.
Assembly was quick and painless. I couldn’t find any actual step-by-step instructions on the internet (Sparkfun could learn a lot from adafruit in this regard) however the component values are printed on the PCB silk-screen; furthermore no mention of LCD connection, but the main PCB can serve as a ‘backpack’ and therefore the pins line up.
To make experimenting with this kit easier I soldered in some header pins to the LCD and matching socket to the main PCB; as well as adding pins for an FTDI cable (5V) to allow reprogramming direct from the Arduino IDE:
So there are in fact two ways to reprogram the microcontroller – either pull it out and insert into another Arduino board, or do it in-place with a 5V FTDI cable. Either way should be accessible for most enthusiasts. At this point one can put the screen and LCD together and have a test run. Find a nice smooth 5V DC power source (from an existing Arduino is fine), or perhaps plug it into USB via a 5V FTDI cable – and fire it up:
Well, that’s a start. The backlight is on and someone is home. The next step is to get some sort of idea of the measurement range, and compare the accuracy of the completed kit against that of a more professional frequency counter. For this exercise you can observer the kit and my Tek CFC-250 frequency counter measuring the same function generator output:
As you can see the update speed isn’t that lively, and there are some discrepancies as the frequencies move upward into the kHz range. Perhaps this would be an example of the limitations caused by the CPU speed. Next on the to-do list was to make the suggested connection between the function generator kit and the frequency counter. This is quite simple, you can solder the included JST socket into the function generator board, and solder the wires of the lead included with the frequency counter as such:
When doing so, be sure to take notice about which PCB hole is connected to which hole, the colours of the wire don’t match the assumed description on the function generator PCB. Furthermore, the voltage applied via the WAVE pin (the frequency source) should not fall outside of 0~+5V.
As mentioned earlier, this kit is basically a minimalist Arduino board, and this gives the user some scope with regards to modification of the software/sketch. Furthermore, the kit has been released under a Creative Commons by-sa license. So you can download the schematic, Arduino sketch and EAGLE files and create your own versions or updates. If doing so, don’t forget to attribute when necessary.
Overall, this was anther interesting and easy kit to assemble. It is ideal for beginners as there isn’t that much soldering, they end up with something relatively useful, and if you have a standard Arduino Uno or similar board you can upgrade the firmware yourself.
However as a standalone frequency counter, perhaps not the best choice. Think of this kit as an educational tool – involving soldering, Arduino programming and learning how frequency counters work. In this regard, the kit is well suited.
You can purchase the kit directly 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 Google Group.
High resolution images are available on flickr.
[Note - The kit was purchased by myself personally and reviewed without notifying the manufacturer or retailer]
Otherwise, have fun, be good to each other – and make something! ![]()
Tutorial: Using analog input for multiple buttons
This is chapter twenty-five of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe.
The first chapter is here, the complete series is detailed here. Please note from November 1, 2010 files from tutorials will be found here.
[Updated 14/03/2013]
The purpose of this article is demonstrate how you can read many push buttons (used for user-input) using only one analog input pin. This will allow you to save digital I/O pins for other uses such as LCD modules and so on. Hopefully you recall how we used analogRead() in chapter one, and how we used a potentiometer to control menu options in exercise 10.1. For this article, we will be looking at reading individual presses, not simultaneous (i.e. detecting multiple button presses).
To recap, an analog input pin is connected to an analog to digital (ADC) converter in our Arduino’s microcontroller. It has a ten bit resolution, and can return a numerical value between 0 and 1023 which relates to an analog voltage being read of between 0 and 5 volts DC.
With this sketch:
/* Example 25.1 - Demonstrating analogRead()
http://tronixstuff.com/tutorials > chapter 25
CC by-sa-nc*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 2, 3);
int a=0;
void setup()
{
lcd.begin(20, 4);
pinMode(A5, INPUT_PULLUP);
}
void loop()
{
a = analogRead(5);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" analogRead() ");
lcd.setCursor(0,1);
lcd.print(" value is :");
lcd.print(a);
delay(250);
}
and in the following short video, we have demonstrated the possible values returned by measuring the voltage from the centre pin of a 10k ohm potentiometer, which is connected between 5V and GND:
As the potentiometer’s resistance decreases, the value returned by analogRead() increases. Therefore at certain resistance values, analogRead() will return certain numerical values. So, if we created a circuit with (for example) five buttons that allowed various voltages to be read by an analog pin, each voltage read would cause analogRead() to return a particular value. And thus we can read the status of a number of buttons using one analog pin.
Example 25.2
The following circuit is an example of using five buttons on one analog input, using the sketch from example 25.1:
And here it is in action:
Where is the current coming from? Using pinMode(A5, INPUT_PULLUP); turns on the internal pull-up resistor in the microcontroller, which gives us ~4.8V to use. Some of you may have notice that when the right-most button is pressed, there is a direct short between A5 and GND. When that button is depressed, the current flow is less than one milliamp due to the pull-up resistor protecting us from a short circuit. Also note that you don’t have to use A5, any analog pin is fine.
As shown in the previous video clip, the values returned by analogRead() were:
- 1023 for nothing pressed (default state)
- 454 for button one
- 382 for button two
- 291 for button three
- 168 for button four
- 0 for button five
So for our sketches to react to the various button presses, they need to make decisions based on the value returned by analogRead(). Keeping all the resistors at the same value gives us a pretty fair spread between values, however the values can change slightly due to the tolerance of resistors and parasitic resistance in the circuit.
So after making a prototype circuit, you should determine the values for each button, and then have your sketch look at a range of values when reading the analog pin. Doing so becomes more important if you are producing more than one of your project, as resistors of the same value from the same batch can still vary slightly.
Using the circuit from example 25.2, we will use a function to read the buttons and return the button number for the sketch to act upon.
/* Example 25.3 - Digital buttons with analog input
http://tronixstuff.com/tutorials > chapter 25 CC by-sa-nc */
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 2, 3);
int a=0;
void setup()
{
lcd.begin(20, 4);
pinMode(A5, INPUT_PULLUP); // sets analog pin for input
}
int readButtons(int pin)
// returns the button number pressed, or zero for none pressed
// int pin is the analog pin number to read
{
int b,c = 0;
c=analogRead(pin); // get the analog value if (c>1000)
{
b=0; // buttons have not been pressed
} else
if (c>440 && c<470)
{
b=1; // button 1 pressed
} else
if (c<400 && c>370)
{
b=2; // button 2 pressed
} else
if (c>280 && c<310)
{
b=3; // button 3 pressed
} else
if (c>150 && c<180)
{
b=4; // button 4 pressed
} else
if (c<20)
{
b=5; // button 5 pressed
}
return b;
}
void loop()
{
a=readButtons(5);
lcd.clear();
if (a==0) // no buttons pressed
{
lcd.setCursor(0,1);
lcd.print("Press a button");
} else
if (a>0) // someone pressed a button!
{
lcd.setCursor(0,2);
lcd.print("Pressed button ");
lcd.print(a);
}
delay(1000); // give the human time to read LCD }
And now our video demonstration:
So now you have a useful method for receiving input via buttons without wasting many digital input pins. I hope you found this article useful or at least interesting.
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.
Initial review: mbed LPC1768 Development Board
In this article we review the mbed NXP LPC1768 development board and the mbed system in general.
Introduction
Today we will examine the mbed NXP LPC1768 development board. The goal of the mbed system is to “provide(s) a platform for microcontroller hardware, tools, libraries and resources designed to enable rapid prototyping with microcontrollers.” (http://mbed.org/handbook/About). Personally I also see this as a good option for a “next step” for those who have outgrown their Arduino – the mbed offers much more processing power, a similar development environment and similar hardware ease of use. A great way to move from 8-bit to 32-bit power…
The NXP LCP1768 MCU on our mbed board offers the following specifications:
- a Cortex-M3 core running at 96MHz
- 512kb flash memory and 64kb RAM
- powered via USB or 4.5~9V DC applied straight to the board
- Real time clock (requires external battery backup if necessary)
- Loads of I/O options, including:
- USB serial
- I2C
- Ethernet on board
- SPI
- serial I/O
- Control-area network (CAN) bus
- 3.3v digital logic, 40mA per digital pin with a total maximum of 400 mA
- analog and digital I/O pins
For a full description and data sheet, please visit: http://mbed.org/handbook/mbed-NXP-LPC1768.
Although a small project started by two ARM employees, the mbed has proven to be a worthy product to allow people of generally all skill levels access to powerful microcontrollers without a lot of the inherent complications. It does this in two ways:
Firstly, the hardware is very simple and designed for ease of use. The LPC1768 is mounted on a small board to convert it to a DIP format, making breadboard easy. The designers have also thought to include four blue LEDs for digital output and a nice large reset button. Interface with the PC is via USB. The mbed appears as a USB flash drive to your computer’s operating system, and compiled programs are downloaded as a single .bin file into the mbed.
Secondly, the development environment. Unlike other MCU products on the market, mbed is a completely online development environment. That is, in a manner very similar to cloud computing services such as Google Docs or Zoho Office. However there are some pros and cons of this method. The pros include not having to install any software on the PC – as long as you have a web browser and a USB port you should be fine; any new libraries or IDE updates are handled on the server leaving you to not worry about staying up to date; and the online environment can monitor and update your MCU firmware if necessary. However the cons are that you cannot work with your code off-line, and there may be some possible privacy issues. We will examine the online environment later on.
Preparing and using the mbed is incredibly simple. The designers have certainly exceeded their goal of providing a rapid prototyping environment. The process from opening the box to running your first program is (as always) quite simple.
The initial packaging is clear and inviting, and includes a getting started document, USB cable, a laminated hardware pinout card (very useful) and a bumper sticker (!):
The mbed unit itself is compact yet not too small:
The underside contains the USB interface and flash drive controllers:
The initial setup requires registration with the mbed online environment. This is done by plugging in your mbed to the USB, and visiting the web page URL stored in the mbed’s flash drive:
This will take you to the login page where you can create a new user profile:
The serial number of the mbed is recognised and linked to your user account. This means you do need to own an mbed to explore the depths of the online services available, and also serves to keep the mbed online ecosystem free of spammers and whatnot. After registration, you will be presented with the “getting started” page, which contains links to the function references, tutorials, FAQs, user forums, user-contributed content and more. All is revealed by exploring the links from this page.
After signing up, you can create a profile page which is public. This also contains tabs that contain notes, published (programs you make public) and libraries (that you have made public) Initially I thought the profile page would be private, or limited to other mbed owners, but this is not the case. From this page you can create notebook files, view your past activity and display published programs and libraries. For example, I created a test notebook page and someone left a comment on it twenty minutes later. So be careful if you have some secrets – instead, you could cut and paste work to and from the IDE. However if you accidentally publish something it can be deleted, but remember that the internet is written in ink, not pencil.
However don’t let privacy worries put you off – just be careful not to write anything or publish programs you want to keep secret. Furthermore, as said earlier – having an online IDE has a few advantages – you don’t need to install anything on your PC apart from an up to date web browser. This means you can work on programs from other computers with ease. Bored at work? Using a locked-down hotel or school computer? You can still work on your mbed programs!
The openness of the mbed environment does create a positive, helpful environment similar to that found in the open-source community – there are many libraries that have been submitted that allow connection to various pieces of hardware such as LCD screens, bluetooth, Wii controllers, motors, servos, sensors and so on – as well as libraries for pachube, twitter, HTTP client and server access, and much more. These are found in the environment’s “Cookbook” section. If something interesting is on the market, there may very well be an mbed library to work with it.
The IDE is quite clear and straightforward. The program editor maintains colour-context, line numbering, support auto-formatting, and you can import or export code using the standard copy and paste keyboard shortcuts.
You can have multiple folders open at once, where each folder contains one program, the standard mbed function library and others you may have imported. Furthermore, there is also a very clear function reference for the standard mbed library available within the IDE – very useful. Programs are written in C++, and the online IDE takes care of everything – leaving you with only the .bin file to upload to the mbed. If you are new to programming or a little rusty with C++, books with unfortunate titles such as “C++ for Dummies” may prove useful.
You can also import libraries published by other mbed users into your own projects. Details of these published libraries (and programs) are listed in the mbed online environment. The speed of development is demonstrated very well in this video from the mbed team:
The support options are very good, including a members-only forum, loads of information, the Cookbook, a wiki for publishing user-contributed libraries and resources, and other FAQs and so on. If you have a question I am sure it could be answered very quickly. When it comes time to compile and run your program, after a successful compile your computer will download a single .bin file, which is then copied over to your mbed. Then by pressing the reset button on the mbed, the program is stored into the MCU and executed. You can store more than one .bin file on the mbed, however the latest file (by time stamp) is only executed.
Overall the mbed is a refreshingly-easy point of entry to microcontrollers. The ability to quickly prototype an idea into reality is really not difficult, and those with some C++ experience (or willing to learn) will make use of the mbed environment in no time at all. And if you decide to move your prototype into production, details and schematics are provided to help implement the nxp LPC1768 into your designs. Frankly, for fast prototyping at work, or just fun for anyone interested in electronics, the mbed offers a simple yet powerful way of getting things done.
The mbed board used in this review was a promotional consideration from RS. You can purchase an mbed directly from your local RS distributor.
In the meanwhile 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? 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.





































![From http://simpsons.wikia.com/wiki/User:Jihem [CC by-sa]](http://images1.wikia.nocookie.net/__cb20091128195239/simpsons/images/1/1a/AutoDialer_AT5000.jpg)





























