Jeremy Harris
100 MW
One thing has bugged me with each of the ebikes I've built, the clunky way we have to turn them on and off. Up until now my daily use ebike has had a key switch, that turns the pre-charge and controller on, and a plug in power link that connects the main power. The turn on procedure is to turn the key switch on, wait a second or two for the capacitors to charge and then plug the link in. The process is reversed to turn the ebike off. It works well, with no big sparks or surges due to the capacitors charging too fast, but is clunky, all the same. My car doesn't have a key, it just senses when the fob is in my pocket and lets me start by pressing a button, so I thought it'd be nice to have something similar for the ebike.
What I came up with is a combined slow turn on switch and coded lock, using an RFID tag (Radio Frequency Identification). The tags are unique and coded with a ten digit number, so are pretty secure (more secure than a key switch, for sure). The readers are now pretty cheap, too, so all that was needed was a bit of electronics to take the code from the reader, check that it is the correct one for the bike and then turn on the power to the controller, with a slow switch on speed to limit the inrush current.
The circuit diagram and code below shows how I did it. The RFID reader is a cheap unit from China (http://www.seeedstudio.com/depot/125khz-rfid-module-uart-p-171.html) that outputs a serial data stream whenever it senses a tag. This gets fed to a small microcontroller that reads the code, checks it against a stored code for the bike and if it matches then turns on some FETs to turn the controller on. The FETs are deliberately turned on slowly, via a resistor and big capacitor, to limit the inrush current. My bike already has a handlebar mounted controller cut off switch, so I used this as a combined "arm" switch and cut off switch. When the switch is turned on the power switch gives a very short beep once a second to let you know the power is on but that the controller isn't yet powered up. Waving the RFID tag within an inch of the antenna coil reads the tag and turns the power on, with the power switch giving a 1 second long beep as confirmation. The controller will then stay latched on until the handlebar cut off switch is turned off, when it turns off and needs to read the tag again to turn on. On my bike the battery "fuel gauge" gives me a good indication that power is on, so I haven't fitted a power on LED, but one would be a good idea normally.
First a photo of the prototype unit:
I built the prototype into a small plastic box about 2 3/4" x 2" x 1". The second version has been built into a new controller box on the bike, with the antenna glued under the bike saddle:
This is a bit stealthier, as it's out of sight and you can turn the bike on by just waving the red tag under the saddle, making it possible to more easily turn the power on when on the move.
Here's the circuit diagram, which should be fairly self explanatory. The microcontroller is similar to the one I used for the "fuel gauge", a cheap, easily programmed (with free software) Picaxe 08M2:
and finally here's the code to make it work, with a dummy ten digit tag number:
Maybe someone might be geeky enough to want a "keyless entry" ebike....................
Jeremy
What I came up with is a combined slow turn on switch and coded lock, using an RFID tag (Radio Frequency Identification). The tags are unique and coded with a ten digit number, so are pretty secure (more secure than a key switch, for sure). The readers are now pretty cheap, too, so all that was needed was a bit of electronics to take the code from the reader, check that it is the correct one for the bike and then turn on the power to the controller, with a slow switch on speed to limit the inrush current.
The circuit diagram and code below shows how I did it. The RFID reader is a cheap unit from China (http://www.seeedstudio.com/depot/125khz-rfid-module-uart-p-171.html) that outputs a serial data stream whenever it senses a tag. This gets fed to a small microcontroller that reads the code, checks it against a stored code for the bike and if it matches then turns on some FETs to turn the controller on. The FETs are deliberately turned on slowly, via a resistor and big capacitor, to limit the inrush current. My bike already has a handlebar mounted controller cut off switch, so I used this as a combined "arm" switch and cut off switch. When the switch is turned on the power switch gives a very short beep once a second to let you know the power is on but that the controller isn't yet powered up. Waving the RFID tag within an inch of the antenna coil reads the tag and turns the power on, with the power switch giving a 1 second long beep as confirmation. The controller will then stay latched on until the handlebar cut off switch is turned off, when it turns off and needs to read the tag again to turn on. On my bike the battery "fuel gauge" gives me a good indication that power is on, so I haven't fitted a power on LED, but one would be a good idea normally.
First a photo of the prototype unit:
I built the prototype into a small plastic box about 2 3/4" x 2" x 1". The second version has been built into a new controller box on the bike, with the antenna glued under the bike saddle:
This is a bit stealthier, as it's out of sight and you can turn the bike on by just waving the red tag under the saddle, making it possible to more easily turn the power on when on the move.
Here's the circuit diagram, which should be fairly self explanatory. The microcontroller is similar to the one I used for the "fuel gauge", a cheap, easily programmed (with free software) Picaxe 08M2:
and finally here's the code to make it work, with a dummy ten digit tag number:
Code:
;Electric bike RFID power switch
;The code below loops around giving a short beep every second until a valid key is detected, when it then turns the power on,
;beeps for one second and the programme ends, leaving the power switch FETs turned on.
;The code restarts at next power on via a handlebar mounted cut-off switch that also supplies the power to the unit.
;With the handlebar switch off the FET power switch is also off.
;The first byte sent by the RFID reader is always 02h, and is ignored in the code below
;The next ten bytes are the RFID tag code in ASCII, read into bytes b1 to b10
;The read value is compared with the tag code obtained from the serial terminal during set up
;after ten ASCII data bytes the unit sends two bytes of checksum and a single byte for end of transmission, 03h, also ignored in this code
#picaxe 08M2
setfreq m8 ;Needs to run at 8MHz in order to get 9600 baud for RFID reader output
main:
serin [2000,no_valid_code],c.4,T9600_8,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13 ;read RFID tag number into variables b1 to b13
IF b1="0" AND b2="1" AND b3="0" AND b4="0" AND b5="0" AND b6="5" AND b7="3" AND b8="5" AND b9="3" AND b10="B" THEN ;Dummy tag number - get real tag number from testing with serial terminal using code below that's commented out
HIGH c.2 ;turn on beeper
HIGH c.1 ;turn on FET switch
PAUSE 2000
LOW c.2 ;turn off beeper
ELSE
LOW c.1 ;keep FET switch turned off when no valid tag
LOW c.2 ;keep beeper turned off when no valid tag
PAUSE 2000
GOTO no_valid_code
ENDIF
END ;comment this out during set up so that the code loops continuously to read tag ID numbers
no_valid_code:
HIGH c.2 ;turn on beeper
PAUSE 20 ;keep beeper on for 10 mS
LOW c.2 ;turn beeper off
;Uncomment the code below to read tag ID numbers via the serial port and terminal when setting the unit up for a new tag ID
;setfreq m4 ;slow picaxe back down for serial comms to work at 4800 baud (not needed when line below commented out)
;sertxd (#b0,",",b1,",",b2,",",b3,",",b4,",",b5,",",b6,",",b7,",",b8,",",b9,",",b10,",",#b11,",",#b12,",",#b13,cr,lf)
;setfreq m8 ;speed clock back up again to run at 9600 baud for RFID reader
GOTO main ;loop back to main programme if tag read isn't valid or if no tag detected
Maybe someone might be geeky enough to want a "keyless entry" ebike....................
Jeremy