Project – Ultrasonic Combination Switch

In this project you learn how to make an ultrasonic distance-sensing combination switch.

Updated 18/03/2013

Time for a follow-up to the Single Button Combination Lock by creating another oddball type of switch/lock. To activate this switch we make use of a Parallax Ping))) Ultrasonic sensor, an Arduino-style board and some other hardware – to make a device that receives a four-number code which is made up of the distance between a hand and the sensor. If Arduino and ultrasonic sensors are new to you, please read this tutorial before moving on.

The required hardware for this project is minimal and shown below – a Freetronics Arduino-compatible board, the Ping))) sensor, and for display purposes we have an I2C-interface LCD module:

The combination for our ‘lock’ will consist of four integers. Each integer is the distance measured between the sensor and the user’s hand (etc.). For example, a combination may be 20, 15, 20, 15. So for the switch to be activated the user must place their hand 20cm away, then 15, then 20, then 15cm away. Our switch will have a delay between each measurement which can be modified in the sketch.

To keep things simple the overlord of the switch must insert the PIN into the switch sketch. Therefore we need a way to take measurements to generate a PIN. We do this with the following sketch, it simply displays the distance on the LCD):

And here is a demonstration of the sketch in action:

Now for the switch itself. For our example the process of “unlocking” will be started by the user placing their hand at a distance of 10cm or less in front of the sensor. Doing so will trigger the function checkPIN(), where the display prompts the user for four “numbers” which are returned by placing their hand a certain distance away from the sensor four times, with a delay between each reading which is set by the variable adel. The values of the user’s distances are stored in the array attempt[4].

Once the four readings have been taken, they are compared against the values in the array PIN[]. Some tolerance has been built into the checking process, where the value entered can vary +/- a certain distance. This tolerance distance is stored in the variable t in this function. Each of the user’s entries are compared and the tolerance taken into account. If each entry is successful, one is added to the variable accept. If all entries are correct, accept will equal four – at which point the sketch will either “unlock” or display “*** DENIED ***” on the LCD.

Again, this is an example and you can modify the display or checking procedure yourself. Moving forward, here is our lock sketch:

To finish the switch, we housed it in the lovely enclosure from adafruit:

And for the final demonstration of the switch in action. Note that the delays between actions have been added for visual effect – you can always change them to suit yourself:

So there you have it – the base example for a different type of combination switch. I hope someone out there found this interesting or slightly useful.

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.

The following two tabs change content below.

John Boxall

Founder, owner and managing editor of tronixstuff.com.

2 Responses to “Project – Ultrasonic Combination Switch”

  1. Stuart ( Nobby ) Clarke says:

    Hi John. I’m a 59 yr old that has been into electronics from an early age and to continue to enjoy this hobby I have realised I need to get up to date with this sort of technology as most kits these days are based on micros and I found programing to be a large hurdle to get over. I have started with looking on the web and find your book is something that I will obtain after looking at this site. Thank you
    Nobby Clarke

Trackbacks/Pingbacks


Leave a Reply

Receive notifications of new posts by email.

Arduino Tutorials

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: