About two weeks ago, I finally bit the bullet and retired my trusty iPhone 3G, and went to the dark bright side, with an Orange San Francisco (also known as the ZTE Blade). At £99 (including a compulsory £10 Orange topup) it can be SIM unlocked for free and flashed to Froyo 2.2 with a variety of ROMs.
But despite a incredible take up by punters everywhere, the lack of handset accessories is frustrating. Until recently we couldn’t even get an OSF specific screen protector, let alone a protective cover. And still we can not buy a desktop charger that fits!
And so, when a colleague was unpacking a toner cartridge and I spotted the polystyrene padding material, I thought, why not bodge one myself?
Santa this year was very generous to my son and gifted him with a Maverick Atom XT RTR 1/18 Electric 4WD Truggy but failed to mention that the batteries that came with it could only be left in the charger for 6 hours, no longer. With grave warnings about explosions and fire, I tried to find an egg-timer on a socket kind of solution, but could not find anything that would go beyond 4 hours.
So what is a tinkerer to do? He makes one himself! ;)
A long time ago I bought an Arduino, but never really got any further with it than a blinking RGB led. Now I finally found a purpose for it :) I was going to build an Arduino controlled timer socket!
First a small word of warning. You are dealing with MAINS voltage, which can be lethal if you fool around. DO NOT EVER! connect the bits to mains power when parts of it are exposed. You’ve been warned
I started off with a small mockup of materials and then got my trusty Dremel clone out and started cutting away at the project case.
First off is the socket in which the battery charger can be plugged. A small template on paper is by far the easiest way to make sure you don’t cut out too much behind the socket
With the socket in place, I created the template for the LCD. I took my time with this, as I didn’t want to cut out too much. A lot of careful sanding ensured that only the black part would be visible, and nothing else. Then with the help of some small bolts and nuts, I created some spacers, enabling the LCD to sit nicely in the cutout. Lots of hotglue completes the mounting
The buttons only required some measuring to make sure they are neatly symetric and do not interfere with the LCD
All that remains is the IEC socket where the power will go into the project box
Now with everything in place, all we need to do is connect the components together with some wire using the below schematic
Warm up the soldering iron and just follow the diagram. As my soldering skills are not that great, I also used a bit of heatshrink here and there to make sure that wires could not short on each other :)
I’m using an old iPhone charger to power the Arduino as it provides a neat 5V/1A, with a small retractable USB lead with a Type A to B converter. A quick test of the wiring to make sure it all works as planned
Now with construction over, it was time to do the Arduino coding. The LCD uses the LiquidCrystal I2C library which takes care of all the hard work interfacing to it. Likewise, the Metro library takes care of the timer. So, it is just a simple case of increasing the clock by an hour every time the red button is pressed, and starting the timer when the green button is pressed. Once the timer is running, any button press will stop the timer and reset the state to the beginning.
// Arduino controlled timer socket// (CC BY) 2011// http://awooga.nl// pull in libraries#include <Wire.h>#include <LiquidCrystal_I2C.h>#include <Metro.h>// arduino pins constants#define RELAY 2 // black wire connected to input on shield#define RED 6 // green wire#define GREEN 7 // white wire// i2c pin A5 = white wire// i2c pin A4 = green wire// allow between 1 and 6 hours#define MINIMUM_TIME 1#define DEFAULT_TIME 6#define MAXIMUM_TIME 6constunsignedlong MILLISECONDS=1;constunsignedlong SECONDS=(1000*MILLISECONDS);constunsignedlong MINUTES=(60*SECONDS);constunsignedlong HOURS=(60*MINUTES);constunsignedlong DAYS=(24*HOURS);constunsignedlong UNITS=HOURS;// prgram states#define IDLE 0#define RED_BUTTON 1#define GREEN_BUTTON 2#define MENU 3#define PAUSE 4#define STOP_TIMER 5#define CANCEL_TIMER 6// global variables
byte events;
byte countdowntime;
boolean menu_running;
boolean timer_running;
boolean debug =false;
byte currentRed = LOW;
byte currentGreen = LOW;
byte previousRed = LOW;
byte previousGreen = LOW;// set the LCD address to 0x27 for the 16x2 display
LiquidCrystal_I2C lcd(0x27,16,2);// initiate Metro object
Metro relayMetro = Metro(0,true);// arduino setup routinevoid setup(){// set the arduino pins
pinMode(RELAY, OUTPUT);
pinMode(RED, INPUT);
pinMode(GREEN, INPUT);// initialise the lcd
lcd.init();
lcd.backlight();// activate debugging on the serial portif(debug){
Serial.begin(9600);
Serial.println("Lets go!");}// initialise variables
events = IDLE;
countdowntime = DEFAULT_TIME;
menu_running =false;
timer_running =false;
digitalWrite(RELAY, LOW);}// arduino loop routinevoid loop(){switch(events){case IDLE:
events = Idling();break;case MENU:
events = MainMenu();break;case RED_BUTTON:
events = RedButton();break;case GREEN_BUTTON:
events = GreenButton();break;case PAUSE:
events = Pause();break;case STOP_TIMER:
events = StopTimer();break;case CANCEL_TIMER:
events = CancelTimer();break;default:
events = IDLE;break;}}int MainMenu(){if(timer_running){return IDLE;}if(menu_running){return IDLE;}if(debug){ Serial.println("MainMenu()");}
lcd.clear();
lcd.print(" Red: Set time");
lcd.setCursor(0,1);
lcd.print("Green: Go (");
lcd.print(countdowntime, DEC);if(countdowntime ==1){
lcd.print("hr)");}else{
lcd.print("hrs)");}
menu_running =true;return IDLE;}int Idling(){
boolean do_red =false;
boolean do_green =false;if(timer_running){if(relayMetro.check()){return STOP_TIMER;}}
currentRed = digitalRead(RED);
currentGreen = digitalRead(GREEN);if(currentRed != previousRed){
do_red =(currentRed == HIGH);}
previousRed = currentRed;if(currentGreen != previousGreen){
do_green =(currentGreen == HIGH);}
previousGreen = currentGreen;if((do_red)&&(!do_green)){return RED_BUTTON;}if((!do_red)&&(do_green)){return GREEN_BUTTON;}// all other button combinations are ignoredreturn MENU;}int RedButton(){if(debug){ Serial.println("RedButton()");}if(timer_running){return CANCEL_TIMER;}if(++countdowntime > MAXIMUM_TIME){ countdowntime = MINIMUM_TIME;}
lcd.clear();
lcd.print("Time set to");
lcd.setCursor(0,1);
lcd.print(countdowntime, DEC);if(countdowntime ==1){
lcd.print(" hour");}else{
lcd.print(" hours");}
menu_running =false;return PAUSE;}int GreenButton(){if(debug){ Serial.println("GreenButton()");}if(timer_running){return CANCEL_TIMER;}
lcd.clear();
lcd.print("Running timer");
lcd.setCursor(0,1);
lcd.print("for ");
lcd.print(countdowntime, DEC);if(countdowntime ==1){
lcd.print(" hour");}else{
lcd.print(" hours");}unsignedlong t = countdowntime * UNITS;
timer_running =true;if(debug){
Serial.print("Setting metro for ");
Serial.print(t);
Serial.println(" seconds");}
relayMetro.interval(t);
digitalWrite(RELAY, HIGH);return IDLE;}int StopTimer(){if(debug){ Serial.println("StopTimer()");}
digitalWrite(RELAY, LOW);
lcd.clear();
lcd.print("Timer finished");
timer_running =false;
menu_running =false;
relayMetro.reset();return PAUSE;}int CancelTimer(){if(debug){ Serial.println("CancelTimer()");}
digitalWrite(RELAY, LOW);
lcd.clear();
lcd.print("Timer stopped");
timer_running =false;
menu_running =false;
relayMetro.reset();return PAUSE;}int Pause(){
delay(1000);return IDLE;}
Obviously you can go all crazy with options and clocks, but I just wanted something quick and working. Changing the code to do all that is just a matter of opening it up, and uploading the new software.
And just to prove it is all working, here’s a small video demonstration. It doesn’t show the timer ending, you just have to take my word on that :D
Who doesn’t have a multitude of devices, phones and other gadgets on their desks? I certainly have, and I finally had enough of all the chargers and wallwarts that each item seems to bring with them. With two iPhones almost constantly being charged, and a Nokia phone thrown in for good measure, I needed to have something flexible enough for those plus any future gadgets. So, I googled a bit, and found the IDAPT I3, and the beautiful, but ridiculously priced The Sanctuary. And then I started to think, how easy would it be to put a mains powered USB hub inside a box and have several USB charger leads coming out of the box, each charging a different device?
And the answer is, very easy :)
I started off with a 4 port powered USB hub, which I had lying in a drawer and plugged my iPhone charger leads into it, expecting them to instantly charge my two iPhones. But to my surpise, nothing happened… so another quick Google later, I came accross a blog entry of Carl Hutzler, which details why they won’t charge. All you have to do is sacrifice the hub and forego it’s PC functionality by cutting the D+/- lines and short them. A quick test shows they now finally charge themselves. Apparently it is better to stick 2x 100K Ohm resistors on the D+/- lines, which I will do at some point, but for now, this will do.
All I now had to do was find a suitable SWMBO friendly container, and as our furniture is all beech, the tea storage container I found for £1.99 at QD stores was perfect. I just needed to gut the compartiments out and put something on top of the plastic lid. At my local crafts store I found a small foam pad for 50p which was nice and soft. Unfortunately I got my measurements all wrong, so I messed up the black pad, but SWMBO came to the rescue by rummaging through my kids crafts drawers by digging up a piece of brown padding.
The final thing to do is then drill some holes at the locations convenient for your devices, and put it all together. Job done!
It’s been 4 long years since I last bought an Apple. But today I took delivery of a nice shiny Macbook Unibody \o/
Glad to be back again
Update 11.06.2009
Just typical… 11 days after I received mine, Apple announces the new 13″ Macbook Pro’s at the Worldwide Developers Conference… I phone the Apple Store the next day to see if I can exchange it for one only to be told that I would have to return and re-order. So I did. Only to receive a new Macbook Pro today on my old order, whilst my new order is now in ‘Prepared for Shipping’, which means I can’t cancel it!
Guess I’ll be keeping the courier in business this month ;)