SANTA ONE was fun but I didn't do much hacking with it so I thought I needed a SANTA TWO too, and possibly (time permitting) a SANTA THREE.
So for SANTA TWO : The Diorama, I decided to implement a Christmas Themed animated (automated?) display. Recently I purchased a remote controlled train for a well known wooden railway system from a well known shop (that rhymes with middle) as they seemed well cheap at £10 each. So cheap and fun that I now have three and I am having trouble restraining myself from purchasing more.
For the diorama scenery I just happened to have a longish thin piece of MDF and I used my newly acquired table saw to cut some 'ruts' into. I used an older train with manual controls to sort out the track width, depth and roundness as I didn't have any proper track. After many hours of fettling and sanding I managed to create a suitable track. I had some white pain so I painted it white - very Christmassy. I also visited a local craft store and purchased some wooden trees: some small, some medium sized (some were already painted white and black but some were unpainted so I sprayed them green - as I had some green paint), as well as some larger trees containing the letters MERRY CHRISTMAS cut into them. With my pillar drill I drilled holes for the medium sized trees, used hot glue for the small trees and BlueTac for the large trees and fixed everything together. It needed some lights and I had some LED strip rescued from a broken bathroom mirror cabinet which still had a sticky back so I just fixed these onto the edge of the train track. The result of all this hard work is shown below.
As trains run on tracks the RC part is fairly simple as no steering is required, just forwards and backwards controlled using infrared, plus the trains have lights and sound (very irritating after a while). I thought that I might be able to generate the IR signals directly from an Arduino but after some investigation I decided not to, there just wasn't enough time to work out the encoding used. Maybe a project for another day. Instead I soldered wires to the control button connectors and used the Arduino to generate the correct signals. I soldered wires directly onto the switch contacts on the controller PCB to make wired AND connections. The switches are active low and are normally high so with both the controller switches and the Arduino HIGH the control signal to the internal microcontroller is also HIGH and nothing happens. If either the controller switch or the Arduino (or both) go LOW the microcontroller input also goes LOW activating an IR output sequence. So either the controller or the Arduino can create the signals - very useful for testing. The RC controller uses 3V signals (2 x AA batteries) whereas my Arduino Nano is 5V so I used a simple resistor divider chain (3K3 and 5K1) to drop the Arduino 5V voltages to the RC controller's 3V. A sort of block circuit diagram is shown below:
The RC controller has an unusual operation. A short forward (or backwards) movement just activates the 'whistle, a slightly longer forward push also causes the train to move forward but if you then stop pushing forward the train stops. If the controller is pushed forward and held for over one second the train whistles, starts moving and continues moving until the reverse operation (backwards) is briefly operated, at which point it stops. It is not intuitive but you get used to it after a while.
The programme is a bit of a mess as I am still fiddling with it but essentially I just get the train to go forward for two seconds, stop and then go backwards for two seconds and then stop. When you watch the video you will see an initial backwards movement followed by the two programmed movements. This something to do with the Arduino Nano as after a reset all the outputs are forced LOW for two seconds which activates the train. A bit irritating but hey, it is a Hack.
Below is this control sequence:
delay(1000);
tbackward();
delay(2000);
tbackstop();
delay(2000);
tforward();
delay(2000);
tforstop();
while (1) { /* do nothings */ }
I used functions to create the sequence for each individual command, which are listed below.
void tforward(void)
{
digitalWrite(trainforwards, LOW);
delay(1500);
digitalWrite(trainforwards, HIGH);
delay(100);
} /* tforward */
void tbackward(void)
{
digitalWrite(trainbackwards, LOW);
delay(1500);
digitalWrite(trainbackwards, HIGH);
delay(100);
} /* tbackward */
void tbackstop(void)
{
digitalWrite(trainforwards, LOW);
delay(100);
digitalWrite(trainforwards, HIGH);
delay(100);
} /* tbackstop */
void tforstop(void)
{
digitalWrite(trainbackwards, LOW);
delay(100);
digitalWrite(trainbackwards, HIGH);
delay(100);
} /* tforstop */
The video below shows the train working with the diorama. The controller LED must be pretty powerful as there is no direct line-of-sight to the train and I had the LED strip on and the room light. A very impressive bit of design for a low cost toy.
All in all, I think it works pretty well. It doesn't tremble (as in the title Simple And Neat Trembling Autonoma) but in my defence, the train I was using for the initial design of the track definitely trembled but the IR controlled train didn't!
Right, so if I can find enough time I have a plan for SANTA THREE. It might work!
Dubbie