Tag Archive | "74HC595"

Arduino and FFD51 Incandescent Displays

In this article we examine another style of vintage display technology – the incandescent seven-segment digital display. We are using the FFD51 by the IEE company (data sheet.pdf) – dating back to the early 1970s. Here is a close-up of our example:

You can see the filaments for each of the segments, as well as the small coiled ‘decimal point’ filament at the top-right of the image above.  This model has pins in a typical DIP format, making use in a solderless breadboard or integration into a PCB very simple:

It operates in a similar manner to a normal light bulb – the filaments are in a vacuum, and when a current is applied the filament glows nicely. The benefit of using such as display is their brightness – they could be read in direct sunlight, as well as looking good inside.  At five volts each segment draws around 30mA. For demonstration purposes I have been running them at a lower voltage (3.5~4V), as they are old and I don’t want to accidentally burn out any of the elements.

Using these with an Arduino is very easy as they segments can be driven from a 74HC595 shift register using logic from Arduino digital out pins. (If you are unfamiliar with doing so, please read chapters four and five of my tutorial series). For my first round of experimenting, a solderless breadboard was used, along with the usual Freetronics board and some shift register modules:

Although the modules are larger than a DIP 74HC595, I like to use these instead. Once you solder in the header pins they are easier to insert and remove from breadboards, have the pinouts labelled clearly, are almost impossible to physically damage, have a 100nF capacitor for smoothing and a nice blue LED indicating power is applied.

Moving forward – using four shift register modules and displays, a simple four-digit circuit can be created. Note from the datasheet that all the common pins need to be connected together to GND. Otherwise you can just connect the outputs from the shift register (Q0~Q7) directly to the display’s a~dp pins.

Some of you may be thinking “Oh at 30mA a pin, you’re exceeding the limits of the 74HC595!”… well yes, we are. However after several hours they still worked fine and without any heat build-up. However if you displayed all eight segments continuously there may be some issues. So take care. As mentioned earlier we ran the displays at a lower voltage (3.5~4V) and they still displayed nicely. Furthermore at the lower voltage the entire circuit including the Arduino-compatible board used less than 730mA with all segments on –  for example:

 For the non-believers, here is the circuit in action:

Here is the Arduino sketch for the demonstration above:

Now for the prototype of something more useful – another clock. :) Time to once again pull out my Arduino-compatible board with onboard DS1307 real-time clock. For more information on the RTC IC and getting time data with an Arduino please visit chapter twenty of my tutorials. For this example we will use the first two digits for the hours, and the last two digits for minutes. The display will then rotate to showing the numerical day and month of the year – then repeat.

Operation is simple – just get the time from the DS1307, then place the four digits in an array. The elements of the array are then sent in reverse order to the shift registers. The procedure is repeated for the date. Anyhow, here is the sketch:

and the clock in action:

So there you have it – another older style of technology dragged into the 21st century. If you enjoyed this article you may also like to read about vintage HP LED displays. Once again, I hope you found this article of interest. Thanks to the Vintage Technology Association website for background information.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, electronics, ffd51, incandescent, lesson, tutorial, vintageComments (2)

Review – Freetronics Module Family

Hello

In this article we examine a new range of eleven electronic modules from Freetronics. When experimenting with electronics or working on a prototype of a design, the use of electronic components in module form can make construction easier, and also reduce the time between thoughts and actually making something :) So let’s have a look at each module in more detail…

PoE Power Regulator – 28V

This is a tiny switchmode voltage regulator with two uses – the first being regulation of higher voltage up to 28V carried via an Ethernet cable to a Freetronics Ethernet shield or EtherTen to power the board itself. The PCB is designed to drop into the shield or EtherTen as such:

… and converts the incoming voltage down to 7V which can be regulated by the EtherTen’s inbuilt regulator. The second use of this board is a very handy power supply for breadboarding or other experimentation. By bridging the solder pads on the rear of the board, the output is set to 5V DC, as such:

Note the addition of the header pins, which make insertion into a breadboard very easy – so now you have a 5V 1A DC power supply. For more information visit the product page.

N-MOSFET Driver/Output Module

This module contains an On Semi NTD5867NL MOSFET which allows the switching of a high current and voltage line – 60V at up to 20A – with a simple Arduino or other MCU digital output pin. The package is small and also contains enlarged holes for direct connection of high-current capability wire:

The onboard circuitry includes a pull-down resistor to ensure the MOSFET is off by default. For more information see the product page.

Logic Level Converter Module

This is a very simple and inexpensive method to interface 3.3V sensors to 5V microcontrollers in either direction.The module contains four independent channels, as shown in the image below:

However you can interface any low or higher voltage, as long as you connect the low and high voltages to the correct sides (marked on the PCB’s silk screen). For more information please visit the product page.

RGBLED Module

Surprisingly this module contains a RGB LED module (red, green and blue LEDs) which is controlled by a WS2801 constant-current LED driver IC. This module is only uses two digital output pins, and can be daisy-chained to control many modules with the same two pins. The connections are shown clearly on the module:

The WS2801 controller IC is on the rear:

There are several ways to control the LEDs. One way is using the sketch from the product home page, which results with the following demonstration output:

Or there is a unique Arduino WS2801 library available for download from here. Using the strandtest example included with the library results with the following:

During operation the module used less than 24 mA of current and therefore can happily run from a standard Arduino-type board without any issues. For more information please visit the product page.

TEMP Temperature Sensor Module

This module allows the simple measurement of temperature using the popular DS18B20 temperature sensor. You can measure temperatures between -55° and 125°C with an accuracy of +/- 0.5°C. Furthermore as the sensor uses the 1-wire bus, you can daisy-chain more than one sensor for multiple readings in the one application. The board is simple to use, and also contains a power-on LED:

Using the demonstation Arduino sketch from the product page results in the following output via the serial monitor:

Using this module is preferable to the popular Analog Devices TMP36, as it has an analogue output which can be interfered with, and requires an analogue input pin for each sensor, whereas this module has a digital output and as mentioned previously can be daisy-chained. For more information please visit the product page.

Humidity and Temperature Sensor Module

For the weather-measuring folk here is a module with temperatures and humidity. Using the popular DHT22 sensor module the temperature range is -4°C to +125°C with an accuracy of +/- 0.5°C, and humidity with an accuracy of between two and five percent. Only one digital input pin is required, and the board is clearly labelled:

There is also a blue power-on LED towards the top-right of the sensor. Using the module is quite simple with Arduino – download and use the example sketch included in the sensor library you can download from here. For the demonstration connect the centre data pin to Arduino digital two. Here is an example of the demonstration output:

Although the update speed is not lightning-fast, this should not be an issue unless you’re measuring real-time external temperature of your jet or rocket. For more information please see the product page.

Shift Register/Expansion Module

This board uses a 74HC595 serial-in parallel-out shift register which enables you to control eight digital outputs with only three digital pins, for example:

You can daisy-chain these modules to increase the number of digital outputs in multiples of eight, all while only using the three digital output pins on your Arduino or other microcontroller. For more information about how to use shift registers with Arduino systems, read our detailed tutorial. Otherwise for more information about the module please visit the product page.

Hall Effect Magnetic and Proximity Sensor Module

This module contains a sensor which changes output from HIGH to LOW when a magnetic presence is detected, for example a magnet. The board also has an LED which indicates the presence of the magnet to aid in troubleshooting:

Using this module and a small magnet would be an easy way to create a speedometer for a bicycle, the module is mounted to the fork, and the magnet on the rim of the front wheel. For more ideas consider the speedometer project in this tutorial. Otherwise for more information about this module please visit the product page.

Microphone Sound Input Module

This module performs two functions – it can return the sound pressure level (SPL) or the amplified audio waveform from the electret microphone. The LED (labelled “DETECT”) on the board visually displays an approximation of the SPL – for example:

… however the value can be returned by using an analogue input pin on an Arduino (etc). to return a numerical value. To do this connect the SPL pin to the analogue input. The MIC pin is used to take the amplified output from the microphone, to be processed by an ADC or used in an audio project. For more information please visit the product page.

Light Sensor Module

This module uses the TEMT6000 light sensor which returns more consistent values than can be possible using a light-dependent resistor. It outputs a voltage from the OUT pin that is proportional to the light level. The module is very small:

Use is simple – just measure the value returned from the OUT pin using an analogue input pin on your Arduino (etc). For more information please visit the product page. And finally, the:

Sound and Buzzer Module

This module contains a piezoelectric element that can be used to generate sounds (in the form of musical buzzes…):

Driving the buzzer is simple, just use pulse-width modulation. Arduino users can find a good demonstration of this here. Furthermore, as piezoelectric elements can also generate a small electrical current when vibrated, they can be used as “shock” detectors by measuring the voltage across the terminals of the element. The procedure to do this is also explained clearly here.

Now for a final demonstration – we use the light sensor to demonstrate making some noise with the buzzer module:

One final note I would like to make is that the design and construction quality of each module is first rate. The PCBs are strong, and the silk-screening is useful and descriptive. If you find the need for some or all of the functions made available in this range, you could do worse by not considering a Freetronics unit. Finally, although this has only been a short introduction to the modules for now, we will make use of them in later projects.

The modules are available directly from Freetronics or through their network of resellers.

Disclaimer – Modules reviewed in this article are a promotional consideration made available by Freetronics

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, freetronics, learning electronics, microcontrollers, modules, reviewComments (0)

Kit review – nootropic design Digit Shield

Hello readers

Time once again to examine another kit. This week we have the nootropic design Digit Shield for Arduino Uno/Duemilanove and compatible boards. Although a finger can be called a digit this shield is not some sort of biotechnological experiment – instead it gives us four seven-segment LED displays to show various forms of numerical data from our Arduino sketches.

Although many people may be tempted to use a standard LCD unit, there are a few advantages to using an LED display – such as digit size, enhanced readability in daylight, and LED displays are generally much more robust than LCDs. Therefore there should be many uses for the Digit Shield. Furthermore, the people at nootropic design have been awesome as they support the Open Hardware Definition 1.0, and the Digit Shield design files have been made available under Creative Commons attribution-share alike.

First let’s run through construction, then operation with some demonstrations. The kit arrives in a nice reusable bag with a pointer to the online instructions:

1ss

Kit construction was relatively simple thanks to the excellent instructions by nootropic design. All the parts required for completion are included, except for IC sockets:

2ss

My demonstration kit included green LED displays, however it is also available in red-orange, depending on the retail outlet you choose. Once again the PCB is well laid out, with a good solder mask and a nicely labelled silk screen on top:

3ss

Now to start soldering. The process is nothing out of the ordinary, and should take around half an hour at the most. First in are the resistors:

4ss

Notice how the current-limiting resistors for the LED segments will be under the LED displays. So now we solder in the LED modules and create a resistor jail:

5ss

Now for the shift register and BCD to decimal ICs. I found inserting them a little tricky due to my large hands and the LED display already being in place, so it would be easier to fit the ICs before the LED modules:

6ss

This leaves us with the transistors, capacitors, header sockets and the reset button:

7ss

After soldering the reset button, you may need trim down the solder and legs (as shown below) otherwise there is a possibility they will rub the DC input socket on the Arduino board:

Finally the shield pins are fitted and the shield is ready:

9ss

The next task is to download and install the Digit Shield’s Arduino library. The latest version can be found here. Extract the folder into your

folder, then restart the Arduino IDE software.  A quick test of the shield can be accomplished with the SimpleCounter sketch available from the inbuilt examples. To find this, select File>Examples>DigitShield>SimpleCounter in the Arduino IDE, and upload the sketch. Hold onto the desk as you watch some numbers increment:


Using the shield in your own sketch is quite simple. Instead of reinventing the wheel there is an excellent explanation of the various functions available on the lower section of this page. A very useful feature is when the shield cannot display a number – it shows all four decimal points instead. The only slight criticism that comes to mind is the inability to directly display hexadecimal digits A~F, as the LED units lend themselves nicely to doing so; or the option of controlling each LED segment individually with a simple function. So let’s see if that is possible…

One of the joys of open hardware is the fact we can get the schematic, see how it works and attempt to solve such dilemmas ourselves. For those without software that can read Cadsoft EAGLE files, here is the schematic in .pdf format. The section we need to see is how the LED segments are driven. Look for the 74HC595 and 74LS247 ICs. Serial data is shifted out from the Arduino digital pins to the 74HC595 shift register. (For more information about how 74HC595s work with Arduino please visit this tutorial).

Outputs A~D (Q0~Q3) represent binary-coded decimal output and the outputs E~H (Q4~Q7) control the transistors which select the current digit to use. The BCD output is fed to the 74LS247 BCD to seven-segment drive IC. Although this is a very useful IC, it can only display the decimal digits and a few odd characters (see page two of the data sheet.pdf). So this leaves us unable to modify our sketches or the shield library to solve our problem. Such is life!

Perhaps the people at nootropic design can consider a change in the hardware for the next version to incorporate such requirements. However there are several projects available in the Digit Shield’s website that may be of interest, including a way to daisy-chain more than one shield at a time.

Nevertheless the Digit Shield is a simple kit that makes displaying Arduino-generated numerical data simple and clear. Furthermore lovers of blinking LEDs will have a ball. For further questions about the Digit Shield contact nootropic design or perhaps post on their forum.

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, follow me on twitter or facebook, or join our Google Group for further discussion.

High resolution images are available on flickr.

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

Posted in arduino, kit review, notropicsComments (13)

Kit review – nootropics design EZ-Expander Shield

Hello readers

Today we are going introduce an inexpensive yet useful kit for Arduino people out there – the nootropic design EZ-Expander shield. As the name would suggest, this is an Arduino shield kit that you can easily construct yourself. The purpose of the shield is to give you an extra 16 digital outputs using only three existing digital pins. This is done by using two 74HC595 shift registers – whose latch, clock and data lines are running off digital pins 8, 12 and 13 respectively. For more information about the 74HC595 and Arduino, read my tutorial here, or perhaps download the data sheet.

Before moving forward I would like to note that the kit hardware is licensed under Creative Commons by-sa v3.0, and the design files are available on the nootropic design website; the software (Arduino library) is licensed under the CC-GNU LGPL. Nice one.

However, there is a library written instead to make using the new outputs easier. More on that later… now let’s build it and see how the EZ-Expander performs. Packaing is simple and effective, like most good kits these days – less is more:

packagingss

Everything you need and nothing you do not. The design and assembly instructions can be found by visiting the URL as noted on the label. The parts are simple and of good quality:

partsss4

The PCB is great, a nice colour, solder-masked and silk-screened very well. And IC sockets – excellent. There has been some discussion lately on whether or not kit producers should include IC sockets, I for one appreciate it. However, what I did not appreciate was having to chop up the long header socket to make a six- and eight-pin socket, as such:

cuttingss

Why the producers did not include real 6 and 8 pin sockets is beyond me. I’m not a fan of chopping things up, but my opinion is subjective. However there are a few extra pin-widths for a margin of error, so life goes on. The instructions on the nootropic design website were well illustrated, however the design is that simple you can determine it from the PCB. First, in with the capacitors for power smoothing:

capsss

Then solder in those lovely IC sockets and the header sockets:

socketsinss

Then time for the shield pins themselves. As usual, the easiest way is to insert the pins into another socket, then drop the new shield on top and solder away:

liningupss

Finally, insert the shift registers, and you’re done:

finishedss6

The shield is designed to still allow access to the digital pins zero to seven, and the analogue pins. Here is a top-down view of the shield in use:

topdownfinishedss

From a software perspective, download the library from here and install it into your arduino-00xx\libraries folder. Then it is simple to make use of the new outputs (20 to 35) on the shield, just include the library in your sketch as such:

then create an EZexpander object:

with which you can control the outputs with. For example,

sets the new output pin number 20 high. You can also buffer the pin mode requests, and send the lot out at once. For example, if you wanted pins 21, 22 and 23 to be HIGH at once, you would execute the following:

What happened is that you set the pin status up in advance, then sent all the commands out at once using the expander.doShiftOut(); function. The maximum amount of current you can source from each new output according to the designers is theoretically six milliamps, which is odd as the 74HC595 data sheet claims that 25 milliamps is possible. In the following demonstration I sourced 10 milliamps per LED, and everything was fine. Here is the sketch for your reference:

And the demonstration in action:

Overall, this is an inexpensive and simple way to gain more outputs on an Arduino Duemilanove/Uno or 100% compatible board. Also good for those who are looking for a kit for basic soldering practice that has a real use afterwards. High resolution images are available on flickr.

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.

Posted in arduino, kit review, notropicsComments (4)

Moving Forward with Arduino – Chapter 18 – RGB LED Matrix

Use an RGB LED matrix with Arduino in chapter 18  of a series originally titled “Getting Started with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.

[Updated 09/01/2013]

In this instalment we will take a turn away from the serious things for a while, (plus I wanted a bit of a break) and instead enjoy some introductory fun with common-cathode RGB LED matrices. (Matrices is the plural form of matrix). I am sure some of you have seen these do all sorts of things, so now it is time for me to learn about them and share this with you.

topss

Quite large – 60 by 60 mm. Thankfully this unit has the diffused/opaque LED surfaces – some cheaper ones have clear surfaces which don’ t look that good – it is like looking directly at an incandescent light globe, you can see the element more than the colour it emits. When you turn the matrix over, there are less pins than a newcomer may expect:

bottomss

Two rows of sixteen pins. Considering there is so much real-estate on the bottom, one would think the manufacturer could print some markings on there – but they don’t. So you need the (example) data sheet.pdf. The three most important things we need to know are:

  • the forward voltages: red – 2 V, green and blue – 3.3;
  • the current at the recommended forward voltage – 20 milliamps;
  • and the pinouts:

pinouts

It looks like a mess but isn’t that hard to work out. Do you remember how we used the 8×8 red LED matrix back in chapter nine? We will work on the same style of design in this chapter as well. I do realise there are chips from TI, Maxim and so on that are quite tricky – but I am trying to keep the cost down, of which I am sure you would appreciate. So instead we will use four 74HC595 shift registers (one to control the anodes of each colour, and one to control the cathodes via a bank of switching transistors.

To get this started, first let’s get the hardware out of the way. To fire this baby up we will need:

  • an Arduino Uno or 100% compatible board;
  • a common-cathode RGB LED matrix;
  • 24 x 560 ohm resistors (this value may seem like a bit much – but the display was still very bright)
  • 8 x 1 kilo ohm resistors (for transistors)
  • 8 x BC548 transistors
  • 4 x 74HC595 shift registers (IC1~4)
  • 1 x 1uF 16V (or higher) electrolytic capacitor
  • 1 x 0.1 uF 16V (or higher) ceramic capacitor
  • a nice large breadboard
  • plenty of connecting wire

Initially I was concerned about the amount of current this circuit would draw, however it was not to be an issue. With all the LEDs on, using the 560 ohm current-limiting resistors, the drain was much less than expected. To check, I powered the lot from a 9V PP3 battery and measured the current flow. 135 milliamps, not bad at all.

exam18p1current

It just occurred to me that if you had an Arduino Mega-compatible board – it could directly take care of everything instead of using three of the shift registers. So here is our schematic:

schematicss2

In the schematic above, there are eight transistor-resistor combinations between the cathodes of the matrix (pins 25, 24, 23, 10, 9, 8, 7 and IC4. And there are 560 ohm resistors on all output pins of ICs 1~3.  Furthermore,  note that your LED matrix’s pinouts may vary – so please check your data sheet before wiring it all up… having to retrace all those wires once they’re in is a real problem. As you can see from the resulting breadboard photo:

boardss

Now how does all this work?

Quite easily really, the hardest part is putting the hardware together. First of all, please review how we used shift registers in chapter four. And, you may recall how we used two 74HC595 shift registers to control an 8×8 red LED matrix back in chapter nine. This is just the same type of set up, but with two more shift registers – now we have one for the cathodes (as we did before), and one shift register each for the red, green and blue LEDs.

Instead of sending out two bytes of data using shiftOut();, we need to send out four bytes. For example, to turn on every LED at once (thereby mixing red, green and blue – producing white) we would create a function such as:

So as you can see, the first byte out the door is the data for the cathodes, in this case 255 – which is 11111111 in binary, or in 74HC595-speak “hey, turn on all outputs”. And the same again in turn for each bank of colours, the other three registers are told to open all gates and let current flow through the LEDs to the common-cathode lines controlled by IC4. So naturally, using some binary to base-10 conversion you can set which LEDs to come on and where. And of course, by mixing the primary colours – you can create new ones. For example, the additive colour chart gives us:

So now you can create yellow with red and green; red and blue makes purple; green and blue makes aqua or teal, etc. However I am colour blind, so you tell me. This time we will view the demonstration video first:

Download the matching sketchNow to examine how each of the effects were created, so you can understand,  use and modify them yourself.

The basic operations are contained in these four lines:

So all you need to do is replace r, b, g and c with the base-10 values you want. For example, to light up the red LED in position 1, 1 – use 1, 0, 0, 1. Or if you want the whole first line to be green, use: 255, 0, 0, 1. After a few moments you should become proficient at converting binary to base-10. This chart from chapter four should help you:

binary2

Remember that you can also create patterns and so on. For example, if you only wanted LEDs 1 and 8 for your x-axis, you would add 1 and 128 together, and use the sum (129) for your x-value. To save some time, I have created a few functions for you to use. For example:

So instead of having to manually repeat a lot of code, you can just insert the values into displayLEDs();. Another handy thing to know about is looping. When looking at the matrix it is easy to accidentally think “Oh, I can just loop from 1 to 8″… No. Remember your binary to base-10 conversions. So if you wanted to scroll a horizontal line of red LEDs your cathode or y-axis value must increment as such: 1, 2, 4, 8, 16, 32, 64, 128. Every time the loop cycles, it needs to double the value. To do this, consider:

Notice the q*=2? This will multiply the value of q by 2 every loop. Very useful. Another method would be to create an array, as such:

and refer to the elements as required. This is done within the function lostinspace(); within example 18.1.

The next thing to take into account is the screen refresh. Every time you send four bytes of data through the shift registers, those new bytes will ‘shift’ the old bytes out of the way. So if you want to alter the display even by just one LED, you need to redraw the entire display over again with four new bytes of data. Also note that to ‘hold’ an image on the display, you only need to send the data once – the shift registers will stay put until the next four bytes of data come along.

And sometimes, you might just want to turn off the display. Just send four zeros down to the registers, as the function clearMatrix(); does in the example sketch.

For now, please review the various functions found in example 18.1 – alter them, mess about and have some fun. Thus concludes our introduction to RGB LED matrices.

LEDborder

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, COM-00683, education, learning electronics, LED, lesson, matrix, microcontrollers, rgb, tutorialComments (6)

Announcement – August Competition!

Competition is well and truly over. 

Posted in competitionComments (1)

Part review – NXP 74HC4066 Quad bilateral switch IC

Hello readers!

Today we are going to examine the 74HC4066 quad bilateral switch IC. My reason for writing this comes from a comment left by a reader on chapter nine of the Arduino tutorial. They suggested using a 4066 IC to control the cathodes of the LED matrix instead of resistors and NPN transistors. This was a good suggestion, however the 4066 can only switch a current of 10mA per pin. Luckily the 74HC4066 can handle up to 25mA per switch – so we’ll look into this instead.

First of all, let’s say hello:

74hc4066

This is the 14-pin DIP package. It is also available in surface mount, and other newer package styles. Although we are looking at an example from NXP, according to my main component supplier (element-14/Newark) this IC is also manufactured by Texas Instruments, ON Semi, ST Microelectronics and Fairchild. So, what is a quad-bilateral switch? Four switches in one IC. Here is a diagram:

Imagine a simple normally-open push button. You press the button, and current can flow through the switch. Using the 74HC4066, when current is applied to the E pin, current can pass through from the matching Y pin to the Z pin. As you can see above, there are four of these switches in the IC. This is where the benefit of the IC comes to mind, normally one might use a 1k ohm resistor and an NPN switching transistor as an electronic switch, and I have done so myself. But when you need a few of them, it can be easier to start using these 74HC4066s as long as the current requirements are met.

With regards to the current the IC can switch, Is, the maximum is 25mA per switch. This is more than enough to run a typical LED, TTL logic gate, etc. The other interesting parameter is the turn-on and turn off times – at 6 volts it can turn on in around 10 nanoseconds and turn off at around 13 nanoseconds (so a rough calculation – say it takes 30 nanoseconds to switch on and then switch off, that’s 33.3 million times per seconds (33.3 MHz). All these parameters and more are available from the data sheet (pdf). Someone correct me if I’m wrong!

That’s enough theory – let’s put it to work now. Our first demonstration is quite simple – just switch on and off some LEDs via a 74HC595 shift register and an Arduino. We send a number (0, 1, 2, 4, 8 ) to the shift register, which stays off, then sets pins Q0, Q1, Q2, Q3 high in order, which in turn activate the switches 1~4 on the 74HC4066. The 74HC4066 sends a current to each LED connected to the switch outputs.

Here is the schematic:

demo1schematicsmall1

Laid out on the breadboard:

demo1small

And the ubiquitous video:

And here is the Arduino sketch: demo1.pdf. Well that was interesting. I know these simple demonstrations may be… well a little simple, but after taking the time to build them from scratch you get a better understanding of the part and how they work. Practice makes perfect and all that. Anyhow, let’s have a look at something much more interesting – a very basic (!) digital to analogue converter. Consider the circuit below:

demo2schematic

The 74HC4066 switches creates a final voltage through the sum of various currents being switched into the final output. First of all, here is a video of the switches being turned on and off one at a time:

and the corresponding Arduino sketch:demo2.pdf. The next video shows the results of sending decimal numbers 0~15 to the shift register – in effect continually adding the outputs of the pins until all pins are on, then in reverse:

and the corresponding Ardiono sketch:demo3.pdf.

Well I hope you found this part review interesting, and helped you think of something new to make. In conclusion I would consider the 74HC4066 easier and quicker for end user to use in projects (less pins to solder, etc) however using it could cost more depending on the volume required. Furthermore, this would only apply if the current restrictions of the IC are met.

So have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Notes: In writing this post, I used information from NXP, plus information and circuit inspiration from various books by Forrest Mims III.

Posted in 4066, 74HC4066, lesson, part review, tutorialComments (24)

Getting Started with Arduino! – Chapter Nine

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

Welcome back fellow arduidans!

In this chapter we will start looking at LED matrix displays, designing user interfaces, implementing a user interface for  a clock, and finish up making an alarm clock.

Firstly, let’s have plenty of fun with 64 LEDs! Using an 8×8 LED display module:

ledmatrixsmall

Previously we have used 74HC595 shift registers to drive strips of LEDs, single and four-digit LED displays. An LED matrix seems complex at first, but after further investigation quite simple. With sixteen pins you can control 64 LEDs. It works by having 8 row pins, each pin connected to all the anodes on one row; and 8 pins each connected to the cathodes on one column:

matrixschematic

It does look like a mess, but we can work it out. As we did with the 4-digit 7-segment display module, we just need one shift register for the anodes, and one for the cathodes. Moving along from exercise 6.2, it will be easy to drive the an LED matrix display – one shift register (the left hand side) will apply current to the rows (anodes) and the other shift register will apply current to NPN transistors to allow current to flow from the cathodes (columns) to ground. So we can make an example quite easily. You will need:

  • Your standard Arduino setup (computer, cable, Uno or compatible)
  • One 8×8 LED matrix. Try to find one that has LEDs with a forward voltage of 2 volts and a current of less than 20mA. If it is bicolour, that’s ok – just use one colour for now
  • Eight 560 ohm 1/4 watt resistors
  • Eight 1 kilo ohm 1/4 resistors
  • Eight BC548 NPN transistors
  • Two 74HC595 shift registers
  • Solderless breadboard and connecting wires

Here is a circuit diagram for our example (click on it to enlarge):

example9p1schematicsmall

Please note that there are eight transistor/resistor combinations from the second shift register – I just have not drawn them in to save my sanity. They’re on the bottom right of my board:

example9p1boardsmall

Now how are we going to light up those LEDs? We need to send two bytes of data to the shift registers, one byte for the row, and one for the column. For this example we will work with individual pixels. For example, say you want to turn on the pixel at 8 across, 8 down – the bottom right. You need to send the following bytes of data to the shift registers: b00000001 and b00000001. In decimal those two numbers are 128 and 128. Or the top-left LED, at 1 across, 1 down – it would be b10000000, b10000000 or decimal 1,1. Once again we can use the functions:

… to send the data to the shift registers. This example sketch for the above circuit should be pretty well self-explanatory if you have been following my tutorials.

Here is is in action:

Once again, quite mesmerising. Did you notice that the horizontal solid rows were dimmer than the solid vertical columns? This is because when you light up one row, all eight LEDs are drawing current from one pin of the shift register – so there is less current for each LED; whereas in the column, each LED has its own source of current, so can therefore operate at full brightness. So a hint – when you are creating images or characters for your display, use scrolling columns to display the image.

Experiment with the example 9.1 sketch, if you display only vertical columns, and make the delay zero – you can give the illusion that the entire display is on, but it is not. Which leads us into the first exercise for this chapter.

Exercise 9.1

We can display entire columns with our matrix display. We can position these columns on demand. And without a delay, fill up the entire matrix. Now you can create images, or characters and display them on the matrix, one column at a time. For example, the little yellow dude from that popular arcade game many years ago might look like this:

Using the circuit described for example 9.1, create a character, shape, or whatever tickles your fancy, and animate it to move across the screen.

Hint – To animate an image, you will need to map the matrix every time the image changes – just like a normal animation or cartoon. However, store all the values for the entire animation in one array, otherwise you will go bonkers. When you need to read the array, each matrix image can be read as they are multiples of eight (then add the reference to the value you want).

For inspiration, here is what I came up with:

and the corresponding sketch.

How did you go? If you have an interesting animation, and you can do so – please email a link to Youtube, Vimeo, etc showing your creation – you could win a prize.

Time to get a little more serious now. :(

Over time you have been making things, some useful, some more experimental than anything. Hopefully you will reach the stage of designing something that has a real-world use and could be used by people other than yourself or your immediate circle of friends. In the next few weeks we will look at methods of transitioning projects from prototypes to standalone products you can develop!

A major part of your design should be the user interface, or how your project responds to user input and displays data, results and so on. If something is difficult to use, or understand, it will not be a good product. So what can we do about this? This week we will examine the clock made in example 7.4 and change it to be independent of a computer, and easy for the user to operate. But now for some design inspiration…

The humble alarm clock (it has been staring at me every morning). Here is my late grandfather’s clock from the 1960s:

frontclocksmall

rearclocksmall

Simple, yet functional. It does what it is supposed to do with the minimum of fuss. (It’s German). And that is how our project user interfaces should be. As technical people it is very easy to get carried away and put buttons, lights, and all sorts of things together, but at the end of the day, less is more. How can we emulate this with Arduino – but in a simple method?

Looking at the face of the clock, it displays the time (hours, minutes, seconds) and the alarm time. We can use an LCD for that. On the top is the alarm off button. We can use a button for that. On the rear there are winders for the time and alarm spring – we have electricity for that. There are two knobs, one to adjust the time, and one to adjust the alarm – here we have several options. We could use up/down buttons… perhaps we could use a knob as well? And finally there is the gain control – we don’t need this as our DS1307 is infinitely more accurate.

A rough map of how you want things to work is always a good start, for example my mess below:

uidraftsmall

How can this be implemented? Let’s see. The clock will normally display the date, time, etc. If a button is pressed, it will switch to menu mode (on the right). A knob will be used to select one of the options listed on the right, when the required option is displayed, the user presses the button to select the option. Then the user can use the knob to adjust the variable for that option, and press the button to return to the menu. The last menu option is to return to the clock display. So we can control the whole lot with only one button and one knob.

The button is easy with Arduino, and to save money we can use a potentiometer as a knob. Remember we did this in in exercise 6.2. Normally it can return a value between 0 and 1023, but with our clock we need it to return a value that falls within a variety of ranges – from 0 to 6 for day of the week, to 0 to 59 for the minute adjustment.

Exercise 9.2

Create a function to use a potentiometer to return an integer between zero and a maximum range value. The function will accept the maximum range value, and return an integer which represents the position of the knob. For example:

Here is a short video of my interpretation in action.

And the resulting sketch. The value rangemax that is fed into the function is the number of positions in the range you want to work with. For example, if I want the knob to return a value between zero and fifty-nine (sixty values in the range) I would set rangemax to 60. The value dialpin is the number of the analogue pin the potentiometer is connected to. You should use a linear potentiometer to ensure a nice smooth adjustment.

Great – now we have a way of reading our knob and customising the result for our range requirements. Our clock example’s menu will require eight options, each with their own function (e.g. set hours, set minutes, set year, return to clock, etc). We have one button, so you could use that to trigger an interrupt to start the menu display (interrupts were covered in chapter three). However if you have made an LCD shield use the interrupt pins, you will need to check the button status while displaying the time. We will make the display of the menu a separate function as well.

For now we will make our clock respond to the ‘menu’ button, and display the eight options when the knob is rotated. We will build on the sketch from example 7.4. Here is the result of doing this:

Now it is time (ha!) to make those menu options actually do something. First we need our displaymenu() function to call the selected option. This can be done with a switch…case function. For example, I will put this code after the while loop:

There is no need for a seventh option (return to clock display) as this will default if the knob is in the ’7′ range. Notice I have already declared the name of the functions to call. All we have to do is create the individual functions. However there is one catch to work around, when it comes to setting time and date data, this is all done with the one function:

So inside the function that (for example) sets the hour, immediately before setting the hour, read the rest of the values from the clock, and reset them back in with the setDateDS1307() function.

Once again the basic work has been done for you, please see this video:

… and the sketch. Although the contents of the LCD during the menus may be brief, the framework of the user interface has been created and can now be easily modified. For example, if you had a 20 x 4 character LCD, you could offer more help to the user. But returning to the original task – emulating Grandfather’s alarm clock. We need an alarm!

Exercise 9.3

You guessed it – modify the clock in example 9.3 to have an alarm as well. User can set the alarm, and turn it on or off with the menu system. When the alarm sounds, the user should be able to turn off the alarm, Have fun!

How did you go? Here is a video demonstration of my work:

… and the sketch. That was really fun – I have a lot more clock ideas now.

I hope you enjoyed the change of pace this article and have a greater understanding on why we should create simpler human-machine interfaces wherever possible. Now to move on to Chapter Ten.

LEDborder

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, education, LED matrix, lesson, microcontrollers, tutorialComments (41)

Getting Started with Arduino! – Chapter Six addendum

Welcome back fellow arduidans!

After reviewing Chapter Six of our tutorials, I felt that there was some important information missing about the section regarding driving 4-digit 7-segment LED display modules. Although we have discussed displaying numbers using the module, and hopefully you have done this yourself with exercise 6.2, those numbers were constantly being written to the display as the sensor was being repeatedly read.

But how do we send a number to the display – and hold it there? We need a function that can accept the number to display – and the length of time (in cycles) to hold it there. I have rewritten the function displaynumber() from the solution to exercise 6.2 – now it accepts another value, “cycles”. This is the number of times the number will be shown on the display.

Here is a sketch to demonstrate this function, the hardware is the same as exercise 6.2, except there is no need for the variable resistor.

And my day wouldn’t be complete without another video demonstration. This example has cycles set to 500.

So there you have it! Now you have the knowledge to use these multi-digit displays effectively. And now that we have mastered them, we can move onto more interesting and useful display types. In the meanwhile, off to Chapter Seven.

LEDborder

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, education, lesson, microcontrollers, tutorialComments (0)

Getting Started with Arduino! – Chapter Six

This is part of a series titled “Getting Started with Arduino!” – A tutorial on the Arduino microcontrollers. The first chapter is here, and the complete index is here.

Welcome back fellow arduidans!

Hello once again to our regular Arduino tutorial instalment. In this chapter we are up to all sorts of things, including: distance sensing, using prototyping shields, even more shiftiness with shift registers and 4-digit 7-segment displays, and some exercises to refresh and expand your knowledge. Wow – let’s get cracking…

Do you know how to keep your distance? Some people do, some do not. The same goes for mechatronical things (i.e. robots, those little autonomous vacuum cleaners, etc). So to solve that problem you can integrate a distance sensor into your design. Hopefully by following this section you will gain an understanding of such sensors, and be able to make use of them later on in your own projects. Anyhow, today we are looking at the Sharp GP2Y0A21YK0F infra-red distance sensor. What a mouthful… The funny thing is that it looks like a robot head:

sharpsensorsmall

That white JST connector is for three leads, +5V, GND, and analogue out. When purchasing it you should also get a matching lead to save time and mucking about.

How it works is quite simple (I must stop writing that, some things are not as simple as they seem…) – the sensor contains an infra-red transmitter and a receiver. It returns a voltage that is relative to the distance between itself and the object in front of it. This output voltage is inversely proportional to the distance; which is explained better with this graph from the data sheet:

voltagedistance

However it is always fun to test these things out yourself. So I placed a sensor up over my desk, measured out 80cm, and attached the multimeter to the analogue output of the sensor:

sensorchecksmall

A crude setup but effective. I held a white piece of cardboard in front of the sensor, starting from more than one metre away, then moved closer to the minimum, then back out again. As shown in this video clip:

Although watching that multimeter may not have been too interesting, hopefully the next task will be!

Exercise 6.1

Using the values from the graph from the Sharp data sheet (above), make yourself a distance-measuring device. Use an LCD module to display the measurements. Metric and imperial! This shouldn’t be too hard at all, you’re just using one analogue input from the sensor, some basic maths, and displaying some data on an LCD. Furthermore, to make it truly portable, you could wire up a 9v PP3 battery to a DC plug and use it for power. A hint – before calculating distances, run a sketch to just return the analogRead() value from the sensor. Then you can make your own judgement on voltage-distance calculations. To save time I used the Electronic Bricks to rapidly construct this prototype.

You will need:
  • Your standard Arduino setup (computer, cable, Uno or compatible)
  • One parallel LCD display module
  • One Sharp infra-red distance sensor and sensor cable
  • a breadboard and some connecting wire

Anyhow, here is a photo of what I came up with:

exercise6p1small

and the ubiquitous video clip

Finally, my sketch for the solution. You may have to adjust the values in the decision tree for more accuracy. After spending some time with this sensor, I wouldn’t rely on it for exact distance calculations, however it would be very useful for general item detection, air switches and so on. In the next week or two we will examine another type of distance sensor.

What else could this be used for? Robotics sensors, burglar alarms, switching things on and off. Hopefully you have gained some knowledge about this sensor and have some ideas for implementation.

LEDborder

Now that we have spent a few weeks constructing our prototypes on breadboards and electronic bricks, it is now time to look at how we can do this in a more compact, and/or permanent method. As you already know, the Arduino system allows for “shields”, PCBs that plug on top of your Arduino board to add some sort of extra functionality. One of these was the Electronic Brick chassis, another popular shield is the Ethernet shield.

Moving on…

In previous instalments we have worked with 7-segment LED displays, using up to three at once, being controlled by 74HC595 shift registers. As you may have realised by now that involved a lot of wiring, resistors, time and effort. But what if you need four or more digits? Use an LCD… Maybe. Sometimes you need to use LED displays for aesthetic reasons, price, clarity, or just because you love that LED look. Thankfully you can find four digit displays, instead of having to use 2 x 2 or 4 x 1 digit displays. Let’s have a look at one now:

4dig7segsmall

For the newcomer there would be a surprising lack of pins on this display module. That is a good thing, and a slightly tricky thing – but we can overcome the obstacles and use it very easily. How? Again, with two 74HC595 shift registers and some brainpower. Firstly, let’s have a look at the pins – from left to right they are: E, D, C, G, F, B, A, C1, C2, C3, C4, decimal point, unused, unused. This display is common cathode, so to display (for example) the number 1 on digit 3, you would apply ~+2 volts to pins 6 and 7, and attach ground to pin 10. Very much the same as using a single-digit display, except you need to choose the cathode that corresponds with the digit you wish to use. In this tutorial we are using a Common Cathode unit. Out of curiosity’s sake, here is the data sheet for the module used in this chapter: data sheet.pdf.

Secondly, how are we going to control the cathodes with out Arduino? Current comes out of a cathode, so it would not accept a signal from our digital out pins. What we need to do is have a simple switch on each cathode between the display pin and ground, so we can control which digit we want to use. How can we do this with our Arduino? Easy… we can use a simple NPN transistor as a switch. Remember we did this with a relay in chapter three!

But using 4 digital out pins for cathode control is a waste of pins, we can use our trusty shift register again to control the cathodes. So that means we need two shift registers in total, the first to control the digit (0~9), and the second to switch on the cathode of the position we wish to display our digit in. Time to do it!

The first (left-hand) shift register from the Arduino controls the segments on the display, via 560 ohm resistors. Just like last time. The second (right-hand) shift register controls the cathodes. Pins Q0~Q3 connect to the base of a BC548 transistor via a 1k ohm resistor. The collector of the transistor is connected to the cathode on the display, and the emitter to ground. For example:

example6p1schematicsmall

Note that the schematic above is a guide only. But here it is in real life, below:

example6p1small

After a few projects, wiring up displays and shift registers should be a lot quicker for you now. Here is the matching sketch I came up with for the demonstration video below.

You’d have to admit, even in the year 2010, LED displays still look mesmerising. Or maybe that’s just me! Here is the data sheet display.pdf for the LED display I used. You can use other ones,as long as they are common cathode; just match the LED element pins with your first shift register, and the cathode pins with the second shift register.

But on to making something useful…

Exercise 6.2

Using the hardware from example 6.1 above, create a device that displays the value of an analogue sensor. For example, if we connect a 10k variable resistor to an analogue input, the Arduino will return a reading of between 0 and 1023. From a hardware perspective, all you need to do is add an analogue sensor (e.g. LDR, 10k variable resistor, the infra-red sensor from earlier on, etc.). The software will be a little tricky, but if you completed exercise 5.1, or 5.2 you shouldn’t have a problem at all. As you will be displaying one digit at a time, but very quickly, try to minimise the number of times you clear the display – in doing so you will keep the brightness at a maximum.

You will need:

  • Your standard Arduino setup (computer, cable, Uno or compatible)
  • One 4-digit, 7-segment LED display, common cathode
  • Two 74HC595 shift registers
  • Four BC548 or equivalent NPN transistors
  • 8 x 560 ohm 0.25 W resistors. For use as current limiters between the LED display segments and ground
  • One 10k variable resistor
  • a breadboard and some connecting wire

For motivation, here is a video clip of my result. There are two examples, one with leading zeroes, and one without:

And the sketch as well.

That wasn’t too hard was it? Now that you can use such a display, it will become easier to display output from your various projects. Now on to Chapter 6A.

LEDborder

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in arduino, distance sensor, education, gp2y0a21yk0f, infrared, IR, lesson, microcontrollers, sharp, tutorialComments (33)

Getting Started with Arduino! – Chapter Five

This is part of a series titled “Getting Started with Arduino!” – A tutorial on the Arduino microcontrollers. The first chapter is here, and the complete index here.

Welcome back fellow arduidans!

Hello once again to our weekly Arduino instalment. This week are up to all sorts of things, including: more shiftiness with shift registers, more maths, 7-segment displays, arduinise a remote control car, and finally make our own electronic game! Wow – let’s get cracking…

In the last chapter we started using a 74HC595 shift register to control eight output pins with only three pins on the Arduino. That was all very interesting and useful – but there is more! You can link two or more shift registers together to control more pins! How? First of all, there is pin we haven’t looked at yet – pin 9 on the ’595. This is “data out”. If we connect this to the data in pin (14) on another ’595, the the first shift register can shift a byte of data to the next shift register, and so on.

Recall from our exercise 4.1, this part of the sketch:

If we add another shiftOut(); command after the first one, we are sending two bytes of data to the registers. In this situation the first byte is accepted by the first shift register (the one with its data in pin [14] connected to the Arduino), and when the next byte is sent down the data line, it “pushes” the byte in the first shift register into the second shift register, leaving the second byte in the first shift register.

So now we are controlling SIXTEEN output pins with only three Arduino output pins. And yes – you can have a third, fourth … if anyone sends me a link to a Youtube clip showing this in action with 8 x 74HC595s, I will send them a prize. So, how do we do it? The code is easy, here is the sketch. On the hardware side, it is also quite simple. If you love blinking LEDs this will make your day. It is the same as exercise 4.1, but you have another 74HC595 connected to another 8 LEDS. The clock and latch pins of both ’595s are linked together, and there is a link between pin 9 of the first register and pin 14 of the second. Below is a photo of my layout:

example5p1small

and a video:

Can you think of anything that has seven or eight LEDs? Hopefully this photo will refresh your memory:

ch57seg_small

Quickie – if you want to find out the remainder from a quotient, use modulo – “%”. For example:

a = 10 % 3;

returns a value of 1; as 10 divided by 3 is 3 remainder 1.

and

If you need to convert a floating-point number to an integer, it is easy. Use int();. It does not round up or down, only removes the fraction and leaves the integer.

Anyhow, now we can consider controlling these numeric displays with our arduino via the 74HC595. It is tempting to always use an LCD, but if you only need to display a few digits, or need a very high visibility, LED displays are the best option. Furthermore, they use a lot less current than a backlit LCD, and can be read from quite a distance away. A 7-segment display consists of eight LEDs arrange to form the digit eight, with a decimal point. Here is an example pinout digram:

7segpinout

Note that pinouts can vary, always get the data sheet if possible.

Displays can either be conmmon-anode, or common-cathode. That is, either all the LED segment anodes are common, or all the cathodes are common. Normally we will use common-cathode, as we are “sourcing” current from our shift register through a resistor (560 ohm), through the LED then to ground. If you use a common-anode, you need to “sink” current from +5v, through the resistor and LED, then into the controller IC. Now you can imagine how to display digits using this type of display – we just need to shiftout(); a byte to our shift register that is equavalent to the binary representation of the number you want to display.

Huh?

Let’s say we want to display the number ’8′ on the display. You will need to light up all the pins except for the decimal point. Unfortunately not all 7-segment displays are the same, so you need to work out which pinout is for each segment (see your data sheet) and then find the appropriate binary number to represent the pins needed, then convert that to a base-10 number to send to the display. I have created a table to make this easier:

example5p2pintable

And here is a blank one for you to print out and use: blank pin table.pdf.

Now let’s wire up one 7-segment display to our Arduino and see it work. Instead of the eight LEDs used in exercise 4.1 there is the display module. For reference the pinouts for my module were (7,6,4,2,1,9,10,5,3,8) = (a,b,c,d,e,f,g,DP, C, C) where DP is the decimal point and C is a cathode (which goes to GND). The sketch: example 5.2. Note in the sketch that the decimal point is also used; it’s byte value in this example is 128. If you add 128 to the value of loopy[] in the sketch, the decimal point will be used with the numbers.

example5p2small

and the video:

There you go – easily done. Now it is time for you to do some work!

Exercise 5.1

Produce a circuit to count from 0 to 99 and back, using two displays and shift-registers. It isn’t that difficult, the hardware is basically the same as example 5.1 but using 7-segment displays.

You will need:

  • Your standard Arduino setup (computer, cable, Uno or compatible)
  • Two 7-segment, common-cathode displays
  • Two 74HC595 shift registers
  • 16 x 560 ohm 0.25 W resistors. For use as current limiters between the LED display segments and ground
  • a breadboard and some connecting wire
  • some water

You are probably wondering how on earth to separate the digits once the count hits 10… a hint: 34 modulo 10 = 4. 34 divided by 10 = 3.4 … but 3.4 isn’t an integer. While you are thinking, here is the shot of my layout:

exercise5p1small

and the ubiquitous video:

And here is the sketch for my interpretation of the answer.

I hope you have gained more of an understanding of the possibilities available with shift registers. We will continue with more in the next tutorial.
Exercise 5.2

Once again it is your turn to create something. We have discussed binary numbers, shift registers, analogue and digital inputs and outputs, creating our own functions, how to use various displays, and much more. So our task now is to build a binary quiz game. This is a device that will:

  • display a number between 0 and 255 in binary (using 8 LEDs)
  • you will turn a potentiometer (variable resistor) to select a number between 0 and 255, and this number is displayed using three 7-segment displays
  • You then press a button to lock in your answer. The game will tell you if you are correct or incorrect
  • Basically a “Binary quiz” machine of some sort!

I realise this could be a lot easier using an LCD, but that is not part of the exercise. Try and use some imagination with regards to the user interface and the difficulty of the game. At first it does sound difficult, but can be done if you think about it. At first you should make a plan, or algorithm, of how it should behave. Just write in concise instructions what you want it to do and when. Then try and break your plan down into tasks that you can offload into their own functions. Some functions may even be broken down into small functions – there is nothing wrong with that – it helps with planning and keeps everything neat and tidy. You may even find yourself writing a few test sketches, to see how a sensor works and how to integrate it into your main sketch. Then put it all together and see!

You will need: (to recreate my example below)

  • Your standard Arduino setup (computer, cable, Uno or compatible)
  • Three 7-segment, common-cathode displays
  • eight LEDs (for binary number display)
  • Four 74HC595 shift registers
  • 32 x 560 ohm 0.25 W resistors. For use as current limiters between the LED display segments and ground
  • a breadboard and some connecting wire
  • 10k linear potentiometer (variable resistor)
  • some water

For inspiration here is a photo of my layout:

exercise5p2small

and a video of the game in operation. Upon turning on the power, the game says hello. You press the button to start the game. It will show a number in binary using the LEDs, and you select the base-10 equivalent using the potentiometer as a dial. When you select your answer, press the button  - the quiz will tell you if you are correct and show your score; or if you are incorrect, it will show you the right answer and then your score.

I have set it to only ask a few questions per game for the sake of the demonstration:

And yes – here is the sketch for my answer to the exercise. Now this chapter is over. Hope you had fun! Now move on to Chapter Six.

 

Posted in 74hc595, arduino, education, hardware hacking, lesson, microcontrollers, tutorialComments (23)

Getting Started with Arduino! – Chapter Four

This is part of a series titled “Getting Started with Arduino!” – A tutorial on the Arduino microcontrollers. The first chapter is here, and the complete index is here.

In this chapter will be looking at getting more outputs from less pins, listening to some tunes, saying hooray to arrays, and even build a self-contained data logger.

More pins from less – sounds too good to be true, doesn’t it? No, it is true and we can learn how to do this in conjunction with a special little IC, the 74HC595 Serial In/Parallel Out 8-bit Shift Register. Let’s say hello:

74hc595

Before we get too carried away, we need to understand a little about bits, bytes and binary numbers.

A binary number can only uses zeros and ones to represent a value. Thus binary is also known as “base-2″, as it can only use two digits. Our most commonly used number types are base-10 (as it uses zero through to nine; hexadecimal is base-16 as it uses 0 to 9 and A to F). How can a binary number with only the use of two digits represent a larger number? It uses a lot of ones and zeros. Let’s examine a binary number, say 10101010. As this is a base-2 number, each digit represents 2 to the power of x, from x=0 onwards.

binary12

See how each digit of the binary number can represent a base-10 number. So the binary number above represents 85 in base-10 – the value 85 is the sum of the base-10 values. Another example – 11111111 in binary equals 255 in base 10.

binary2

Now each digit in that binary number uses one ‘bit’ of memory, and eight bits make a byte. A byte is a special amount of data, as it matches perfectly with the number of output pins that the 74HC595 chip controls. (See, this wasn’t going to be a maths lesson after all). If we use our Arduino to send a number in base-10 out through a digital pin to the ’595, it will convert it to binary and set the matching output pins high or low.

So if you send the number 255 to the ’595, all of the output pins will go high. If you send it 01100110, only pins 1,2,5, and 6 will go high. Now can you imagine how this gives you extra digital output pins? The numbers between 0 and 255 can represent every possible combination of outputs on the ’595. Furthermore, each byte has a “least significant bit” and “most significant bit” – these are the left-most and right-most bits respectively.

Now to the doing part of things. Let’s look at the pinout of the 74HC595: (from NXP 74HC595 datasheet)

74hc595pinouts

Pins Q0~Q7 are the output pins that we want to control. The Q7′ pin is unused, for now. ’595 pin 14 is the data pin, 12 is the latch pin and 11 is the clock pin. The data pin connects to a digital output pin on the Arduino. The latch pin is like a switch, when it is low the ’595 will accept data, when it is high, the ’595 goes deaf. The clock pin is toggled once the data has been received. So the procedure to get the data into a ’595 is this:

1) set the latch pin low (pin 12)

2) send the byte of data to the ’595 (pin 14)

3) toggle the clock pin (pin 11)

4) set the latch pin high (pin 12)

