Project by Calin D. Raszga

I always had a fascination with children’s toys and how they can be modified, rebuilt or changed – in a word “hacked”. Visiting the local thrift stores is a cherished tradition that I still enjoy my dad. Our target is picking out old remote control toys so we could rewire them and build custom robots.

What we found

Recently I found a Power City Trains set at my local “Once Upon a Child” store. It had an engine, a few rail cars and a LOT of track pieces. However, it was missing the Infra-Red remote control transmitter that came with the set. For $10 it was still a good buy.

After mechanical disassembly of the engine, the following was found inside:

  • A DC motor linked to a transmission for propulsion.
  • An LED with an in-line resistor – the Headlight.
  • Battery tray for 3 AAA batteries.

The original circuit board was no help. The micro-controller was covered by epoxy and the IR receiver didn’t display a part number. The whole original circuit board had to be scrapped for parts and something new had to replace it.

As usual, the plan was to use whatever I had around while still being frugal with my parts. The determining factor for the whole project would be the IR remote. Digging through the drawers I found some old remotes from car stereos. Specifically I found a Pioneer QXE1047 that I had already labelled “40 kHz”. This would be the carrier frequency. If the remote was not labelled, the carrier would have to be determined. We have written a good Mini-Talk on this subject. Read it Here.

How we rebuilt it

Before any of the setup can be done, the output of the IR receiver has to be understood.
This will drive many of the peripheral setup decision later. The simplest way to do this is to wire the receiver, in our case TSOP34840, to a power supply and an oscilloscope as per the datasheet. While pointing the remote (QXE1047) at it, repeatedly press the same button. While doing this with one hand, use the other hand to adjust the oscilloscope so that a single period of the transmission is caught on the screen. This may take a few tries at first. Use the RUN/STOP button to freeze the frame when it is satisfactory. The result should be something very similar to the picture below:

From the above picture the following can be roughly deduced:

  • Every transmission is around 90ms long.
  • Every transmission starts with a 8.5ms “low” state followed by a 4ms “high” state.
  • Every transmission has 32 individual data bits.
  • The spaces between the bits are even so the value of the bit is determined by their width. This points clearly to Pulse Width Coding as per Vishay 80071.pdf
  • The bits that are to be interpreted as a “1” are about 1.5ms long.
  • The bits that are to be interpreted as a “0” are about 0.5ms long.
  • The end of the transmission is marked by a “high” period of 20+ ms. This can be considered a STOP or INTER-SPACE area.
  • Note: Care must be taken to ensure repeated and continuous presses of the same button yield the same result. Some remotes have an internal protocol where if a button is kept pressed, the output alternates between the real code and a “neutral” code in order to create a “de-bouncing” effect. This behaviour was observed on the “DISP” button on the QXE1047 remote. The real risk is that other buttons may use the same “neutral” code in which case serious confusion can ensue. These buttons were avoided in this project for the sake of simplicity.

Let’s map the buttons we want to use on this remote:

Buttons to be used are as follows:

  • Volume Minus – Slow Down Motor.
  • Volume Plus – Speed Up Motor.
  • AUDIO – Toggle HeadLight.
  • SRC – Start Motor (PWM = 85%).
  • PAUSE – Stop Motor (PWM = 0% ).

It was now time to draw a schematic for the new electronics. With the space inside the engine being quite limited, a small circuit board had to be built for the PIC and the MCLR resistor. No programming port was to be permanently installed. The programming would be done by soldering directly to the PIC pins from above then removing the leads when programming is complete. A socket could not be used because there was no vertical space for it inside the engine

  • RA2 was chosed for input from the IR receiver. This pin has a hardware interrupt attached.
  • RC1 was chosen for controlling the LED headlight.
  • RC2 was chosen for the PWM output. This pin has a special PWM feature.
  • RC0 was chosen to be used as a debug pin in case of interrupt problems.
  • RC4 was assigned as Serial TX for debug purposes.
  • RC5 was assigned as Serial RX for debug purposes.
Schematic of rebuilt PowerCity Engine

Note: The motor already had a diode across the terminals that was built in, which is the reason why we haven’t included it in the above print.

With the hardware more or less sorted out, it was time to develop new software for this unit. Programming was done in MPLABX and the project is made available below. We encourage you to look through it for ideas that can be integrated into your own projects.
MPLabX Project

Finally, with the software written, we took a video of the rebuilt train set. Enjoy.