Posts | Comments

Planet Arduino

Archive for the ‘electronics tutorial’ Category

Hello readers

Today we continue with the second in a series of articles about the bipolar transistor. The first section is here. In this article we look at using the bipolar transistor as an amplifier. That is, change a very small alternating-current signal and make it larger, increasing the amplitude of the signal. Although originally it would seem to be rather simple, perhaps it is not. There are many, many ways to construct a transistor amplifier circuit, but I hope this introduction helps your basic understanding of the process.

When we used the transistor as a switch in part one, we were concerned about the amount of current that flowed between the base and the emitter – that it did not exceed the maximum rating for the particular transistor. When a transistor is allowing the most amount possible of current to flow, it is saturated – the point where the transistor cannot handle any more current. However, to use a transistor as an amplifier we need to bias the transistor so that it is passing current, but not saturated. The procedure of setting the output DC level is known as biasing. The procedure for biasing is outside the scope of this article, as there are many ways of constu

When selecting transistors one needs to take note of the hFE (DC current gain), as variations in this will require a complete recalculation of the values for the bias resistors. Even a common model such as the BC548 is available with hFE ranges between 110~520.

one transistor amplifier

Consider the example schematic above. The transistor is not saturated, due to the bias being set by the two 10k ohm resistors, which drops the voltage over the base by around half. In this case with our 6V supply this drops to around 3V. When power is applied, the transistor is biased and allows a small amount of current to flow, but it still has a lot more current-handling capacity. In testing this example, without an input the base current Ib is 0.32 milliamps, and the collector current Ic is 19.9 milliamps . These amounts of current are known as the quiescent current values.

The purpose of the 0.1 uF capacitor is to block DC current and only allow AC current to flow. When the AC current passes through the 0.1 uF capacitor, it is combined with the DC quiescent current running through the base and rides the stronger current out of the emitter. At which point the 100 uF capacitor before the speaker stops the DC current and only allows the AC signal through to the speaker, but amplified. The level of amplification is dependent upon the gain of the transistor, and the amount of base current. Let’s have a look at the behaviour of the current as it passes through the example circuit above:

At the end stage of the video clip we increased the input signal greatly. Did you notice the clipping at the output? This occurs when the voltage is too great for the transistor, and therefore it cannot pass the complete signal through to the emitter. In an audio signal situation, this will cause distortion. That is another reason to check the specification of the transistor against your requirements.

Moving along. You can also connect more than one transistor together to increase the amplification, for example:

two-transistor amplifier

The left half of the circuit above should be familiar. The 10uF capacitor at the bottom is to stop the DC current being passed through to the base of the BC548 transistor. The second transistor, the BC558 is a PNP transistor, and amplifies the signal at the collector of the BC548. Finally, the 1uF capacitor blocks the DC current from reaching the output. However in using two or more transistors in such a method, you need to ensure the emitter current rating of the second transistor is much higher, as the gain of two transistors is the product of the individual transistors’ gain.

Question – Who makes the BC547 transistors sold by Little Bird Electronics?

As stated at the beginning, this is only an introduction. There are literally hundreds of thousands of pages of material written about the use of transistors, so don’t stop here – experiment and do your own research and learning!

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.

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



Hello readers

Today we are going to examine the 74HC238 decoder/demultiplexer IC. My reason for writing this was to examine another way to get more output pins when using an Arduino or compatible board. However you can use any combination of three logic lines to turn on or off eight mutually exclusive outputs. How? Let’s find out…

First of all, here is the IC:

It is also available in SO16, SSOP16,  TSSOP16 and DHVQFN16 packages. What? Here is a good list of various SMD packaging types. Although my sample is from NXP, a quick search shows it is also made by Texas Instruments and ST Microelectronics. Here is the NXP data sheet.

The pin layout is very simple, apart from +5V and ground, you have six pins that control the outputs, and eight output pins, however in reality you only need to control three from the microcontroller or other logic lines. Here is the pinout diagram:

To get the output pins high, you use a combination of levels on pins A0~A2 and possibly E3. If you leave E3 low, no outputs can be set to high. The input combination required for each output is described in this table from the data sheet (click to enlarge):

Notice that columns with an X can be set either high or low, but you must not leave them floating, so always connect or set an X to high or low. If you need to have active low outputs (that is, outputs are high instead of low), there is the 74HC138. So now to do this in real life! Here is a demonstration schematic to use the 74HC238 with an Arduino Duemilanove or 100% compatible board:


… and in real life:

And here is a demonstration video, using this arduino sketch: 74HC238Arduino.pdf

Question: In real life, in which country is the Hoff a popular singer?

As with most other ICs of this type, you can only source 25 milliamps of current from each output, so if you need more you will have to consider the use of a switching NPN transistor etc. Although only one output can be high at a time, if you scan them quick enough, you can create the illusion that all are on at once (as in the video). Apart from LEDs and other items, you could use this IC to control stepper motors or even create a safeworking environment on a model train layout.

To conclude, the 74HC238 offers one of several ways to control more things with less control pins. Ideal for mutually exclusive outputs, however if you needed more than one high at once, the 74HC595 shift register would be the better solution. (See here for a 74HC595 tutorial).

As always, avoid the risk of counterfeit ICs and get yours from a reputable distributor. Living in Australia, mine came from Little Bird Electronics.

Once again, 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. High resolution photos are available on flickr.

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

Hello everyone

Today we are going to continue exploring alternating current, with regards to how resistors and capacitors deal with AC. This chapter is part two, chapter one is here.

To help with the explanations, remember this diagram:

That is, note that there are three possible voltage values, Vpp, Vp and Vrms. Moving on. Alternating current flows through various components just like direct current. Let’s examine some components and see.

