Ebike derestrictor

Festivejelly

Pedelecer
Jun 29, 2016
45
36
39
Bristol
  • Like
Reactions: HypnoToad
D

Deleted member 4366

Guest
As I said before, most bikes use a hall sensor for the speed sensor, so you don't need the hall sensor and coil. You just cut the three wires to it and join the signal wire to the pink wire in the schematic above, then take the output to the other side of the wire that you cut instead of to the transistor.

I think there's a mistake in that schematic. it shows both pins 1 and 3 of the transistor joined to the 5v rail, so no possibility of switching.
 
  • Like
Reactions: HypnoToad

HypnoToad

Finding my (electric) wheels
Jun 13, 2012
24
0
Thanks for posting up the circuit for the flip-flop circuit, after reading up a little on logic gates it looks like the flip-flop halves the frequency, and I'm guessing the 4093 converts the long high signal back into a pulse?

I'll order the parts to build the circuit, I like the fact I'm not cutting into the wiring of the bike means the risk of screwing something up is minimal. I'll have to try winding a few magnets, I've found an old motor that I can use the wire from, I will have to get the drill out :D

EDIT: Quick question, does VCC have to be 5v? I have a connector for the lights that puts out 6v and was thinking about using this to power the dongle.

Or if I want to keep it simple, maybe just a single 18650, would ~3.7v be anough?

I must admit I have more experience with arduino type stuff so I am learning as I go along here. :)
As I said before, most bikes use a hall sensor for the speed sensor, so you don't need the hall sensor and coil. You just cut the three wires to it and join the signal wire to the pink wire in the schematic above, then take the output to the other side of the wire that you cut instead of to the transistor.
My Bosch gen1 bike only has 2 pins on the speed sensor, so I guess it uses a reed switch?

Taken from the SX2 dongle manual:


So I guess I need to use a coil here?
 
Last edited:

HypnoToad

Finding my (electric) wheels
Jun 13, 2012
24
0

Festivejelly

Pedelecer
Jun 29, 2016
45
36
39
Bristol
So you can use a boost circuit to boost a 3.7v 18650 to 5v. They are pretty efficient these days to about 90%.

Flip flips are the lowest power solution but if you wanted a simpler circuit you could use an AtTiny85 which consumes around 5ma of current.

The great thing about the AtTiny85 is you can program it with the arduino IDE but also you can put it in sleep mode so it will literally be drawing micro amps.

I'll upload a schematic when I get home. The one thing I havnt found an easy solution for yet is the electromagnet. I'm still winding my own, it seems 5v relays arnt quite powerful enough to trigger the hall effect sensor on my bike.



Thanks for posting up the circuit for the flip-flop circuit, after reading up a little on logic gates it looks like the flip-flop halves the frequency, and I'm guessing the 4093 converts the long high signal back into a pulse?

I'll order the parts to build the circuit, I like the fact I'm not cutting into the wiring of the bike means the risk of screwing something up is minimal. I'll have to try winding a few magnets, I've found an old motor that I can use the wire from, I will have to get the drill out :D

EDIT: Quick question, does VCC have to be 5v? I have a connector for the lights that puts out 6v and was thinking about using this to power the dongle.

Or if I want to keep it simple, maybe just a single 18650, would ~3.7v be anough?

I must admit I have more experience with arduino type stuff so I am learning as I go along here. :)

My Bosch gen1 bike only has 2 pins on the speed sensor, so I guess it uses a reed switch?
So I guess I need to use a coil here?
 

Festivejelly

Pedelecer
Jun 29, 2016
45
36
39
Bristol
I think there's a mistake in that schematic. it shows both pins 1 and 3 of the transistor joined to the 5v rail, so no possibility of switching.
Thats my crappy diagram, if you expand it you'll see the wire is a different colour. The base isnt meant to be attached to the 5v.
 

Festivejelly

Pedelecer
Jun 29, 2016
45
36
39
Bristol
Very good! Sounds like you've got a great solution going on there. I was unable to get the hall sensor on my bike to trigger with a 5v relay so im stuck with the electromagnet :(
Maybe i'll try directing the fields.

RE The arduino, you could easily control the whole circuit using an ATTiny85 and program it using the arduino IDE.

What ive done with mine is put it into sleep mode if it doesnt detect a magnet in 30 seconds. This basically turns the whole thing off without the need for a power switch.