Pin 10 (reset) is always connected to the +5V, pin 13 (output enable) is always connected to ground.

Thankfully there is a command that has parts 2 and 3 in one; you can use digitalWrite(); to take care of the latch duties. The command shiftOut(); is the key. The syntax is:

where:

a = the digital output pin that connects to the ’595 data pin (14);

b = the digital output pin that connects to the ’595 clock pin (11);

c can be either LSBFIRST or MSBFIRST. MSBFIRST means the ’595 will interpret the binary number from left to right; LSBFIRST will make it go right to left;

d = the actual number (0~255) that you want represented by the ’595 in binary output pins.

So if you wanted to switch on pins 1,2,5 and 6, with the rest low, you would execute the following:


Now, what can you do with those ’595 output pins? More than you could imagine! Just remember the most current you can sink or source through each output pin is 35 milliamps.

For example:

  • an LED and a current-limiting resisor to earth… you could control many LEDs than normally possible with your Arduino;
  • an NPN transistor and something that draws more current like a motor or a larger lamp
  • an NPN transistor controlling a relay (remember?)

With two or more ’595s you can control a matrix of LEDs, 7-segment displays, and more – but that will be in the coming weeks.

For now, you have a good exercise to build familiarity with the shift-register process.

Exercise 4.1

Construct a simple circuit, that counts from 0~255 and displays the number in binary using LEDs. You will require the following:

  • Your standard Arduino setup (computer, cable, Uno or compatible)
  • 8 LEDs of your choosing
  • One 74HC595 shift register
  • 8 x 560 ohm 0.25 W resistors. For use as current limiters between the LEDs and ground.
  • a breadboard and some connecting wire

The hardware is quite easy. Just remember that the anodes of the LEDs connect with the ’595, and the cathodes connect to the resistors which connect to ground. You can use the Arduino 5V and GND.

Here is what my layout looked like:

ex4p1layoutsmall

and of course a video – I have increased the speed of mine for the sake of the demonstration.

How did you go? Here is the sketch if you need some ideas.

Next on the agenda today is another form of output – audio.

Of course you already knew that, but until now we have not looked at (or should I say, listened to) the audio features of the Arduino system. The easiest way to get some noise is to use a piezo buzzer. An example of this is on the left hand side of the image below:

soundmachine_small

These are very simple to use and can be very loud and annoying. To get buzzing, just connect their positive lead to a digital output pin, and their negative lead to ground. Then you only have to change the digital pin to HIGH when you need a buzz. For example:

You won’t be subjected to a recording of it, as thankfully (!) my camera does not record audio…

However, you will want more than a buzz. Arduino has a tone(); command, which can generate a tone with a particular frequency for a duration. The syntax is:

where pin is the digital output pin the speaker is connected to, frequency in Hertz, duration in milliseconds. Easy! If you omit the duration variable, the tone will be continuous, and can be stopped with notone();. Furthermore, the use of tone(); will interfere with PWM on pins 3 and 11, unless you are using an Arduino Mega.

Now, good choice for a speaker is one of those small 0.25w 8 ohm ones. My example is on the right in the photo above, taken from a musical plush toy. It has a 100 ohm resistor between the digital output pin and the speaker. Anyhow, let’s make some more annoying noise – hmm – a siren! (download)

Phew! You can only take so much of that.

Array! Hooray? No… Arrays.

What is an array?

Let’s use an analogy from my old comp sci textbook. Firstly, you know what a variable is (you should by now). Think of this as an index card, with a piece of data written on it. For example, the number 8. Let’s get a few more index cards, and write one number on each one. 6, 7, 5, 3, 0, 9. So now you have seven pieces of data, or seven variables. They relate to each other in some way or another, and they could change, so we need a way to keep them together as a group for easier reference. So we put those cards in a small filing box, and we give that box a name, e.g. “Jenny”.

An array is that small filing box. It holds a series of variables of any type possible with arduino. To create an array, you need to define it like any other variable. For example, an array of 10 integers called jenny would be defined as:

And like any other variable, you can predefine the values. For example:

Before we get too excited, there is a limit to how much data we can store. With the Arduino Duemilanove, we have 2 kilobytes for variables. See the hardware specifications for more information on memory and so on. To use more we would need to interface with an external RAM IC… that’s for another chapter down the track.