First, the resistor. It operates in the same way with AC as it does DC, and the usual calculations apply with regards to Ohm’s law, dividing voltage and so on. However you must keep in mind the type of voltage value. For example, 10Vrms + 20Vpp does NOT equal 30 of anything. But we can work it out. 20Vpp is 10Vp,  which is 7.07Vrms… plus 10Vrms = 17.07Vrms. Therefore, 10Vrms + 20Vpp = 17.07Vrms.

Furthermore, when using Ohm’s law, or calculating power, the result of your equation must always reflect the type of voltage used in the calculations. For example:


Next, the capacitor. Capacitors oppose the flow of alternating current in an interesting way – in simple terms, the greater the frequency of the current, the less opposition to the current. However, we call this opposition reactance, which is measured in ohms. Here is the formula to calculate reactance:


the result Xc is measured in Ohms, f is frequency is Hertz, and C is capacitance in Farads. Here are two examples – note to convert the value of the capacitor back to Farads


Also consider if you have identical frequencies, a smaller capacitor will offer a higher resistance than a larger capacitor. Why is this so? A smaller capacitor will reach the peak voltages quicker as it charges in less time (as it has less capacitance); wheras a larger capacitor will take longer to charge and reach the peak voltage, therefore slowing down the current flow which in turn offers a higher reactance.

Resistors and capacitors can also work together as an AC voltage divider. Consider the following schematic:

As opposed to a DC voltage divider, R2 has been replaced with C1, the 0.1 uF capacitor. In order to calculate Vout, we will need the reactance of C1 – and subsitute that value for R2:

However, once the voltage has been divided, Vout has been transformed slightly – it is now out of phase. This means that Vout oscillates at the same frequency, but at different time intervals than Vin. The easiest way to visualise this is with an oscilloscope, which you can view below:

Please note that my CRO is not in the best condition. In the clip it was set to a time base of 2 milliseconds/division horizontal and 5 volts/division vertical.

Thus ends chapter two of our introduction to alternating current. 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! :)

Hello readers

In this article you can follow the process of making another LCD shield for the Arduino Duemilanove or compatible boards. In the past (which explains the word another in this title) I made a 16 x 2 character LCD shield, however it was not backlit, nor large enough. Recently I acquired a 20 x 4 character backlit LCD for use in my Arduino tutorials, therein making this project necessary. To refresh your memories, here is the original shield:

However this time, I cannot mount the display on the shield, it is just too large. Furthermore, it is preferable to be able to stack other shields on top of the new LCD shield. Therefore the display will be external and connected with lengths of wire. So time to get cracking. The first step was to assemble all the parts together. The new LCD has a standard 16-pin  HD44780 interface, and is very easy to connect:

What we have: one 20×4 character backlit LCD, a Freetronics basic protoshield, some stacking pin headers, a button, 10k ohm trimpot for contrast adjustment, and some spacers and matching screws to give the LCD some legs. Afterwards I got some 0.1uF ceramic capacitors as well, to smooth supply current on the 5V rail of the shield. Here is the data sheet for the LCD: 2004 LCD.pdf.

As usual the first thing to do was to make a plan. The LCD interface is easy enough, but I still like to have something on paper to refer to:

The next step is to breadboard it – to make sure it works. However I did solder in the wires to the LCD at this stage:

And after assembling the circuit, a brief test:

Success. The demonstration sketch is the example provided with the Arduino IDE, modified for a 20×04 LCD – 2004LCDdemo.pdf. During the test above, I used an external 5V power supply for the breadboard. Remember to connect the ground line from the Arduino to the ground line of your breadboard, otherwise it will not work. At this point I was wondering how much current the LCD used by itself. The data sheet claimed it was five milliamps… I think not. Mr Multimeter had a different opinion:

Now it was time to finish the soldering work. Instead of trying to jam all the wires together along the digital pins, I used some wire jumpers to spread out the landing points for the wires from the LCD.

Furthermore, I decided to install a power LED and 560 ohm resistor – you can never have too many LEDs. :) The rear of the protoshield was also quite neat, dollops of solder easily bridged pads when required. Then after a visual inspection it was time to solder in the header pins. The easiest way to do this is to use an existing shield:

After soldering in the pins, the first attempt of using the display was unsuccessful. I had confused a couple of wires, but some reprogramming of the sketch fixed that. (It was Saturday night and my eyes were tired). But once the error had been fixed – success!

If this shield/display needed a name, I would call it the Dog’s breakfast. Now, hardware is only half of the solution – there are one or two things to take into account when writing your sketch. If you do not have the latest version of the Arduino IDE (v18), upgrade so you will have the new LiquidCrystal library. Also, when using .setCursor(x,y); to position the cursor, the top left position on the LCD is 0,0; and the bottom right is 19,3. For example, the image below was created by:

lcd.setCursor(0, 0);
lcd.print("A");
lcd.setCursor(1,1);
lcd.print("B");
lcd.setCursor(2,2);
lcd.print("C");
lcd.setCursor(3,3);
lcd.print("D");

Now to make something slightly more useful to take advantage of the screen area – another clock! (I like clocks) using my DS1307 real time clock shield. Here is the sketch: worldclock.pdf, (doesn’t allow for DST) and an action shot:

Question – from which organisation did my LCD module come from? :)

So there you have it. Another way to use an LCD with an Arduino, and show how you can do things yourself.

If you have any questions at all please leave a comment (below). We also have a Google Group dedicated to the projects and related items on the website – please sign up, it’s free and we can all learn something. High resolution photos are available from flickr. This article is a guide – always check your own work before committing to construction.

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


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 complete series is detailed here.

Welcome back fellow arduidans!

This chapter we will spend some more time with the rotary encoder by using it to control a clock, look at ways of driving a common-anode LED display with Arduino, and make a usable alarm clock with which we can start to move from the prototype stage to an actual finished product – something you would be proud to give to someone.

So off we go…

In chapter eleven, we looked at getting some values from the rotary encoder. Not the easiest way of receiving user input, but certainly interesting. This week I have an example for you where the encoder is used for setting the time of a digital clock.

Example 12.1

This example is basically two previous projects mashed together. It consists of the LED digital clock from exercise 7.1, and the rotary encoder sketch from example 11.2. The sketch was quite simple in theory, but somewhat complex in execution. The idea was to read the decoder, and after every read, display the time. However, if the encoder’s button was pressed, the time set function would be activated. At this point, you turn the encoder in one direction to set the hours, and the other direction to set the minutes. Then press the button again to set that time and return to normal operations.

To recreate it you will need:

  • Your standard Arduino setup (computer, cable, Duemilanove or 100% compatible)
  • Seven 560 ohm 1/4 watt resistors
  • Four 1 kilo ohm 1/4 resistors
  • Four BC548 NPN transistors (if you cannot find these, you can use 2N3904)
  • Two 74HC595 shift registers
  • DS1307 timer IC circuit components (see this schematic from chapter seven) or a pre-built module
  • Solderless breadboard and connecting wires

Here is the sketch for your perusal: example 12.1.pdf, and the matching schematic (sorry, I forgot to add the DS1307 module – see example 12.2 schematic below for how to do this):

… in real life:

and a video clip:

After watching that clip you can soon see that there is an issue with the encoder. As a normal switch can bounce (turn on and off very very quickly in the latter part of operation), so can a rotary encoder. That is why it would sometimes return a result of clockwise, instead of anti-clockwise. Furthermore, they are right little pains when trying to use in a breadboard, so if you were going to use one in greater lengths, it would pay to make up your own little breakout board for it. Therefore at this stage we will leave the encoder for a while.

You may also have noticed the extra shield between the real time clock shield (yellow) and the TwentyTen arduino board. It is the Screwshield for Arduino – reviewed here. It is very useful to making a stronger connection to the I/O pins, or using normal multi-core wires.

Next on the agenda is the common-anode LED display. Normally the LED display we have demonstrated in the past has been common-cathode, and very easy to use. Current would flow from the power supply, through the shift register’s outputs (for example the 74HC595), through current-limiting resistors, into the LED segment, then off to earth via the cathode. Current flows through a diode from the anode to the cathode, and finally back to earth/ground. For a refresher on diodes, please read this article.

The other month I found this useful LED display:

Absolutely perfect for our clock experimentations. A nice colon in the middle, and another LED between the third and fourth digit which could make a good indicator of some sort. However the one catch (always a catch…) is that is was common-anode. This means that current starts from the power supply, through the common anode pin for the particular digit, then the LED segment, the LED’s individual cathode pin, through the current-limiting resistor and then to ground. With the current flowing in the opposite direction via a common anode, we can’t just hook the display up to our 74HC595 shift register.

Therefore, we will need the shift register to control switches to allow the current to flow through each segment, just like we have done previously controlling the cathodes of a common cathode display (see example 12.1). So to control the digits of this new display, we will need twelve switches (eight for the segments of the digit, and four to control the anodes). That would mean twelve BC548  transistors and 10k ohm resistors, and a lot of mess.

Example 12.2

Instead we will now use the 74HC4066 quad bilateral switch IC. I have reviewed this chip being used with Arduinos in a separate article here. The 74HC4066 is quite a common chip, available from many suppliers including: Farnell/Newark (part number 380957), Digikey (part number 568-1463-5-ND) or Mouser (771-74HC4066N). If you cannot find them, email me and I can sell you some at cost plus postage. Once you have a understanding of this IC, please consider the following circuit:


Most of this should be easily understood. One shift register is controlling the anodes, turning them on and off via a 74HC4066. In past examples this shift register would have turned off common cathodes via a 10k resistor and an NPN transistor. The other shift register is controlling the individual LEDs for each digit via a pair of 74HC4066s (as they only have four switches per IC).

Here is the sketch, this should be quite a familiar piece of code for you by now: example 12.2.pdf.

To recreate it you will need:

  • Your standard Arduino setup (computer, cable, Duemilanove or 100% compatible)
  • Seven 560 ohm 1/4 watt resistors
  • DS1307 timer IC circuit components (see this schematic from chapter seven) or a pre-built module
  • Two 74HC595 shift registers
  • Three 74HC4066 quad bilateral switch ICs
  • Solderless breadboard and connecting wires
  • LED clock display module

And here is the result, with red and a blue display.

And the usual board layout:

QuestionDo you think the time shown on the display was correct when I took the photo? :) Personally the blue looks really good in a dark background. You can also get them in yellow and green.

Moving along. Now and again, you often want to have a few buttons in use for user input, however the cheap ones don’t really like to sit in a breadboard. Naturally, you could make your own “button shield”, which would be very admirable, but then it would be preset to certain pins, which could interfere with your project. I had the same problem in writing this chapter, so came up with this example of an external “button panel” to make life easier.

Example 12.3

Here is the schematic, nothing complex at all – just four buttons and the required 10k ohm pull-down resistors:

and the finished product:

This was a quick job, as I will need to use a few buttons in the near future. Have also put some rubber feet on the bottom to stop the solder joints scratching the surface of the bench. Originally I was going to chop off the excess board at the top, but instead will add some LEDs to it after finishing this article. However using this button board will save a lot of frustration by not trying to jam the buttons into a breadboard.

Exercise 12.1