Hey Festive Jelly,

Just wanting to say thanks for your post, using your information provided i was able to build a similar set up to derestrict my Shimano Steps (E6001) powered bike.

I opted for the arduino based approach as i wanted to clamp the detected speed just below the cutoff threshold instead of just halving the frequency to keep the DI2 automatic shifting on my bike.

Build information to help anyone researching this.

Bike: Merida Espresso 800 EQ
Motor: Shimano Steps E6001

Parts used:
- Arunino uno (plan on downsizing had a spare one)
- Hall Sensor sheild https://www.jaycar.co.nz/arduino-compatible-hall-effect-sensor-module/p/XC4434
- Relay Sheild as electromagnet https://www.jaycar.co.nz/arduino-compatible-5v-relay-board/p/XC4419
It was dead simple to put together just pull top of relay to get access to the electromagnet and remove relay contacts then just simply mount on top of existing sensor. Mount Hall senor and move existing magnet to trigger.

For the Shimano Steps motor both the frequency divider method and the speed clamping derestricting method worked really well though with the frequency dividing my auto DI2 shifting bounced between gears endlessly. Placing the magnet on your crank does not work with the Steps motor and throws an error which is kind of annoying to clear.


Just a quick question
Doesn't using a flip flop instead of the arduino result in the magnet being on for one full revolution the off for one increasing your overall power consumption?
 
D

Deleted member 4366

Guest
Is there a reason that you don't simply cut the existing sensors wire and send the output through this device straight to the controller, like this?

Also, I notice that there's no pull-up/down resistor on the hall signal and no capacitors to reduce noise and ripple. The controller must have those on its pcb, but that's downstream of this. Do you think it would be a good idea to include some?

revised flip-flop.jpg
 

Festivejelly

Pedelecer
Jun 29, 2016
45
36
39
Bristol
Is there a reason that you don't simply cut the existing sensors wire and send the output through this device straight to the controller, like this?

Also, I notice that there's no pull-up/down resistor on the hall signal and no capacitors to reduce noise and ripple. The controller must have those on its pcb, but that's downstream of this. Do you think it would be a good idea to include some?

View attachment 19389
But then i'm modifying my bike right? I want a non intrusive way of de restricting.

This way it can be easily removed.

Theres a pull up resistor and capacitor built onto the hall effect sensor board.
 

IR772

Esteemed Pedelecer
Jun 5, 2016
931
1,044
Leominster
On my Yam Hardnine the sensor is a reed switch, you can hear it ping away with a magnet.

Using a 5 volt Schrack power relay, one of the Orange double pole ones, I took it apart stripped out the contacts and used the coil, powered off a 3 volt CR123. This easily operated the reed with a healthy ping. It is small and easy to use, the plastic case strips off easily with some side cutters.

Any 5 volt power relay should work. You can fit the coil on top of the reed switch and not between it and the spokes, it works fine.

I used a reed switch (door contact) as the input moving the magnet down the spoke a couple of inches.

Worked fine as I was only playing on a wet weekend, my bike is too low geared to benefit much and I am not much of a road cyclist.

This should make things a lot easier if you want a self build.
 

Festivejelly

Pedelecer
Jun 29, 2016
45
36
39
Bristol
On my Yam Hardnine the sensor is a reed switch, you can hear it ping away with a magnet.

Using a 5 volt Schrack power relay, one of the Orange double pole ones, I took it apart stripped out the contacts and used the coil, powered off a 3 volt CR123. This easily operated the reed with a healthy ping. It is small and easy to use, the plastic case strips off easily with some side cutters.

Any 5 volt power relay should work. You can fit the coil on top of the reed switch and not between it and the spokes, it works fine.

I used a reed switch (door contact) as the input moving the magnet down the spoke a couple of inches.

Worked fine as I was only playing on a wet weekend, my bike is too low geared to benefit much and I am not much of a road cyclist.

This should make things a lot easier if you want a self build.
Hrm I tried a 5v relay, how did you position it over the sensor? I couldnt get it to trigger with my relay, even with it stripped down.
 

IR772

Esteemed Pedelecer
Jun 5, 2016
931
1,044
Leominster
Opened another relay up, you can see the type as I was more careful with the opening.

I have not chopped off the contacts, but did take out the hinged armature to expose the pole.

