# Project: Clock Two – Single digit clock

Let’s hack an Ikea lamp into a single-digit clock! How? Read on…

Updated 18/03/2013

Time for another instalment in my irregular series of clock projects. (Or should that be “Time for another instalment in the series of irregular clock projects”?) In contrast with the extreme “blinkiness” of Clock One, in this article we describe how to build this single-digit digital clock:

Once again the electronics of the clock will be based from an Arduino-compatible board with a DS1307 real-time clock IC added to the board. On top of this we add a shield with some extra circuitry and two buttons – but more on this later. The inspiration for this clock came from a product that was recently acquired at Ikea – the “Kvart” work lamp, for example:

If you are shopping for one, here are the Ikea stock details:

The goal is to place the electronics of the clock in the base, and have one single-digit LED display at the top of the neck which will blink out the digits. There will be two buttons under the base that are used to set the time. It will be powered by a 9V battery or an AC adaptor which is suitable for a typical Arduino board.

Construction

This article is a diary of my construction, and you can always use your own knowledge and initiative. It is assumed that you have a solid knowledge of the basics of the Arduino system.  If not, review my series of tutorials available from here. Furthermore, feel free to modify the design to work with what you have available – I hope this article can be of some inspiration to you.

Software

It is much easier to prototype the clock and get the Arduino sketch working how you like it before breaking down the lamp and building up the clock. To do this involves some jumper wires and a solderless breadboard, for example:

Although there are four buttons on the board we only use two. They are connected to digital pins eight and nine (with 10k pull-down resistors). The LED display segments a~g are connected to Arduino digital pins 0~6 respectively. The decimal point is connected to the pulse output pin of the DS1307 – which will be set to a 1Hz output to have a nice constant blinking to show the clock is alive and well.

If you are unfamiliar with operating the DS1307 real-time clock IC please review this tutorial. Operation of the clock has been made as simple for the user as possible. To set the time, they press button A (on digital eight) while the current time is being displayed, after which point the user can select the first digit (0~2) of the time by pressing button A. Then they press button B (on digital nine) to lock it in and move to the second digit (0~9) which is again chosen with button A and selected with button B. Then they move onto the digits in the same manner.

After this process the new time is checked for validity (so the user cannot enter invalid times such as 2534h) – and is ok, the clock will blink the hyphen twice and then carry on with the new time. If the entered time is invalid, the clock reverts back to the current time. This process is demonstrated in the following video clip:

You can download the Arduino sketch from here.

Hardware

The parts required to replicate the Clock Two in this article are:

• One Arduino-compatible board with DS1307 real-time clock IC as described in this article
• One Arduino protoshield and header pins
• One common-cathode 7-segment LED display of your choosing
• Seven current-limiting resistors to reduce the output current from Arduino digital outputs going to the LED segments. In our example we use a 560 ohm resistor network to save time
• Two buttons and two 10k ohm pull-down resistors
• One meter of nine-core wire that will fit inside the neck and stand of the Kvart lamp – an external diameter of less than 6mm will be fine
• And of course – the lamp

The protoshield is used to hold the buttons, resistor network and the terminus for the wires between the LED display and the Arduino digital outputs, for example:

At this stage you will need to do some heavy deconstruction on the lamp. Cut off the mains lead at the base and remove the plastic grommet from the stand that surrounded the AC lead. Next,  with some elbow grease you can twist off the lamp-shade unit from the end of the flexible neck. You could always reuse the lamp head and AC lead if wired by a licensed electrician.

Now you need to feed the multicore wire through the neck and down to the base of the lamp. You can pull it through the hole near the base, and then will need to drill a hole in the base to feed it through to the electronics as such:

Take care when feeding the cable though so you don’t nick the insulation as shown above. Leave yourself a fair bit of slack at the top which will make life easier when soldering on the LED display, for example:

The next step is to solder the wires at the top to the LED display. Make notes to help recall which wires are soldered to the pins of the display. If your soldering skills (like mine) aren’t so good, use heatshrink to cover the soldering:

Most displays will have two GND pins, so bridge them so you only need to use one wire in the multicore back to base:

At this point use the continuity function of a multimeter or a low-voltage power source to test each LED segment using the other end of the cable protruding from the base. Once you are satisfied the segments have been soldered correctly, carefully draw the cable back through the neck and base in order to reduce the slack between the display and the top of the lamp neck. Then solder the individual LED segment wires to the protoshield.