Now it is time for you to do some work. From this chapter onwards, we will be working on making a small alarm clock – something you could use. Just like the six million dollar man, we have the capability, the technology, and so on … except for Steve Austin. So this chapter, your task is to create and breadboard the  circuit and the underlying sketch. Using the LED display from example 12.1, your clock will have a menu option to set the time, alarm time, turn on and off the alarm, a snooze button – and also switch the display on and off (so you don’t stare at it when you should be trying to sleep).

You could either use a DS1307 module, or the raw parts. For an explanation of the circuitry, please see this post about making a RTC shield. You can always change it when we get to making a real prototype. The same with the Arduino – but for this exercise just stick with the normal board. Later on we will use a bare circuit the same as in chapter ten. With regards to user input, it’s up to you. A rotary encoder could be a real PITA, my example below just uses buttons. Anyhow, off you go!

Parts you will need:

  • Your standard Arduino setup (computer, cable, Duemilanove or 100% compatible)
  • Seven 560 ohm 1/4 watt resistors
  • DS1307 timer IC circuit components (see this schematic from chapter seven) or a pre-built module
  • Two 74HC595 shift registers
  • Three 74HC4066 quad bilateral switch ICs
  • Four normally open buttons or a board as described in example 12.3
  • Solderless breadboard and connecting wires
  • LED clock display module

Here is my interpretation of the answer to the exercise, the sketch: exercise 12.1.pdf. Although this is a particularly long sketch for our examples, it is broken up into many functions which are quite modular, so you can easily follow the flow of the sketch if you start at void loop(). All of the types of functions used have been covered in the past tutorials. In then next chapters we will add more functions, such an an adjustable snooze, selectable blinking colon, and so on. If you have any questions, please ask.

The buttons have several functions. In normal clock display mode, button one is for menu, two turns the alarm on, three turns it off, and four turns the display on and off. If you press menu, button two is to select time set, three for alarm set, and four is like an enter button. When in the time/alarm set modes, button one increases the hour, button two increases minutes in units of ten, and button three increases minutes in ones, and four is enter. When the alarm activates, button four turns it off.

The schematic is just example 12.2 and example 12.3 connected together, however the first button on the external board is connected to digital pin 8 instead of 1.

So here is a photo of our work in progress:

And a video clip showing the various functions of the clock in operation:


Well that is another chapter over. However, as usual I’m already excited about writing the next instalment… Congratulations to all those who took part and built something useful!

Please subscribe (see the top right of this page) to receive notifications of new articles. High resolution photos are available from flickr.

If you have any questions at all please leave a comment (below). We also have a Google Group dedicated to the projects and related items on the website – please sign up, it’s free and we can all learn something. If you would like to showcase your work from this article, email a picture or a link to john at tronixstuff dot com. You might even win a prize!

Don’t forget to check out the range of gear at Little Bird Electronics!

So have fun, stay safe and see you soon for our next instalment, hopefully by 23rd July 2010.

Hello everyone!

Today we are going to introduce the basics of AC – alternating current. This is necessary in order to understand future articles, and also to explain in layperson’s terms what AC is all about. So let’s go!

AC – Alternating Current. We see those two letters all around us. But what is alternating current? How does current alternate? We know that DC (direct current) is the result of a chemical reaction of some sort – for example in a battery, or from a solar cell. We know that it can travel in either direction, and we have made use of it in our experimenting. DC voltage does not alter (unless we want it to).

Therein lies the basic difference – and why alternating current is what is is – it alternates! :) This is due to the way AC current is created, usually by a generator of some sort. In simple terms a generator can be thought of as containing a rotating coil of wire between two magnets. When a coil passes a magnet, a current is induced by the magnetic field. So when the coil rotates, a current is induced, and the resulting voltage is relative to the coil’s positioning with the magnets.

For example, consider the diagram below (exploded view, it is normally more compact):

This is a very basic generator. A rotating coil of wire is between two magnets. The spacing of the magnets in real life is much closer. So as the coil rotates, the magnetic fields induce a current through the coil, which is our alternating current. But as the coil rotates around and around, the level of voltage is relative to the distance between the coil and the magnet. The voltage increases from zero, then decreases, then increases… as the coil constantly rotates. If you were to graph the voltage level (y-axis) against time (x-axis), it would look something like below:

That graph is a sine wave… and is a representation of perfect AC current. If you were to graph DC voltage against time, it would be a straight horizontal line. For example, compare the two images below, 2 volts DC and AC, shown on an oscilloscope:

2 volts DC

The following clip is 2 volts AC, as shown on the oscilloscope:

So as you can see, AC is not a negative and positive current like DC, it swings between negative and positive very quickly. So how do you take the voltage measurement? Consider the following:

The zero-axis is the point of reference with regards to voltage. That is, it is the point of zero volts. In the oscilloscope video above, the maximum and minimum was 2 volts. Therefore we would say it was 2 volts peak, or 2Vp. It could also be referred to as 4 volts peak to peak, or 4Vpp – as there is a four volt spread between the maximum and minimum values of the sine wave. There is another measurement in the diagram above – Vrms, or volts root mean squared. The Vrms value is the amount of AC that can do the same amount of work as the equivalent DC voltage. Vrms = 0.707 x Vp; and Vp = 1.41 * Vrms. Voltages of power outlets are rated at Vrms instead of peak as this is relative to calculations. For example, in Australia we have 240 volts:

DO NOT do this

Well, close enough. In fact, our electricity distributor says we can have a tolerance of +/- 10%… some rural households can have around 260 volts. Moving on…

The final parameter of AC is the frequency, or how many times per second the voltage changes from zero to each peak then back to zero. That is the time for one complete cycle. The number of times this happens per second is the frequency, and is measured in Hertz (Hz). The most common frequency you will hear about is your domestic supply frequency. Australia is 50 Hz, the US is 60 Hz, etc. In areas that have a frequency of 60 Hz, accurate mains-powered time pieces can be used, as the seconds hand or counter can be driven from the frequency of the AC current.