I placed the pole against the speed sensor in this position.
20170526_173329[1651].jpg

This is the pole and type.
20170526_173617[1752].jpg

This is the result if you keep tapping on and off with a CR123 battery
20170526_173012[1650].jpg
 

Festivejelly

Pedelecer
Jun 29, 2016
45
36
39
Bristol
Ah nice thanks for the pics. I decided to go ahead and make my own magnet. I tweaked my code a bit and its only using 20 milliamps now. I put in a 850mah lipo with a recharging circuit so I think thatle do me :) I would have liked to have used the relays as ive got 10 or so of them kicking around, but they are a different type to yours so I think the field pattern ends up being too weak at the mounting point.
My new magnet is a steel bolt with thin enamelled wire.
I basically turn it on for 20ms each power up. Works a treat now.
 

Geoff Anderson

Just Joined
Jun 4, 2017
3
0
63
Melbourne
Ah nice thanks for the pics. I decided to go ahead and make my own magnet. I tweaked my code a bit and its only using 20 milliamps now. I put in a 850mah lipo with a recharging circuit so I think thatle do me :) I would have liked to have used the relays as ive got 10 or so of them kicking around, but they are a different type to yours so I think the field pattern ends up being too weak at the mounting point.
My new magnet is a steel bolt with thin enamelled wire.
I basically turn it on for 20ms each power up. Works a treat now.
Just found this thread - definitely going to build this for my wife's Gazelle. I'm guessing from your reference to code that you are going the Arduino route. Can you post your updated code? Also love to see a pic of your magnet.
 

Festivejelly

Pedelecer
Jun 29, 2016
45
36
39
Bristol
Just found this thread - definitely going to build this for my wife's Gazelle. I'm guessing from your reference to code that you are going the Arduino route. Can you post your updated code? Also love to see a pic of your magnet.
Sure thing Geoff.

Here is the arduino code:

Code:
// Speed Derestrictor
// Nicholas John
// 22 May 2017
//
//                                 ATMEL ATTINY 85
//
//                                     +-\/-+
// (PCINT5/RESET/ADC0/dW)        PB5  1|    |8  Vcc
// (PCINT3/XTAL1/OC1B/ADC3)      PB3  2|    |7  PB2 (SCK/USCK/SCL/ADC1/T0/INT0/PCINT2)
// (PCINT4/XTAL2/CLKO/OC1B/ADC2) PB4  3|    |6  PB1 (MISO/DO/AIN1/OC0B/OC1A/PCINT1)
//                               GND  4|    |5  PB0 (MOSI/DI/SDA/AIN0/OC0A/OC1A/AREF/PCINT0)
//                                     +----+

#include <avr/sleep.h>    // Sleep Modes
#include <avr/power.h>
#include <elapsedMillis.h>

const int hallPin = 2;     // the number of the hall effect pin
const int ledPin =  1;      // the number of the LED pin
const long debouncing_time = 15; //Debouncing Time in Milliseconds

// variables will change:
volatile int hallState = 0;         // variable for storing the hall counter
volatile unsigned long last_micros;

elapsedMillis timer;

void setup() 
{
  pinMode(ledPin, OUTPUT);
  pinMode(hallPin, INPUT);
  //digitalWrite(hallPin, HIGH);
  // Attach an interrupt to the ISR vector
  attachInterrupt(0, pin_ISR, RISING); //default interupt pin is always 0 on attiny85 (physical pin 7)
  timer = 0;
}

void sleep() 
{

    GIMSK |= _BV(PCIE);                     // Enable Pin Change Interrupts
    PCMSK |= _BV(PCINT2);                   // Use PB2 as interrupt pin
    ADCSRA &= ~_BV(ADEN);                   // ADC off
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);    // replaces above statement

    sleep_enable();                         // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
    sei();                                  // Enable interrupts
    sleep_cpu();                            // sleep

    cli();                                  // Disable interrupts
    PCMSK &= ~_BV(PCINT2);                  // Turn off PB2 as interrupt pin
    sleep_disable();                        // Clear SE bit
    ADCSRA |= _BV(ADEN);                    // ADC on

    sei();                                  // Enable interrupts
} // sleep

void loop() 
{
  if(hallState>1)
  {
      digitalWrite(ledPin,HIGH);
      delay(20);
      digitalWrite(ledPin,LOW);
      hallState=0;
  }
  if(timer>=30000)
  {
    sleep();
  }
}