Now if you have not already done so, upload the sketch into the Arduino board – especially if you are going to permanently mount the circuitry into the base. A simple method of mounting would be using  a hot glue gun, but for the purpose of demonstration we have just used blu-tac:

Although this does look a little rough, we are using existing stock which kept the cost down. If you are going to power the clock with an AC adaptor, you will also need to cut out small opening to allow the lead to protrude from the side of the base. And now for the resulting clock – our Clock Two:

So there you have it, the second of many clocks we plan to describe in the future.

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.

# Tutorial: Control AC outlets via SMS

Learn how to control AC outlets via SMS text message. This is chapter thirty-three of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.

Updated 02/03/2013

Assumed understanding for this article is found in part one. If you have not already done so, please read and understand it.

In this chapter we will continue with the use of the SM5100 cellular shield to turn digital outputs on and off via SMS. However please read chapters twenty-six and twenty-seven first if you are unfamiliar with using the GSM shield with Arduino. As an extension of chapter twenty-seven, we will use our Arduino to turn on or off AC outlets via a common remote-control AC outlet pack. Please note this is more of a commentary of my own experience, and not an exact tutorial. In other words, by reading this I hope you will gain some ideas into doing the necessary modifications yourself and in your own way.

Firstly, we need some remote-control AC outlets. Most electrical stores or giant retail warehouses may have something like this:

Nothing too original, just a wireless remote control that can switch on or off receiver outlets on a choice of four radio frequencies. Before moving forward I would like to acknowledge that this article was inspired by the wonderful book Practical Arduino – Cool Projects for Open Source Hardware by Jon Oxer and Hugh Blemings. In chapter two an appliance remote-control system is devised using a similar system.

At first glance the theory behind this project is quite simple – using the hardware in example 27.2, instead of controlling LEDs, activate the buttons on the wireless remote control for the AC outlets – leaving us with AC outlets controlled via SMS. However there are a few things to keep in mind and as discovered during the process, various pitfalls as well.

Before voiding the warranty on your remote control, it would be wise to test the range of the remote control to ensure it will actually work in your situation. I found this was made a lot easier by connecting a radio to the remote outlet – then you can hear when the outlet is on or off. If this is successful, make a note of the amount of time required to press the on and off buttons – as we need to control the delay in our Arduino sketch.

The next step is to crack open the remote control:

… and see what we have to work with:

Straight away there are two very annoying things – the first being the required power supply – 12 volts; and the second being the type of button contacts on the PCB. As you can see above we only have some minute PCB tracks to solder our wires to. It would be infinitely preferable to have a remote control that uses actual buttons soldered into a PCB, as you can easily desolder and replace them with wires to our Arduino system. However unless you can casually tear open the remote control packaging in the store before purchase, it can be difficult to determine the type of buttons in the remote.

As you can see in the photo above, there is an off and on pad/button each for four channels of receiver. In my example we will only use two of them to save time and space. The next question to solve is how to interface the Arduino digital outputs with the remote control. In Practical Arduino, the authors have used relays, but I don’t have any of those in stock. However I do have a quantity of common 4N25 optocouplers, so will use those instead. An optocoupler can be thought of as an electronic switch that is isolated from what is it controlling – see my article on optocouplers for more information.

Four optocouplers will be required, two for each radio channel. To mount them and the associated circuitry, we will use a blank protoshield and build the Arduino-remote control interface onto the shield. The circuitry for the optocoupler for each switch is very simple, we just need four of the following:

As the LED inside the optocoupler has a forward voltage of 1.2 volts at 10mA, the 390 ohm resistor is required as our Arduino digital out is 5 volts. Dout is connected to the particular digital out pin from the Arduino board. Pins 4 and 5 on the optocoupler are connected to each side of the button contact on our remote control.

The next consideration is the power supply. The remote control theoretically needs 12 volts, however the included battery only measured just over nine. However for the optimum range, the full 12 should be supplied. To save worrying about the battery, our example will provide 12V to the remote control. Furthermore, we also need to supply 5 volts at a higher current rating that can be supplied by our Arduino. In the previous GSM chapters, I have emphasised that the GSM shield can possibly draw up to two amps in current. So once again, please ensure your power supply can deliver the required amount of current. From experience in my location, I know that the GSM shield draws around 400~600 milliamps of current – which makes things smaller and less complex.

The project will be supplied 12 volts via a small TO-92 style 78L12 regulator, and 5 volts via a standard TO-220 style 7805 regulator. You could always use a 7812, the 78L12 was used as the current demand is lower and the casing is smaller. The power for the whole project will come from a 15V DC 1.5A power supply. So our project’s power supply schematic will be as follows:

Now to mount the optocouplers and the power circuitry on the blank protoshield. Like most things in life it helps to make a plan before moving forward. I like to use graph paper, each square representing a hole on the protoshield, to plan the component layout. For example:

It isn’t much, but it can really help. Don’t use mine – create your own, doing so is good practice. After checking the plan over, it is a simple task to get the shield together. Here is my prototype example:

It isn’t neat, but it works. The header pins are used to make connecting the wires a little easier, and the pins on the right hand side are used to import the 15V and export 12V for the remote. While the soldering iron is hot, the wires need to be soldered to the remote control. Due to the unfortunate size of the PCB tracks, there wasn’t much space to work with:

But with time and patience, the wiring was attached:

Again, as this is a prototype the aesthetics of the modification are not that relevant. Be careful when handling the remote, as any force on the wiring can force the soldered wire up and break the PCB track. After soldering each pair of wires to the button pads, use the continuity function of a multimeter to check for shorts and adjust your work if necessary.

At this stage the AC remote control shield prototype is complete. It can be tested with a simple sketch to turn on and off the related digital outputs. For example, the following sketch will turn on and off each outlet in sequence:

Now to get connected with our GSM shield. It is a simple task to insert the remote shield over the GSM shield combination, and to connect the appropriate power supply and (for example) GSM aerial. The control sketch is a slight modification of example 27.2, and is shown below

The variable pressdelay stores the amount of time in milliseconds to ‘press’ a remote control button. To control our outlets, we send a text message using the following syntax:

Where a/b are remote channels one and two, and x is replaced with 0 for off and 1 for on.

So there you have it – controlling almost any AC powered device via text message from a cellular phone. Imagine trying to do that ten, or even five years ago. As always, now it is up to you and your imagination to find something to control or get up to other shenanigans.

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.

# Tutorial: Arduino and GSM Cellular – Part Two

Continue to learn about connecting your Arduino to the cellular network with the SM5100 GSM module shield. This is chapter twenty-seven of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.

Updated 02/03/2013

Assumed understanding for this article is found in part one. If you have not already done so, please read and understand it. In this instalment we continue with bare projects which you can use as a framework for your own creations.

Reach out and control something

First we will discuss how to make something happen by a simple telephone call. And the best thing is that we don’t need the the GSM module to answer the telephone call (thereby saving money) – just let the module ring a few times. How is this possible? Very easily. Recall example 26.1 – we monitored the activity of the GSM module by using our terminal software. In this case what we need to do is have our Arduino examine the text coming in from the serial output of the GSM module, and look for a particular string of characters.

When we telephone the GSM module from another number, the module returns the text as shown in the image below:

We want to look for the text “RING”, as (obviously) this means that the GSM shield has recognised the ring signal from the exchange. Therefore need our Arduino to count the number of rings for the particular telephone call being made to the module. (Memories – Many years ago we would use public telephones to send messages to each other. For example, after arriving at a foreign destination we would call home and let the phone ring five times then hang up – which meant we had arrived safely). Finally, once the GSM shield has received a set number of rings, we want the Arduino to do something.

From a software perspective, we need to examine each character as it is returned from the GSM shield. Once an “R” is received, we examine the next character. If it is an “I”, we examine the next character. If it is an “N”, we examine the next character. If it is a “G”, we know an inbound call is being attempted, and one ring has occurred. We can set the number of rings to wait until out desired function is called. In the following example, when the shield is called, it will call the function doSomething() after three rings.

The function doSomething() controls two LEDs, one red, one green. Every time the GSM module is called for 3 rings, the Arduino alternately turns on or off the LEDs. Using this sketch as an example, you now have the ability to turn basically anything on or off, or call your own particular function. Another example would be to return some type of data, for example you could dial in and have the Arduino send you a text message containing temperature data.

And now for a quick video demonstration. The first call is made, and the LEDs go from red (off) to green (on). A second call is made, and the LEDs go from green (on) to red (off). Although this may seem like an over-simplified example, with your existing Ardiuno knowledge you now have the ability to run any function by calling your GSM shield.

Control Digital I/O via SMS

Now although turning one thing on or off is convenient, how can we send more control information to our GSM module? For example, control four or more digital outputs at once? These sorts of commands can be achieved by the reception and analysis of text messages.

Doing so is similar to the method we used in example 27.1. Once again, we will analyse the characters being sent from the GSM module via its serial out. However, there are two AT commands we need to send to the GSM module before we can receive SMSs, and one afterwards. The first one you already know:

Which sets the SMS mode to text. The second command is:

This command tells the GSM module to immediately send any new SMS data to the serial out. An example of this is shown in the terminal capture below:

Two text messages have been received since the module was turned on. You can see how the data is laid out. The blacked out number is the sender of the SMS. The number +61418706700 is the number for my carrier’s SMSC (short message service centre). Then we have the date and time. The next line is the contents of the text message – what we need to examine in our sketch.

The second text message in the example above is how we will structure our control SMS. Our sketch will wait for a # to come from the serial line, then consider the values after a, b, c and d – 0 for off, 1 for on. Finally, we need to send one more command to the GSM module after we have interpreted our SMS:

This deletes all the text messages from the SIM card. As there is a finite amount of storage space on the SIM, it is prudent to delete the incoming message after we have followed the instructions within. But now for our example. We will control four digital outputs, D9~12. For the sake of the exercise we are controlling an LED on each digital output, however you could do anything you like. Although the sketch may seem long and complex, it is not – just follow it through and you will see what is happening:

And now for a video demonstration:

So there you have it – controlling your Arduino digital outputs via a normal telephone or SMS. Now it is up to you and your imagination to find something to control, sensor data to return, or get up to other shenanigans.

If you enjoyed this article, you may find this of interest – controlling AC power outlets via SMS.

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.

# Tutorial – Arduino Uno and SM5100B GSM Cellular

Shield is now obsolete. Contact your hardware supplier for support.

# Breaking up an automatic room deodoriser – round two

Again we attempt to break down an automatic room deodoriser.

Updated 18/03/2013

Today we are going to tear down another automatic room deodoriser. Why? Well the first attempt beat me, so it was time to even the score and try again with another type. The supermarket had the following units for \$7.99, which seemed a little too cheap:

The “satisfaction guarantee” gave me a chuckle, the thought of writing to SC Johnson complaining that their products were not that hackable would be interesting. But would it be hackable at all? Let’s find out. The packaging promises a squirt of scent when the unit detects motion, then holds out for 30 minutes until the next release. The word motion hints that there would be a PIR inside the unit. However the instructions mention that the unit does not work that well in dark or bright rooms – which is odd, as PIRs usually work in the dark. Hmm. This unit is somewhat smaller than the previous attempt, yet still offers us a pair of alkaline AA cells:

Moving on, time to start the disassembly process. The rear shows four screws, easily removed:

revealing the fun things:

The motor drive is reduced twice, which then has a geared arm which causes the vertical motion to pressure the cylinder to release the scent. The whole mess of gears was lubricated generously, the whole lot literally came out with the touch of a finger. Removing the gears and goop reveals the motor and control boards, which clipped out easily:

Interesting – a labelled motor. Very good, what looks like to be a 3V DC motor. The control board is made up of two PCBs, a smaller module that holds a control IC of some sort, and the larger, lesser-densely populated board with the button, status LED and “motion detector”. Let’s have a close-up of that PCB:

So we have the button, which causes the motor to run; a yellow LED which blinks once every five seconds; and out motion detector in the black casing. The motion detector seemed rather familiar, so I removed the black housing around it with some pliers, which revealed this:

Huh – that looks just like an LED. The metal object inside the clear casing was even identical to what you would see inside an LED. However, foolishly I broke it off the PCB when removing the housing, so could not get any voltage to it. From reading the instructions earlier on – that mention the light/dark issue, causes me to ponder if this is some sort of light-dependent sensor?

No – it is a photodiode! However the motor looked quite worthwhile. Curious to see what is driving it, I hooked up Mr Fluke to see what happens:

No surprises there, almost three volts DC forward voltage. After applying forward current the circuit applies a quick reverse current to release, thereby causing the gears and arm to ‘squeeze’ down on the scent cylinder. So now we have a circuit board that runs on 3V, which can output 3V for a few seconds every 30 minutes – or at the press of a button.

With regards to current, another measurement was taken:

When free-running, the motor draws around 45 milliamps – and the stall current (that is, the current drawn when I force the spindle to stop) is around 675 milliamps. That is quite a strong little motor, and worth the effort. In general, this has been a good tear down, we scored some AA cells, a good motor and gears, some stink spray, and a timing circuit that could have uses elsewhere. So overall a win – the score has evened with the deodoriser world! High resolution photos available on flickr.

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.

# Breaking up an automatic room deodoriser – part one

In this article we attempt to break down an automatic room deodoriser and have some fun.

Updated 18/03/2013

[Update – we won round two]

Today we are going to tear down an automatic room deodoriser. Why? Why not! After walking around the supermarket as one does, pontificating over the need for doughnuts – I noticed this package on sale for eight dollars:

What grabbed my attention was the words “movement sensor” and the price tag. A sensor by itself can cost more. Where’s the catch? I am sure the company makes their money back from selling the refills, in a similar method to ink cartridges and razor blades. Good for them. However, perhaps this can be good for us! So into the basket and home it came. My flatmates thought it was a lovely gesture to have one in the hallway. Hah! As Dave Jones would say, “don’t turn it on – take it apart!” So let’s go…

The can of spray went straight into the WC, nothing of interest there. Three alkaline AA cells were included:

Well that’s a good start, you can always use these in a camera or something else. Armed with a philips-head screwdriver and a pair of needle-nosed pliers, the entire assembly came apart very easily and without force. I must congratulate the designers, you almost get the feeling that this is designed to be repaired if broken, and not replaced. The process of disassembly was quite easy:

The front cover came off quite easily. The switch on the right enables/disables the movement sensor; the LED indicates the repeat mode for the spray; and the black switch controls the duration between sprays – off, 9, 18 or 36 minutes.

After removing the rear panel with four screws, we can see the motor and one of the two PCBs. Two more screws, and we can remove the electronics and mechanical sections:

This is the front-facing part of the motor board. The motor turns one direction then another to have the plastic ‘finger’ push down and release on the aerosol can nozzle. The gear ratios are quite large, allowing the motor to exert quite an amount of torque. The metal base board has some convenient mounting holes as well, so this could be reused easily. If you had a pair of these you could drive something that is quite heavy at a sedate speed.

Here is the main controller board, with nicely colour-coded JST connectors for leads to the motor, power source (those 3 x AA cells, 4.5V) and to the switch that turns the sensor on and off. The underside is very professional, all SMD:

The motion detector’s board plugs nicely into the main board, thanks to the 2×9 pin header and socket arrangement:

Now it is time to see how things work. The first step will be the motor – how much voltage and current does it use? I ran the motor without a load for thirty minutes at 4.5 volts DC – the  motor body did not warm up at all, a good sign that this voltage was suitable. With regards to current, there are two measurements to take – current while free-running, and under maximum load (i.e. feeding the motor 4.5 volts while holding the gears still). While free running, the current drawn was 34 milliamps:

… and when I held down the gears so the motor could not turn, the current drawn was 305 milliamps:

So now we have a nice strong motor that can run at 4.5 DC, and draws between 34 and 305 milliamps. That’s a good start. Furthermore, being able to stick the meter display to the desk lamp really makes life easy. Now it is time to investigate the detector. It had a few codes on the PCBs, such as KT-7964, Smart Motion A-06 and RB-S04 which I searched for on the Internet without any luck.

So the next thought was to feed it 4.5 volts DC, and use the Scanalogic2 to analyse any signals or voltages around the PIR sensor module to see what happens. However, the entire system was dead, it would not do a thing. The same problem occurred at four volts DC. No luck either. After the initial power up, the unit should light the LED for one second, then activate the motor for a “first spray” – but nothing. Hmmm.

So at this point we are at a brick wall, however this is not the end. Research will continue to look for details of the PIR unit, and once it is working independently a new post will be published.

This article also shows to me and others that not everything is a success first time. It can be disappointing, however it’s not the end of the world. With every failure comes knowledge which can be used the next time around. So subscribe to the web page updates, and keep an eye out in the future. High resolution images are available from flickr.

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.