The higher the frequency, the shorter the period of time taken by one cycle. The frequency and time are inversely proportional, so frequency = 1/time; and time – 1/frequency. For example, if your domestic supply is 50 Hz, the time for each cycle is 1/50 = 0.02 seconds. This change can be demonstrated quite well on an oscilloscope, for example:

In the video above there is 2 volts AC, and the frequency starts from 100 Hz, then moves around the range of 10 to 200 Hz. As you can see, the amplitude of the sine wave does not change (the height, which indicates the voltage) but the time period does alter, indicating the frequency is changing. And here is the opposite:

This video is a demonstration of changing the voltage, whilst maintaining a fixed frequency.

Thus ends the introduction to alternating current. In the next instalment about AC we will look at how AC works in electronic circuits, and how it is handled by various components.

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.

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



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

Welcome back fellow arduidans!

Finally it is wireless week here in the tiny tronixstuff lab, as we will start to investigate radio data transmission; then followed by starting to make sense of rotary encoders.

So let’s go!

As technology has marched along and generally improved on the past, things have been getting small and relatively cheaper. What was once jaw-droppingly amazing is now just meh. But as you are reading this, you know differently. We can now take control of this technology for our own devices. What has been in the past quite unapproachable is now relatively – the concept of wireless data transmission. But no just sending a signal, like a remote-control garage door opener – but sending actual,  useful data – numbers and characters and so on.

How is it so? With this pair of tiny devices:

Quite small indeed – the pins are spaced 2.54mm apart, and the graph paper is 5mm square. The transmitter is on the right. This pair operates at 315 kHz, over up to a theoretical 150 metres. The data transmission speed is 2400 bps (bits per second). These units are serial passthrough, that is they can replace a link of wire between the serial TX (pin 1) from one Arduino, and the RX of another Arduino (pin 0). They don’t need aerials for very short distances, but the use of one will extend the range towards the maximum. And finally, the transmitter needs between 2 and 10 volts; the receiver 5. Here is the data sheet for these modules: 315MHz.pdf. Normally they are sold individually, for example the transmitter and receiver. You can also find faster (data speed) modules, however we will use these ones today.

In preparation to use these modules, another library needs to be installed – the VirtualWire library. Download the latest revision from the following location: http://www.open.com.au/mikem/arduino/.

There is also a guide to using the library in .pdf format as well. Please note the library author’s instructions with regards to licensing on the last page of the guide. For a refresher on how to install a library, please head back to chapter two. This library will save us a lot of time, it takes care of checking for errors, and only allows complete, correct data (i.e. what is received matches what is sent) to be used in the receiver’s sketch. However, as wireless is not 100% reliable, you need to take into account that transmissions may not be received, or erroneous ones will be ignored by the receiver’s sketch. You can reduce the data speed to improve reliability and range.

Therefore if you are using this for some important communications, have the transmitter repeatedly sent the message. Later on in this series we will investigate more powerful solutions. Anyhow, moving along …

Example 11.1

First of all, we will demonstrate the use of these modules with a basic sketch. It sends some text from one Arduino to another. The receiving Arduino sends the data to the serial monitor box. Of course you could always use an LCD module instead. In my own inimitable style the sketches are very simple, yet allow you to use their contents in your own work. Here is the sketch for the transmitter – tx.pdf and the receiver – rx.pdf.

When working with two sketches at the same time, you can have two Arduinos connected to your PC simultaneously,  just remember to select the correct USB port for the correct Arduino. Do this with the tools > serial port menu option in the IDE. Otherwise you will become very frustrated if you upload the rx sketch to the tx Arduino. :) Furthermore, you will need to remove the wire from digital 0 to the data pin on the receiving units before uploading the sketch. And finally, remember to set the serial monitor window at 9600 baud. Now I can laugh, but earlier I kept setting it to 2400 as that number was in my mind from the sketch.

Here are my two boards in action:

Although having both boards connected to the one computer is only useful for demonstration purposes, in real life this is obviously useless. Remember that once you upload your sketch the Arduino doesn’t need a computer, only a power supply. You can feed yours between 7 and 12 volts DC through the socket. A nice switchmode power pack will do nicely, or if you are a cheapskate like me, a PP3 battery and clip soldered to a DC plug:

You may find that when you use a battery powered Arduino that it basically does not work. Arduino genius Jon Oxer (co-author of Practical Arduino) has found a solution for this issue – place a 10k resistor between GND and digital 0 (RX), or between digital pins 0 and 1. The next thing to consider it improving the reception range. This can be done using two methods – the first by connecting an external antenna, either a length of wire, or perhaps a purpose-built aerial. The second method is to increase the supply voltage of the transmitter up to 12 volts.

Now it is your time to do some work:

Exercise 11.1

You now are able to send characters using the radio link from one Arduino to another. Now it is time to control things remotely. For the purpose of the exercise, we will just control three LEDs, turning them on and off. You already know how to control other things with digital output pins, so we just need to focus on getting the switching on and off. Hint – you can send characters via the wireless link, so create your own codes.

You will need:

Here is the schematic of my interpretation:


… the transmitter:

… the receiver:

and the video:

So how did you go? Hopefully this exercise was easier than you had first expected. If not, here are the example sketches: exercise 11.1 tx.pdf and exercise 11.1 rx.pdf. A basic transmit/receive system like this would also be handy for testing the range that wireless modules can operate over, or testing a particular site to see if you could implement such wireless modules. It’s always better to test before agreeing to make something for someone.

If you are having trouble understanding the sketches, please feel free to ask for help via email, leaving a comment, or asking the question in our Google Group.

That concludes our work with radio wireless links – for now.