void pin_ISR() 
{
  if((long)(micros() - last_micros) >= debouncing_time * 1000) 
  {
    timer=0;
    hallState++;
    last_micros = micros();
  }
}
This is using a reed switch as a opposed to a hall effect sensor. A reed switch is a normally open circuit, and the circuit doesnt get closed until the magnet comes near the reed switch.
A hall effect sensor on the other hand is normally high and gets pulled low when a magnet is near.

I prefer the reed switch as it saves energy when the circuit is not in use. As you can see ive included some code to put the AtTiny85 to sleep, so it draws microamps. It then gets woken when a magnet activates the reed switch.

The magnet itself is just a steel bolt wrapped in 0.23 mm enamelled copper wire winding from only left to right (not both ways, all the coils have to be doing 1 direction in order to make an effective magnet).

Ive attached some pictures of my old circuit that uses a flip flip and nand gates
20170604_134909076_iOS.jpg
and also my new one that uses the arduino style attiny85
20170604_135131644_iOS.jpg
 

Festivejelly

Pedelecer
Jun 29, 2016
45
36
39
Bristol
Just found this thread - definitely going to build this for my wife's Gazelle. I'm guessing from your reference to code that you are going the Arduino route. Can you post your updated code? Also love to see a pic of your magnet.
Arduino code:

Code:
// Nicholas John
// 22 May 2017
//
//                                 ATMEL ATTINY 85
//
//                                     +-\/-+
// (PCINT5/RESET/ADC0/dW)        PB5  1|    |8  Vcc
// (PCINT3/XTAL1/OC1B/ADC3)      PB3  2|    |7  PB2 (SCK/USCK/SCL/ADC1/T0/INT0/PCINT2)
// (PCINT4/XTAL2/CLKO/OC1B/ADC2) PB4  3|    |6  PB1 (MISO/DO/AIN1/OC0B/OC1A/PCINT1)
//                               GND  4|    |5  PB0 (MOSI/DI/SDA/AIN0/OC0A/OC1A/AREF/PCINT0)
//                                     +----+

#include <avr/sleep.h>    // Sleep Modes
#include <avr/power.h>
#include <elapsedMillis.h>

const int hallPin = 2;     // the number of the hall effect pin
const int magnetPin =  1;      // the number of the magnet pin
const long debouncing_time = 15; //Debouncing Time in Milliseconds

// variables will change:
volatile int hallState = 0;         // variable for storing the hall counter
volatile unsigned long last_micros;

elapsedMillis timer;

void setup()
{
  pinMode(magnetPin, OUTPUT);
  pinMode(hallPin, INPUT);
  //digitalWrite(hallPin, HIGH);
  // Attach an interrupt to the ISR vector
  attachInterrupt(0, pin_ISR, RISING); //default interupt pin is always 0 on attiny85 (physical pin 7)
  timer = 0;
}

void sleep()
{

    GIMSK |= _BV(PCIE);                     // Enable Pin Change Interrupts
    PCMSK |= _BV(PCINT2);                   // Use PB2 as interrupt pin
    ADCSRA &= ~_BV(ADEN);                   // ADC off
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);    // replaces above statement

    sleep_enable();                         // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
    sei();                                  // Enable interrupts
    sleep_cpu();                            // sleep

    cli();                                  // Disable interrupts
    PCMSK &= ~_BV(PCINT2);                  // Turn off PB2 as interrupt pin
    sleep_disable();                        // Clear SE bit
    ADCSRA |= _BV(ADEN);                    // ADC on

    sei();                                  // Enable interrupts
} // sleep

void loop()
{
  if(hallState>1)
  {
      digitalWrite(magnetPin,HIGH);
      delay(20);
      digitalWrite(magnetPin,LOW);
      hallState=0;
  }
  if(timer>=30000)
  {
    sleep();
  }
}

void pin_ISR()
{
  if((long)(micros() - last_micros) >= debouncing_time * 1000)
  {
    timer=0;
    hallState++;
    last_micros = micros();
  }
}
The above includes functionality to sleep when its not detected a magnet in 30 seconds. this is there to save power. When its in sleep mode the device draws about 20 micro amps, which is a tiny amount.

Also includes debounce code to handle bouncing that you'll get using a reed switch.
 
  • Like
Reactions: Transistor

Advertisers