Now to change the contents of an array is also easy, for example

will change our array to

Oh, but that was the fourth element! Yes, true. Arrays are zero-indexed, so the first element is element zero, not one. So in the above example, jenny[4] = 6. Easy.

You can also use variables when dealing with arrays. For example:

Will change alter our array to become

A quick way set set a lot of digital pins to output could be:

Interesting… very interesting. Imagine if you had a large array, an analogue input sensor, a for loop, and a delay. You could make a data logger. In fact, let’s do that now.

Exercise 4.2

Build a temperature logger. It shall read the temperature once every period of time, for 24 hours. Once it has completed the measurements, it will display the values measured, the minimum, maximum, and average of the temperature data. You can set the time period to be of your own choosing. So let’s have a think about our algorithm. We will need 24 spaces to place our readings (hmm… an array?)

  • Loop around 24 times, feeding the temperature into the array, then waiting a period of time
  • Once the 24 loops have completed, calculate and display the results on an LCD and (if connected) a personal computer using the Arduino IDE serial monitor.

I know you can do it, this project is just the sum of previously-learned knowledge. If you need help, feel free to email me or post a comment at the end of this instalment.

To complete this exercise, you will need the following:

  • Your standard Arduino setup (computer, cable, Uno or compatible)
  • Water (you need to stay hydrated)
  • Analog Devices TMP36 temperature sensor (element-14 part number 143-8760)
  • 1 little push button
  • 1 x 10k 0.25 W resistor. For use with the button to the arduino
  • a breadboard and some connecting wire
  • one LCD display module

And off you go!

Today I decided to construct it using the Electronic Bricks for a change, and it worked out nicely. Here is a photo of my setup:

ex4p2layoutsmall

a shot of my serial output on the personal computer:

and of course the ubiquitous video. For the purposes of the demonstration there is a much smaller delay between samples…

(The video clip below may refer to itself as exercise 4.1, this is an error. It is definitely exercise 4.2)

And here is the sketch if you would like to take a peek. High resolution photos are available in flickr. Another chapter over! I’m already excited about writing the next instalment… Chapter Five.

LEDborder

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

Posted in 74hc595, arduino, education, lesson, microcontrollers, tronixstuff, tutorialComments (19)


Receive notifications of new posts by email.

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

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

Use of our content…

%d bloggers like this: