Category Archives: sensor

Book – “Arduino Workshop – A Hands-On Introduction with 65 Projects”

Over the last few years I’ve been writing a few Arduino tutorials, and during this time many people have mentioned that I should write a book. And now thanks to the team from No Starch Press this recommendation has morphed into my new book – “Arduino Workshop“:


Although there are seemingly endless Arduino tutorials and articles on the Internet, Arduino Workshop offers a nicely edited and curated path for the beginner to learn from and have fun. It’s a hands-on introduction to Arduino with 65 projects – from simple LED use right through to RFID, Internet connection, working with cellular communications, and much more.

Each project is explained in detail, explaining how the hardware an Arduino code works together. The reader doesn’t need any expensive tools or workspaces, and all the parts used are available from almost any electronics retailer. Furthermore all of the projects can be finished without soldering, so it’s safe for readers of all ages.

The editing team and myself have worked hard to make the book perfect for those without any electronics or Arduino experience at all, and it makes a great gift for someone to get them started. After working through the 65 projects the reader will have gained enough knowledge and confidence to create many things – and to continue researching on their own. Or if you’ve been enjoying the results of my thousands of hours of work here at tronixstuff, you can show your appreciation by ordering a copy for yourself or as a gift 🙂

You can review the table of contents, index and download a sample chapter from the Arduino Workshop website.

Arduino Workshop is available from No Starch Press in printed or ebook (PDF, Mobi, and ePub) formats. Ebooks are also included with the printed orders so you can get started immediately.


In the meanwhile have fun and keep checking into 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.

Tutorial – Parallax Ping))) Ultrasonic Sensor

Sense distance with ultrasonic sensors in chapter forty-five of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – a series of articles on the Arduino universe. The first chapter is here, the complete series is detailed here.

Updated 05/02/2013

Whilst being a passenger in a vehicle with a ‘reversing sensors’, I became somewhat curious as to how the sensors operated and how we can make use of them. So for this chapter we will investigate an ultrasonic sensor from Parallax called the Ping)))™ Ultrasonic Distance Sensor. It can measure distances between ~2cm and ~3m in length. Here is our example sensor:

(Memories of Number Five …)

Parallax have done a lot of work, the board contains not just the bare sensor hardware but controller circuitry as well:

Which is great as it leaves us with only three pins – 5V, GND and signal. More on those in a moment, but first…

How does it work?

Good question. The unit sends out an ultrasonic (a sound that has a frequency which is higher than can be heard by the human ear) burst of sound from one transducer (the round silver things) and waits for it bounce off an object and return – which is detected by the other transducer. The board will then return to us the period of time taken for this process to take, which we can interpret to determine the distance between the sensor and the object from which the ultrasonic sound bounced from.

The Ping))) only measures a distance when requested – to do this we send a very short HIGH pulse of five microseconds to the signal pin. After a brief moment a pulse will come from the board on the same signal pin. The period of this second pulse is the amount of time the sound took to travel out and back from the sensor – so we divide it by two to calculate the distance. Finally, as the the speed of sound is 340 metres per second, the Arduino sketch can calculate the distance to whatever units required.

It may sound complex, but it is not –  so let’s run through the theory of operation with an example. Using our digital storage oscillscope we have measured the waveforms on the signal pin during a typical measurement. Consider the following example of measuring a distance of 12cm:


You can see the 5uS pulse in the centre and the pulse returned from the sensor board on the right. Now to zoom in on the returned pulse:


Without being too picky the pulse is roughly 720uS (microseconds) long – the duration of ultrasonic sound’s return trip from the sensor board. So we divide this by two to find the time to travel the distance – 360uS. Recall the speed of sound is 340 metres per second – which converts to 29.412 uS per centimetre. So, 360uS divided by 29.412 uS gives 12.239902081… centimetres. Rounded that gives us 12 centimetres. Easy!

Finally, there are some limitations to using the Ping))) sensor. Download the data sheet (pdf) and read pages three to five for information on how to effectively mount the sensor and the sensitivity results from factory resting.

How do we use it with Arduino?

As described previously we first need to send a 5uS pulse, then listen for the return pulse. The following sketch does just that, then converts the data to centimetres and displays the result on the serial monitor. The code has been commented to explain each step.

And the results of some hand-waving in the serial monitor:

So there you have it – you can now measure distance with a degree of accuracy. However that image above isn’t very exciting – instead let’s use a 7-segment display shield to get things up in lights. The shield uses the NXP SAA1064 LED display driver IC (explained quite well here). You can download the demonstration sketch from here. And now for the video:

So there you have it – now the use of the sensor is up to your imagination. Stay tuned using the methods below to see what we get up to with this sensor in the future.


Have fun and keep checking into 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.

Moving Forward with Arduino – Chapter 15 – RFID Introduction

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

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

Updated 21/02/2013

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

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

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


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

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

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



Note that all the GND pins are connected together. Now upload the following sketch:

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

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

Excellent – simple numbers that we can work with. For example, one of my tags returns: 2,51,69,48,48,49,65,51,53,70,50,69,51,3 and another returns 2,51,67,48,48,67,69,49,48,68,53,51,55,3. Note that both start with 2 and end with 3, so the unique tag details are the 12 integers between the 2 and 3. One could read the data as characters or hexadecimal numbers by altering the data type in the sketch from int to byte, but for simplicity I am working in integers. Now all we need to do is fashion sketches to recognise the tag number(s) we want to use, and perform an action based on which tag number is used (or do something when a tag is read, but not the tag you want).

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


And a short video in action:

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

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

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

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

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

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

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


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

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


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


Have fun and keep checking into 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.