To get a feel for the ideas and evolution of this project, if you haven't already done so, please see this page, detailing the mark one wireless bike alarm.

This is a big page - please give it time to load. All photos are thumbnails - click on them for a larger view.

Since the construction of the first PMR based wireless alarm last year, I had constantly sought ways to improve it. The main issue was reducing the size of the unit, but other areas with scope for improvement included ease of activation, luggage loop connections and ease of removal for bike cleaning and service. I'd identified several issues with the previous design:

I was also unhappy with the rough nature of the construction  - I had proved the concept worked, but now was the time for more elegance in the solution.

For a few months I scoured all available channels looking for alternative PMR sets to base the new alarm upon. I originally thought the Entel Eurowave would be the natural choice - but obtaining information despite a rather unhelpful attitude from Entel indicated that their product was so basic that it had no 'call' feature - as this was central to the design, and not really having thought about the practicalities of circuitry yet, I ditched the idea. I knew that any design I would come up with would have to be quite different to the last one - all the small radios were fitted with soft-off power controls rather than the old fashioned rotary volume knob on the Binatone. This meant that whenever the alarm was activated, the control electronics would have to first simulate pressing the power button to turn the radio on. This was a concern, because I recognised that adding another analogue timer would make the circuitry bulkier, and possibly outweigh the advantage of using a smaller radio. Discussing the idea with friends, and following a suggestion on a newsgroup, I had the idea planted in my head of using a PIC microcontroller to control the radio.

PIC's have been around for a long time - I'd learned about them at college. A PIC, or programmable interface controller, is a small, self-contained microprocessor, complete with memory and all the components of a functioning embedded control system in one tiny package. They have a number of general purpose pins which can be assigned as either inputs or outputs, and a simplified, minimal instruction set which can be manipulated to undertake a huge variety of control tasks. PIC's are programmed using a number of methods, and to learn more, I picked up a couple of books. Programming the PIC itself is usually undertaken by writing the code as a text file on a PC, assembling or translating it into a hex file, and then using a software package to transfer the assembled code to the chip using a programmer. Commercial programmers can be purchased for about £150, but one of the books I purchased helpfully contained a circuit board upon which a useful PIC programmer could be constructed - together with a CD full of handy information and software. The two books I bought were McGraw Hills'  'Programming And Customizing PICmicro Microcontrollers'  by Myke Predko (that's the one with the freebies), ISBN 0-07-136172-3  and the smaller, but slightly more useful book published by Newnes 'PIC - Your Personal Introductory Course 2nd Edition' by John Morton, ISBN 0-7506-5038-9. Reading these books, I learned that although at first daunting, PIC's were easy to use and were ideally suited to the task at hand.

As it was again the season of radio rallies, I pottered along to Drayton for the annual MARS rally, where I'd bought the Binatone sets 12 months previously. Originally intending to buy parts to build the PIC programmer with, I came back with some bargain PMR sets, but more on that later. I got the parts I needed, as well as a few PIC16F84's - an 18 pin example of the PIC. When I got home construction of the programmer commenced.

Programming And Customizing PICmicro Microcontrollers by Myke Predko. Weighing in at a hefty £37, it came with the circuit board and a CD full of software. A very authoritative work, with loads of good info. PIC - Your Personal Introductory Course 2nd Edition by John Morton. At £13, much cheaper, and easier to grasp the basics from... I considered both books essential. The completed programmer. Costing no more than £20, it connects to the PC via a serial port, and is operated by software on the supplied CD. The most expensive bits were the lead and power supply... The PIC 16F84 - just over twice the length of the chip used in the previous alarm, but millions of times more powerful.

I played around for a while, my first programs mainly involving counting and turning LED's on and off. Unlike earlier PIC's, the 16F84 was a re-writable device - many of the earlier microcontrollers were writable once only. This meant that once programmed, the only thing to do if there was a bug was to throw the chip away and crack open another. The fact that the 16F84 was reprogrammable gave me a little more freedom. I was soon reasonably confident programming for the PIC, and assembled circuits solderlessly on breadboard.

The bargain PMR sets I acquired were Telcom TE200's. I got 4 customer returns for a minimal sum - I think £8 for the four. I had originally intended to base the new design on a pair of ICOM 446S radios - about £80 each, but on seeing the Telcoms, I couldn't resist them. They were tiny, and appeared to have a whole raft of features. What was particularly interesting was the fold-down antenna they were fitted with - it looked removable and suitable for re-mounting on another enclosure. I knew that I wasn't going to get four good radios - I only needed one. Rooting carefully through the selection, I bought one evidently water damaged, one whose antenna had been broken off the main housing, one unspecified casualty and one with a melted battery contact. Trying them with batteries (these were 6v devices - another plus) I found 2 worked straight away, the water damaged one was dead, and the burn out needed new contacts... not bad for a day's haggling.

No time was wasted as I stripped one down.

This tiny wonder is a Telcom 200. It packs a full-power 446 PMR with CTSS, adjustable squelch and even a FM radio. The antenna swivels down beside the belt clip when not in use. The radio takes 4 'AAA' batteries. On stripping the unit down, the antenna was found to be removable - held in place by a claw washer and 4mm nut. The swivel was provided by a mechanism within the antenna. The electronic module came away easily in one chunk - the antenna, speaker and battery compartments being connected by spring contacts
The module was found to be covered by a screening can at the rear. It appeared to be sturdy and rigid. I also noted the four fixing holes - handy for mounting... The lower portion looked eminently suitable for mounting my electronics on. This picture shows the side mounted PCB with the call and PTT button contacts. The antenna terminal - all that connected it to the external aerial was a steel spring pushed on the post on the back of the case fixing. Helpfully (!) Telcom had provided fairly large, bare test points around each pushbutton contact - ideal for soldering small wires to.

I started thinking in depth about circuits. I knew I could program the PIC to turn the module on, and to press the call button for a time period. An issue I also faced was that the Telcom had no range check feature - I used this on the Binatone to alert me if the alarm went dead or I went out of contactable range of the bike. As I intended to continue using the MR500 as a receiver, I wanted to solve the problem. Experiments with a working Telcom indicated that all the Binatone was doing was broadcasting a very short burst of RF on the selected channel at close intervals. Replicating this behaviour on the Telcom by pressing PTT quickly was adequate to make the Binatone think another was in range. The Telcom's have an annoying 'feature' in that they add a short beep to the audio on release of the PTT key... until I had better means of experimentation (shorter duration PTT pulses from the Telcom) I was disappointed to discover that the beep was audible on the Binatone... quite a problem. Normally the radio sits in silence, only making a noise on the reception of stray bursts of RF or when the alarm went off - the idea of the unit sat there beeping was unacceptable.

Before I could experiment, I needed to come up with a suitable way to interface the PIC to the radio module. The relay I had used on the original alarm was good, but too bulky, and quite noisy. The idea of turning the alarm on to be met with a cascade of clicking put me off the idea. Poking around the circuit with a multimeter I found that the buttons (on the Telcom, they are all 2 contacts) merely shorted a line floating at about 3.8V to ground. This was confirmed by a circuit diagram of a Telcom 150 I found on the net... see here (PDF document, Adobe Acrobat required). Now my circuitry was going to be running at 6 volts, and it was tempting to just connect a PIC output straight onto the 3.8volt line - after all, both the radio and the PIC would share a common ground. Keeping the line high and then dropping it (i.e. outputting 0,lowering it to ~0 volts) would be equivalent to pressing the button. I was, however, worried that the radio would not stand such a positive voltage, and after no little consideration came up with the concept detailed in the diagram shown.

The idea was to add a small signal diode in line between the PIC output and the radio. The diode would conduct from the radio into the PIC output, thus blocking the voltage rise from the PIC when the output was high, and conducting to ground when the output was low. The solution appealed because there would be no delay in action (as caused by a relay), it would be silent and totally reliable.

I tested this theory carefully by soldering a wire from the pushbutton input, through a diode, and touched the ground terminal. The radio saw the button as being pressed. I touched the wire to the +6v supply, and measured the voltage on the pushbutton contact - still 3.8 volts. I tried it on the power on, call and PTT buttons, and they all worked. My main concern was that the voltage rise on the radio pushbutton line would not be great enough to prevent the radio from seeing the action of the PIC, and to my surprise, found that 3 diodes in series could be added giving a voltage drop of just over 2 volts. It seemed I'd found a solution.

The next step was to consider the first steps in the programming of the PIC. In simplified terms what it needed to achieve is detailed in the flowchart illustrated. I discovered through experimentation that the radio, when energised, needed a second or so to settle and boot when power was applied before hitting the power button, otherwise it would be ignored. I also found that the device exhibited peculiar 'key rollover' properties', in that when one button was pressed, small pauses had to be allowed for otherwise no response would be elicited.

It would be far too lengthy to enter into the minutia of microcontroller programming here, for anyone interested in the subject I recommend a number of sites, the links to which can be found at the bottom of this page. I intend to approach the discussion of the program in general terms, and anyone wishing to know more about the program can mail me here.

The general intention was to start the radio, and then enter a loop of pressing PTT and pausing, to maintain contact with the receiver. The alarm conditions (vibration, luggage loop) would be continuously monitored and any activity detected would lead to the suspension of the loop and the alarm procedure being executed. Along with the signal outputs to the radio, I'd decided to use a single, 2 chip LED for indication purposes and assign a couple of inputs, one for the vibration switch and one for the luggage loop.

Inside the PIC, the 13 general purpose pins it provides are divided into one group of 5 (port A, labelled RA0 to RA4) and one group of 8 (port B, labelled RB0 to RB7). Any pin in any port can be assigned as either an input or an output, and these can be read from or written to at any time. Pin RB0 and pins RB4 to RB7 have an extra function, in that they can be programmed to cause interrupts when used as inputs.

The best way to achieve my goal of monitoring the alarm conditions was to use interrupts... interrupts are a facility on the 16F84 that can be used to halt current program execution, and start executing another portion of code. Providing the interrupt has been handled correctly, when complete, the PIC will recommence exactly where it left off - in other words, execution has been interrupted for a more important task. On the 16F84, the two interrupts which were useful to me were INTF and RBIF - INTF occurs when a specific change occurs on pin RB0, and RBIF occurs when any one of the pins RB4-RB7 undergoes a change of state. I decided to attach the vibration switch to RB0 and the luggage loop to RB4. This took care of the inputs, and I decided to be tidy and assign all the port A pins to output functions; RA0 and RA1 were to operate the indicator LED and RA2 to RA5 were to operate the radio.

Writing the software for the PIC was no trivial task; I wrote it gradually over a couple of weeks. The main difficulty with writing PIC programs is that once written, one cannot necessarily tell what is happening when the program doesn't function - it's impossible to tell what's going on inside the chip. Thus fault-finding is a laborious and infuriating task. While programming, I tested the chip and software, as well as modifications to the circuitry, on solderless breadboard as I went along. Sometimes I found myself looking for programming faults that were actually circuit design issues...

I learned much about the Telcom in the process. Many of the pauses in the final program are required to allow the radio time to settle. One bug I found after final construction was that if the alarm was triggered during a range check pulse, because of the rollover issue, the radio would not send the call tone. It behaved like it did, but with no RF broadcast, even though the display said that was what it was doing. Inserting a pause at the start of the alarm interrupt before the call key was simulated solved that one.

It was while experimenting in this manner that I found out how the range check system on the Binatone's actually worked. As I have mentioned, any signal on the selected waveband was enough to keep the MR500 happy. What I couldn't work out experimenting by hand, was how come the radio didn't make a sound when it received an RF pulse from another Binatone. The answer became blindingly obvious while fiddling with the PIC program - as I shortened the range check pulse from the Telcom, the MR500 stopped making a noise. However, using another Telcom, I could still plainly hear a roger beep. When set in range check, the MR500 just suppresses the speaker for the first 400mS or so of reception. Broadcasting a very short pulse falls within this, so the radio doesn't make a noise. I was surprised a just how basic Binatone's solution was. But I was very happy to overcome the beep problem!

The source code for the finished program can be viewed by clicking here; this is the current version of the software completely annotated. Some modifications were made following construction, but I feel it's best to supply just one set of code. The reasons for the modifications will become clearer as you read on.

After what seemed like an age, I had a working circuit programmed and assembled on breadboard on the bench. Testing had eliminated all the issues I found, and I was happy to commence construction. I had overcome a number of issues - the unit was to be switched on and off using a magnet. The magnet would operate reed switches inside the case of the alarm, epoxied to the cover. To arm the device, a normally open reed was used - this fires the gate of a SCR which latches the circuitry into operation, the current consumed keeping the SCR switched on; and to turn off, a normally closed reed was inserted into the negative line to break the current, thus de-latching the SCR and turning the alarm off.

The 2 colour LED was programmed to display yellow when arming (both chips on at once), red when sending a range check pulse and green in an alarm condition. At this point I was using the radio without any form of antenna - I found the radio, strangely, performed well enough without one for testing purposes.

Diodes were soldered to the button inputs on the radio, and then leads connected to them. The leads were clipped up temporarily to prevent pulling The contacts for PTT and call were originally constructed by having a convex disc of metal laminated above them... the failure of the lamination and movement of the disc (removed in the above picture) is apparently a common fault on these radios. It can be seen here that the test point was an ideal soldering position. The white print with the brown stain (bottom left) is where the microphone was situated - I removed this to lessen noise from the PTT pulse. The assembled, working design constructed on breadboard. The components just push into conductive strips within the board. This rats' nest would simplify considerably later. 

It was at the point of the first construction I experienced the greatest problems. I actually built two alarms, abandoning the first due to difficulties. The first was built around the TE200 I had be experimenting with all along - I was over-confident in the program and glued the PIC to the rear side of the radio module, dead bug style, with other components mounted from the chip's pins, using the screening can as a ground and various leads and copper wires as bus bars. I had trouble mounting the unit in the selected enclosure, mounting the unit too far to the one end, and had to open the mounting holes; The LED, mounted underneath the module, obstructed it. Whilst the alarm worked, it was a disaster.

The enclosure I chose to use was just right to accommodate all I needed. The radio module was to be mounted using some small, insulated M3 spacers. The reed switches for turning the alarm on and off - they look huge, but in reality are 13mm long and 2mm in diameter. The first, doomed attempt. Note the large washers covering the opened mounting holes. At this stage I was planning to use screws for the luggage terminals. The PIC was glued upside down to the screening can. Note that some components have been removed for construction of the second device.
   
  Note the small chip device hanging from the PTT terminal on the bottom left - this is an optocoupler, added later  to aid fault finding. The silver component on the left is the crystal which provides timing for the PIC... in the next model I used a much smaller version. The SCR for switching the alarm on can be seen bolted to the cover at the bottom of the picture.  

Leaving aside the dimensional cock-ups, once I had the alarm built, I started to shake out electronic bugs. Occasionally, the transmitter would lose contact with the receiver, as if not range check pulse had been broadcast. Sometimes the alarm would turn on, but the module did not. As the days went by, the alarm would die after 10 or 20 minutes, the module being dead but the PIC still running. Sometimes the alarm would not go off if the bike was disturbed, or just switch off altogether. To say I was losing heart would be a major understatement. I just didn't understand why it all worked so well on the bench in breadboard but on fixing everything permanently it turned turkey...

My instinct told me to suspect the PIC program, however, due to the downright foolish way in which I had constructed it, I couldn't reprogram the PIC. I scoured the program's source code to try to find what was causing the issues, to no avail. I burned another PIC, and tried synthesising the same results with another module, but to no avail. It all worked perfectly. As time went on, I began to suspect the diode interface method - quite irrationally on reflection. I got hold of some opto-isolators to try and remove the link between radio and PIC.

Opto-isolators are small chips containing a LED and a variety of photosensitive switch. I chose a device called a photomos relay (RS stock no. 171-8623, data sheet available here, Acrobat reader required)  which behaves exactly like a relay, except it will only switch DC, has no moving parts, and comes in a tiny, six pin package. This device was capable of switching low voltages at extremely low currents, with no volt drop. I got hold of a few and tried them in the alarm. There was possibly a minor improvement, but it remained troublesome. I came to the conclusion that the only way to sort the design out was to rebuild it - I had begun to suspect the radio module. It was, after all, a customer return, and may have had some kind of fault all along.

I obtained replacement parts, took others from the previous unit, and then thought about construction once more. I needed a method of making the PIC removable for reprogramming, and generally making the electronics tidier and easier to modify. After some consideration, I got a piece of strip board, and instead of using it by pushing component leads through it and soldering on the reverse side, used it copper side up. This made mounting of the assembled board on the screening can possible by covering the underside with sticky plastic and gluing it down. I used a chip socket for the PIC. To be on the safe side, I used the photomos relays for all three pushbuttons.

The upside-down stripboard was cut to size and glued in place after assembly between the screw mounting holes. The opto-isolators were glued dead-bug style between the stripboard and the raised part of the module. The clear LED on top illuminates the unit when switched on giving it a pleasant glowing appearance. The PIC is easily removable from it's socket for reprogramming if required. The vibration switch was covered in heat shrink sleeving to insulate it form the adjacent components. The doomed luggage loop screw terminals became 2mm banana sockets - these can be used effectively with tinned wire ends. The screws holding the module were insulated from the board with fibre washers. The SCR is mounted underneath the radio module, the reeds glued in at the top and bottom of the case lid. The capacitors buffer the reeds should they operate momentarily. The resistor is for charge dissipation purposes.
The radio is wired in such a way as to allow removal to one side if necessary, as shown here. Some of the mounting pillars had to be filed to avoid fouling components on the PCB. The antenna links to the coil of wire by inductive coupling. I took a separate ground wire back for each optoisolator. The Telcom was certainly an easier unit to interface with. When assembled, excluding the antenna, the alarm measures just 110x60x30mm. It attaches to the rear of the carrier, and plugs into a power distribution box near the battery. The antenna folds down when not in use. The magnet to switch the alarm on and off with was eventually glued to the bike lock key. This meant I'd never leave home without it. The whole thing consumes surprisingly little power, and is shown here running off 4 'AA' batteries.

To my surprise, and not to mention suspicion, the second build worked fine. I did notice that there are at least two issues of the Telcom 200 module in circulation - the one I first used was a 'B' series (identified on the PCB); the second a 'C' series - there were component differences and the firmware in the radio was different - the 'C' series said 'Call' on the display when it was calling, whereas the 'B' version did not. One problem the change gave me was that the call tones between the units differed in duration. The B had a duration of 9 seconds and the C only 4... I ended up modifying the program to press call twice for each activation, as 4 seconds were barely enough to hear the alarm being activated. One side effect of using interrupts for the detection was that the luggage loop no longer needed to be shorted out when not in use. Since the interrupt the loop is connected to is activated by a change of state, it was a simple matter to make the alarm activate only on the PIC seeing a change from connected to disconnected - if the alarm is armed without the loop present, it will never experience the change of state required to activate the luggage alarm and consequently just trigger on the vibration alarm. Should the luggage loop be broken, the alarm keeps sounding until it's reconnected.

The final circuit is shown below.

(Clicking on the diagram will open a larger, more legible version in a separate window)

I notice that I still have issues with surplus 10K resistors...

The alarm mounts unobtrusively on the rear of the carrier. In this position it picks up the vibration of the bike more efficiently than the first design. The elevated position also seems to improve the range of the signal. The fold down aerial is resistant to knocks and doesn't interfere with the fit of the camera case onto the carrier. The power distribution box  mounts onto the carrier bracket screw and provides convenient 2.5mm power sockets for all the electrical devices on the bike. The unit is easily removed from the bike for cleaning... two 6mm hex head screws are fixed into the case (threaded in and sealed with epoxy), and these are counter bored and threaded for 4mm mounting screws.  The hex heads stand the housing clear of the carrier, and provide a strong, flat mounting surface.

And that's about the size of it. In total, I spent about 3 months working on the alarm - not solid work, but hours here and there. Performance has been solid since the second build, and freinds and acquaintances find the concept and size remarkable. The range is good, and the position is far less intrusive.

Mission accomplished!

In conclusion, I'd like to thank Clive Roberts for continually listening to me expounding ludicrous theories and talking utter rubbish, and lending radio advice and support. An honourable mention must also go out to Delboy, his PMR radio forum was the source of many answers as were his PMR pages. Delboy is a sex machine...

Links of some use:

All the information you ever wanted about license-free radio.

If you want a PMR answer, these guys will know.

A growing site with plenty of information.

 

The manufacturers of the 16F84 PIC.

 

All the PIC info and help you could ever need.

 

PH Andersons' wonderful embedded control pages

This guy's writings about interrupts makes it all easy.

Home