As most of you are quite aware theres a speed limit in the UK of 15.5mph for electric bikes, which makes sense for public roads etc (not really). But what about when you're on your own private land and you want to get more out of the bike...
Yeah theres lots of different dongles you could buy... but why not make your own?
I used an arduino micro and a hall effect sensor to sense the magnet along the wheel and then activate an electromagnet every 2 rotations thus fooling the bike into thinking im going half the speed.
Here is the schematic:
And here's the code:
//**********************************************************
// Ebike_Jellyhack firmware v0.1
// Author: Nicholas John
// Date: August 2016
// Device: Arduino/Genuino Micro
// Hall Sensor: LinkSprite Hall sensor module
// RPM to Speed resource: https://endless-sphere.com/forums/viewtopic.php?f=28&t=16114
// 29 inch tire 11.6 RPM per one-MPH
// 27.5 inch tire: 12.2 RPM per one-MPH
// 26-inch tire: 12.93RPM per one-MPH
//**********************************************************
int digitalPin = 2; //D0 attach to pin2
boolean digitalValue; //variable to store the value coming from pin2
const int magnetOutPin = 12; //Pin that will be switched on to turn on transistor
volatile byte revolutions;
volatile byte half_revolutions;
unsigned int rpm;
unsigned long timeold;
const double rpmPerMph = 12.2;
double mphSpeed =0;
void setup()
{
Serial.begin(9600);
pinMode(digitalPin, INPUT);
pinMode(magnetOutPin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(digitalPin),magnet_detect,RISING);
revolutions = 0;
half_revolutions = 0;
rpm = 0;
timeold = 0;
}
//Runs over and over
void loop()
{
if (half_revolutions >= 20) {
rpm = 30*1000/(millis() - timeold)*half_revolutions;
timeold = millis();
half_revolutions = 0;
mphSpeed = rpm/rpmPerMph;
Serial.print(mphSpeed,DEC);
Serial.println(" mph");
}
if (revolutions >= 2)
{
revolutions = 0;
digitalWrite(magnetOutPin,HIGH);
Serial.println("magnet engaged");
delay(20);
digitalWrite(magnetOutPin,LOW);
}
}
void magnet_detect()//This function is called whenever a magnet/interrupt is detected by the arduino
{
revolutions++;
half_revolutions++;
Serial.println("detect");
}
its pretty basic so far and has room for improvements, and it looks quite ugly, but it cost me around 20 quid to make... and it works a charm.
I'm thinking about adding a wireless LCD to the handlebar to read out the REAL speed.
Here's a pic of it on the bike:
pretty bulky and ugly I know, but I was quite pleased I got it working
If anyone has any questions ask away!
Yeah theres lots of different dongles you could buy... but why not make your own?
I used an arduino micro and a hall effect sensor to sense the magnet along the wheel and then activate an electromagnet every 2 rotations thus fooling the bike into thinking im going half the speed.
Here is the schematic:
And here's the code:
//**********************************************************
// Ebike_Jellyhack firmware v0.1
// Author: Nicholas John
// Date: August 2016
// Device: Arduino/Genuino Micro
// Hall Sensor: LinkSprite Hall sensor module
// RPM to Speed resource: https://endless-sphere.com/forums/viewtopic.php?f=28&t=16114
// 29 inch tire 11.6 RPM per one-MPH
// 27.5 inch tire: 12.2 RPM per one-MPH
// 26-inch tire: 12.93RPM per one-MPH
//**********************************************************
int digitalPin = 2; //D0 attach to pin2
boolean digitalValue; //variable to store the value coming from pin2
const int magnetOutPin = 12; //Pin that will be switched on to turn on transistor
volatile byte revolutions;
volatile byte half_revolutions;
unsigned int rpm;
unsigned long timeold;
const double rpmPerMph = 12.2;
double mphSpeed =0;
void setup()
{
Serial.begin(9600);
pinMode(digitalPin, INPUT);
pinMode(magnetOutPin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(digitalPin),magnet_detect,RISING);
revolutions = 0;
half_revolutions = 0;
rpm = 0;
timeold = 0;
}
//Runs over and over
void loop()
{
if (half_revolutions >= 20) {
rpm = 30*1000/(millis() - timeold)*half_revolutions;
timeold = millis();
half_revolutions = 0;
mphSpeed = rpm/rpmPerMph;
Serial.print(mphSpeed,DEC);
Serial.println(" mph");
}
if (revolutions >= 2)
{
revolutions = 0;
digitalWrite(magnetOutPin,HIGH);
Serial.println("magnet engaged");
delay(20);
digitalWrite(magnetOutPin,LOW);
}
}
void magnet_detect()//This function is called whenever a magnet/interrupt is detected by the arduino
{
revolutions++;
half_revolutions++;
Serial.println("detect");
}
its pretty basic so far and has room for improvements, and it looks quite ugly, but it cost me around 20 quid to make... and it works a charm.
I'm thinking about adding a wireless LCD to the handlebar to read out the REAL speed.
Here's a pic of it on the bike:
pretty bulky and ugly I know, but I was quite pleased I got it working
If anyone has any questions ask away!