Next on the agenda is the rotary encoder. Recall how we used a potentiometer in the previous chapters as a dial, to select menu options using the readdial() function. It was simple, cheap and it worked, but some may say it was a kludge. There must be a better way! And there is, with the rotary encoder. A rotary encoder looks like a potentiometer, but it is a knob that can be rotated in either direction infinitely. Furthermore, the knob is also a normally-open button. The encoder we will be using in this chapter is a 12-step encoder, in that you can feel it physically resist rotation slightly twelve times over the 360 degrees of rotation.

Here is our example:

On one side there are three pins, and two on the opposing side. On the perpendicular sides are legs for strength, that is they are meant to be soldered into a PCB to lock it in nicely. The problem for us is that those legs interfere when trying to use the encoder in a breadboard, so I have bent them up and cut them off:

The pins are easy to understand. The two pins on one side are the button contacts, just like any simple button. The other side with the three pins – the centre goes to ground, and the outside pins are the forwards and backwards output pins. The data sheet for our encoder is here. After fooling about with this all afternoon, the quickest way to get a feel for how it works is with a simple demonstration. So first we will test it out, then see how we can use it in our user-interfaces.

Example 11.2

This example is very easy to assemble. You only need an encoder, and the usual Arduino setup. Here is the sketch: example 11.2.pdf; and the schematic:

and in real life:

and finally a snapshot of the output. Don’t forget to set the speed in your serial monitor box to 115200 baud:

So as you can see, this is a much better solution that then potentiometer that we used in the past. Plus having the button integrated in the encoder is very convenient, you can really create a user interface with only one control. In the next instalment of this series we will implement the encoder in an existing design.

At this point I would like to ask you for some feedback. Would you like shorter, weekly articles – or longer, fortnightly (every two weeks) articles? Please leave a comment with your opinion.

Subscribe (see the top right of this page) to receive notifications of new articles. High resolution photos are available from flickr.

If you have any questions at all please leave a comment (below). We also have a Google Group dedicated to the projects and related items on the website – please sign up, it’s free and we can all learn something. If you would like to showcase your work from this article, email a picture or a link to john at tronixstuff dot com. You might even win a prize!

Don’t forget to check out the range of gear at Little Bird Electronics!

So have fun, stay safe and see you soon for our next instalment! (Hopefully the 10th of July) :)


Hello readers!

Today we are going to examine the 4541 CMOS programmable timer IC. The main function of this chip is to act as a monostable timer. You are probably thinking one of two things – “what is a monostable timer?” or “why didn’t he use a 555 timer instead?”. A monostable timer is a timer that once activated sets an output high for a specified period of time, then stops waiting to be told to start again.  If you are not up to speed on the 555, have a look at my extensive review.

Although the 555 is cheap, easy to use and makes a popular timer, I have found that trying to get an exact time interval out of it somewhat difficult due to capacitor tolerance, so after some poking around found this IC and thought “Hmm – what have we here?”. So as always, let’s say hello:

As you can see this is a 14-pin package by Texas Instruments. It is also available in various surface-mount options. It is also currently available from FairchildNXP, ON Semi, and ST Micro. Note that this is a CMOS semiconductor, and that you should practice good anti-static precautions when handling it. Futhermore, when designing it into your circuit, don’t leave any pins floating – that is not connected to +5V or ground; unless specified by the data sheet. Here is the data sheet from ON Semiconductor.

This IC is interesting in that it contains a timer that can count to one of four values: 2^8, 2^10, 2^13, and 2^16. That is: 256, 1024, 8192 and 65536. With wiring you select which value to count to, and also the action to take whilst counting and once finished. This is quite easy, by connecting various pins to either GND or +5V. The following table from the data sheet details this:

And here are the pinouts:

The speed of the counting (the frequency) is determined by a simple RC circuit. For more information on RC circuits, please visit this post. You can calculate the frequency using the following formula:

There are two external resistors used in the circuit – Rtc and Rs. Rs needs to be as close as possible to twice the value of Rtc. Try and use 1% tolerance metal-film resistors for accuracy, and a small value capacitor. Also remember to take note of the restrictions printed next to the formula above.

Before examining a demonstration circuit, I would like to show you how to calculate your timing duration. As you can see from the formula above, calculating the frequency is easy enough. Once you have a value for f, (the number of counts per second) divide this into the count value less one power you have wired the chip. That is, if you have wired the chip up for 2^16, divide your frequency into 2^15.

For example, my demonstration circuit has Rtc as 10k ohm, Ctc as 10 nF, and Rs as 20k ohm; and the chip is wired for 2^16 count. Remember to convert your values back to base units. So resistance in ohms, and capacitance in farads. Remember that 1 microfarad is 1×10-6 farads. So my frequency is:


So my timing duration will be 2^15 divided by 4347.826 Hz (result from above) which is  7.536 seconds give or take a fraction of a second. To make these calculations easier, there is a spreadsheet you can download here. For example:

Here is my demonstration monstable circuit. Once the power has been turned on the counter starts, and once finished the LED is lit. Or if the circuit already has power, the reset button SW1 is pressed to start counting. You can see that pins 12 and 13 are high to enable counting to 2^16; pin 6 is low unless the button is pressed; and pin 9 is low which keeps the LED off while counting.


And my demonstration laid out (I really do make everything I write about):

Easily done. Although this IC has been around for a long time, and many other products have superseded it, the 4541 can still be quite useful. For example, an Arduino system might need to trigger a motor, light, or something to runfor a period of time whilst doing something else. Unfortunately (thankfully?) Arduino cannot multi-task sketches, so this is where the 4541 can be useful. You only need to use a digitalWrite() to send a pulse to pin 6 of your timer circuit, and then the sketch can carry on, while the timer does its job and turns something on or off for a specified period of time.

Well I hope you found this part review interesting, and helped you think of something new to make.

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. High resolution photos are available on flickr.

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

Notes: In writing this post, I used information from NXP and On Semiconductor. Thank you.


Hello readers

Today we continue with the series of articles on basic electronics with this continuation of the article about the resistor. Part one can be found here.

With regards to this article, it is only concerned with direct current (DC) circuits.

In this chapter we will examine how two or more resistors alter the flow of current in various ways. First of all, let’s recap what we learned in the previous chapter.

Ohm’s Law – the relationship between voltage, current and resistance:

Resistors in series:


Resistors in parallel:

Dividing voltage with resistors:

However the fun doesn’t stop there. As there is a relationship between voltage, current and resistance, we can also divide current with resistors. For now we will see how this works with two resistors. Please consider the following:

There is a balance between the two resistors with regards to the amount of current each can handle. The sum of the current through both resistors is the total current flowing through the circuit (It). The greater the resistance the less current will flow, and vice versa. That is, they are inversely proportional. And if R1 = R2, I1 = I2. Therefore, I1/I2=R2/R1 – or you can re-arrange the formula to find the other variables.

Here is an example of doing just that:

Our problem here – there is 6 volts DC at half an amp running from left to right, and we want to use an indicator LED in line with the current. However the LED only needs 2 volts at 20mA. What value should the resistors be?

First of all, let’s look at R1. It needs to change 6V to 2V, and only allow 20 mA to pass. R=E/A or R= 4 volts /0.2 amps = 200 ohms.

So R1 is 200 ohms. I1 is .02 A. Now we know that the total current is equal to I1+I2, so I2 will be 0.48A. That leaves us with the known unknown R2 :)  We can re-arrange the formula R2/R1=I1/I2 to get R2 = (R1 x I1)/I2 – which gives us R2 of 8.3 ohms. Naturally this is a hypothetical, but I hope you now understand the relationship between the current through the resistors, and their actual resistance.

What we have just demonstrated in the problem above is an example of Kirchhoff’s current law (KCL). Gustav Kirchhoff was another amazing German physicist who worked on the understandings of electrical circuits amongst other things. More on GK here. His current law states that the amount of current entering a junction in a circuit must be equal to the sum of the currents leaving that junction. And not-coincidentally, there is also Kirchhoff’s voltage law (KVL) – the amount of voltage supplied to a circuit must equal the sum of the voltage drops in the circuit. These two laws also confirm one of the basic rules of physics – energy can not be created nor destroyed, only changed into different forms.

Here is a final way of wrapping up both KCL and KVL in one example:

The current through R3 is equal to I1 + I2

Therefore, using Ohm’s law, V1 = R1I1 + (R3 x (I1+I2)) and V2 = R2I2 + (R3 x (I1+I2))

So with some basic algebra you can determine various unknowns. If algebra is your unknown, here is a page of links to free mathematics books, or have a poke around BetterWorldBooks.

There is also another way of finding the currents and voltages in a circuit with two or more sources of supply – the Superposition Theorem.

This involves removing all the sources of power (except for one) at a time, then using the rules of series and parallel resistors to calculate the current and voltage drops across the other components in the circuit. Then once you have all the values calculated with respect to each power source, you superimpose them (by adding them together algebraically) to find the voltages and currents when all the power sources are active. It sounds complex, but when you follow this example below, you will find it is quite simple. And a lot easier the th.. fourth time.  Just be methodical and take care with your notes and calculations. So let’s go!

Consider this circuit:

With the Superposition theorem we can determine the current flowing through the resistors, the voltage drops across them, and the direction in which the current flows. With our example circuit, the first thing to do is replace the 7V power source with a link:

Next, we can determine the current values. We can use Ohm’s law for this. What we have is one power source, and R1 which is in series with R2/R3 (two parallel resistors). The total current in the circuit runs through R1, so calculate this first. It may help to think of the resistors in this way:

Then the formula for Rt is simple (above), and Rt is And now that we have a value for Rt, and the voltage (28V) the current is simple:

Which gives us a value of 6 amps for It. This current flows through R1, so the current for R1 is also 6 amps.

Next, the current through R2:

Using Kirchhoff’s Current Law, the current flowing through R2 and R2 will equal It. So, this is 4 amps.

At this point, note down what we know so far:

For source voltage 28V, Ir1 = 6A, Ir2 = 2A and Ir3 = 4A; R1=4 ohms, R2 = 2 ohms, R3 = 1 ohm.

Now – repeat the process by removing the 28V source and returning the 7V source, that is:

The total resistance Rt:

Gives us Rt = 2.3333 ohms (or 2 1/3);

Total current It will be 7 volts/Rt = 3 amps, so Ir3 = 3;

So Ir2 = 2A – therefore using KCL Ir1 = 3-2 = 1A.

So, with 7V source: Ir1 = 1A, Ir2 = 2A and Ir3 = 3A.

Next, we calculate the voltage drop across each resistor, again by using only one voltage source at a time. Using Ohm’s law, voltage = current x resistance.

For 28V:

Vr1 = 4 x 6 = 24V; Vr2 = 2 x 2 = 4V; Vr3 = 4 x 1 = 4V. Recall that R2 and R3 are in parallel, so the total voltage drop (24 + 4V) = 28 V which is the supply voltage.

Now, for 7V:

Vr1 = 4V, Vr2 = 4V, Vr3 = 3V.

Phew – almost there. Now time to superimpose all the data onto the schematic to map out the current flow and voltage drops when both power sources are in use:

Finally, we combine the voltage values together, and the current values together. If the arrow is on the left, it is positive; on the right – negative. So:

Current – Ir1 = 6 – 1 = 5A; Ir2 = 2 +2 = 4A; Ir3 = 4-3 = 1A;
Voltage – Vr1 = 24 – 4 = 20V; Vr2 = 4 + 4 = 8V; Vr3 = 4 – 3 = 1V.

And with a deep breath we can proudly show the results of the investigation:

So that is how you use the Superposition theorem. However, there are some things you must take note of:

  • the theorem only works for circuits that can be reduced to series and parallel combinations for each of the power sources
  • only works when the equations are linear (i.e. straight line results, no powers, complex numbers, etc)
  • will not work when resistance changes with temperature, current and so on
  • all components must behave the same way regardless to polarity
  • you cannot calculate power (watts) with this theorem, as it is non-linear.

Well that is enough for today. I hope you understood and can apply what we have discussed today. The final chapter on resistors can be found here.

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.

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

Notes: In writing this post, I used information from allaboutcircuits.com, plus information  from various books by Forrest Mims III and “Practical Electronics Handbook” 4th ed., Ian Sinclair. And used a lot of paper working out the theorem for myself. Thank you!


Hello readers

Today we continue down the path of analog electronics theory by stopping by for an introductory look at the RC circuit. That’s R for resistor, and C for capacitor. As we know from previous articles, resistors can resist or limit the flow of current in a circuit, and a capacitor stores electric current for use in the future. And – when used together – these two simple components can be used for many interesting applications such as timing and creating oscillators of various frequencies.

How is this so? Please consider the following simple circuit:

When the switch is in position A, current flows through R1 and into the capacitor C1 until it is fully charged. During this charging process, the voltage across the capacitor will change, starting from zero until fully charged, at which point the voltage will be the same as if the capacitor had been replaced by a break in the circuit – in this case 6V. Fair enough. But how long will the capacitor take to reach this state? Well the time taken is a function of several things – including the value of the resistor (R1) as it limits the flow of current; and the size of the capacitor – which determines how much charge can be stored.

If we know these two values, we can calculate the time constant of the circuit. The time constant is denoted by the character zeta (lower-case Greek Z).

The time constant is the time taken (in seconds) by the capacitor C that is fed from a resistor R to charge to a certain level. The capacitor will charge to 63% of the final voltage in one time constant, 85% in two time constants, and 100% in five time constants. If you graphed the % charge against time constant, the result is exponential. That is:

Now enough theory – let’s put this RC circuit to practice to see the voltage change across the capacitor as it charges. The resistor R1 will be 20k ohm, the capacitor 1000 uF.

Our time constant will be R x C which will be 20000 ohms x 0.001 farads, which equals 20 (seconds).  Notice the unit conversion – you need to go back to ohms and farads not micro-, pico- or nanofarads. So our example will take 20 seconds to reach 63% of final voltage, and 100 seconds to reach almost full voltage. This is assuming the values of the resistor and capacitor are accurate. The capacitor will have to be taken on face value as I can’t measure it with my equipment, and don’t have the data sheet to know the tolerance. The resistor measured at 19.84 k ohms, and the battery measured 6.27 volts. Therefore our real time constant should be around 19.84 seconds, give or take.

First of all, here is a shot of the little oscilloscope measuring the change in voltage over the capacitor with respect to time. The vertical scale is 1v/division:

And here is the multimeter measuring the voltage next to a stopwatch. (crude yet effective, no?)

The two videos were not the most accurate, as it was difficult to synchronise the stopwatch and start the circuit, but I hope you could see the exponential relationship between time and voltage.

What about discharging? Using the circuit above, if we moved the switch to B after charging the capacitor –  and R2 was also 20k ohm – how long would it take to discharge the capacitor? Exactly the same as charging it! So one time constant to discharge 63% and so on. So you can take the graph from above and invert it as such:

How can we make use of an RC circuit?

I’m glad you asked. Consider the following circuit:

When power is applied, the capacitor starts to charge, and in doing so allows current to flow to the emitter of the transistor, which turns on the LED. However as the capacitor charges, less current passes to the base of the transistor, eventually turning it off. Therefore you can calculate time constants and experiment to create an off timer. However, a preferable way would be to make use of a 555 timer. For example, an RC combination is used to set the pulse length used in astable timing applications, for example using R1, R2 and C1:

(For more information on the 555 timer, please read this article)

Another use of the RC circuit is oscillating. Due to varying capacitor values due to tolerance, you most likely cannot make precision frequency generators, but you can still have some fun and make useful things. Here is a classic oscillator example – an astable multivibrator:

What is going on here? Here it is in action:

and here is one side being measured on the little scope:

We have two RC circuits, each controlling a transistor. When power is applied, there is no way to determine which side will start first, as this depends on the latent charge in the capacitors and the exact values of the resistors and capacitors. So to start let’s assume the left transistor (Q1) and LED are on; and the right transistor (Q2) and LED are off. The voltage at collector of Q1 will be close to zero as it is on. And the voltage at the base of Q2 will also be close to zero as C2 will initially be discharged. But C2 will now start charging via R4 and base of Q1 to around 5.4V (remember the 0.6v loss over the base-emitter junction of a transistor). While this is happening, C1 starts charging through R2. Once the voltage difference reaches 0.6V over the capacitor, Q2 is turned on.

But when Q2 is on, the voltage at the collector drops to zero, and C2 is charged, so it pulls the voltage at the base of Q1 to -5.4v, turning it off and the left LED. C1 starts charging via R1, and C2 starts charging via R3 until it reaches 0.6v. Then Q1 turns on, bringing the base of Q2 down to -5.4V – switching it off. And the whole process repeats itself. Argh. Now you can see why Arduino is so popular.

Time for a laugh – here is the result of too much current through a trimpot:

So there you have it – the RC circuit. Part of the magic of analogue 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.

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




  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook