Cutoff throttle on standstill?

michielk

100 mW
Joined
Jun 8, 2017
Messages
38
Hello,

I'm building an electric kickbike.

Optional Intro
I have build three ebikes so far.
- 'stealth' oldschool city bike with 2000W hub motor, custom battery/controller hidden in saddle bags
- full suspension downhill MTB with BBSHD and custom 1kwh battery in backpack (offroad)
- modern city ebike based on a MTB frame with Bafang ultra motor and EM3EV Jumbo battery on downtube

Now I would like to build an electric kickbike (scooter, dogscooter, autoped).
- MTB Frontend (front suspension, 26" MTB wheel, MTB handle bars, Hydraulic disc brakes)
- Custom home build frame
- 20" Backwheel with HUB motor (most likely HT3525)
- Controller: 48V/40A Sensorless controller that I have from a previous project
- Battery: undecided, depends on frame design but sourced from EM3EV (square box, 1 or 2 super shark)

Question
To make it road legal you can not use the throttle to move the bike from a standstill. So you would need to push or kick it before the throttle works. My controller has a standard 4 pin throttle and a 3 pin e-brake cutoff. I can solder things together but I don't have the electronics knowhow to 'design' custom electronics.

Is there anything available that will either activate the e-brake cutoff or disable the throttle if the bike is standing still? So as soon as you push the bike a bit, or kick it, the e-brake is disabled and throttle is enabled.

Thank you so much for your help!
 
Do you have any Arduino experience? An ATTiny85 microcontroller could do the job. Just run one of the hall signals to an input pin and power it off the 5v line from the controller. It only draws a few milliamps, so it would be fine. Take a transistor, hook the emitter to ground, hook the collector to the e-brake cutoff line, and hook the base through a resistor (around 1kohm) to another pin on the AtTiny.

Write a program that requires there to be more than 3 or so pulses per second on the hall input pin before bringing the output high. When there are less than 3 pulses per second, the output pin would be high, turning on the transistor, simulating the brake being held, and preventing the controller from powering the motor.

Customizing, tinkering, and hacking controllers to add features that they didn't come with requires the ability to design basic circuits and either program microcontrollers or wire together a shit-ton of logic gates. Microcontroller and circuit knowledge has been invaluable for my custom e-bike endeavors.

Get an Arduino and start going through the examples. Within 10 to 15 hours of messing around, you should be proficient enough to design a simple program that requires you to start the bike before using the throttle. BlinkWithoutDelay would be a good example to play with. Good luck!
 
Hello,

Thanks for your very helpfull reply. This does sound like a smart and doable solution. I have some experience programming (basic VBA, simple Python, ..) and have done some simple Raspberry Pi Projects (Python). I'm confident I can design the program myself. I also know what a transistor and resistor "does". However, I have no experience designing the circuit you are describing.

Would this microcontroller work? Does such a microcontroller have a build in timer (so it knows how long a second is)? I have only programmed raspberry pi, which have a lot of functions build in.
https://www.adafruit.com/product/3500

I have this controller, I assume the 5V output power for the external display will be plenty of power for a tiny microcontroller.
http://shop.crystalyte-europe.com/product.php?productid=16463&cat=296&page=1

It sounds like a very simple circuit, if it is not too much trouble, could you give me a start with a simple circuit drawing?
Just a picture of a simple circuit on a napkin is fine!

Thanks so much
 
The microcontroller you listed would not be suitable for the task at hand, as it runs off of 3.3 volts and all ESCs I've ever seen run off of 5 volts. Get an Arduino Nano, those things use less than 10 milliamps and even less if you break SMD power LED off. You can get a clone off of eBay for less than $5, cheaper if you're willing to buy from China and wait two weeks.

I've never heard of CircuitPython before, but after a little research, it seems like a terrible idea that anyone would even design such a language. It is around 100x slower that C++ and will come back to bite you when you are trying to run a 100hz PID loop with complicated calculations. The best time to learn C++ is now when you are starting on simple projects like this, not later when you are running into bottlenecks with a complicated project.

First, make a program that toggles the ebrake on and off, based on BlinkWithoutDelay. From there, you can replace the millis comparison with a counter that decreases with time and increases a certain amount whenever the hall sensor changes state. Restrict the counter to a minimum and maximum value and if it is higher than a certain value, disengage the ebrake. Otherwise, engage the ebrake.
Gp9Uu94.png
 
Thanks
I bought a Arduino Nano V3 and a pack of different resistors and transistors. Will need to have a look to write the code for this in the required language. The biggest motivation to use Python is that it is very high level and so easy to understand and learn.

Kind regards, Michiel.
 
It's a pretty simple task, so the code for Arduino will be pretty easy. The schematic looks like it would work.
 
Hello,

I'm still waiting for my wheel, but in the mean time I have developed the code using an online emulator (tinkerCAD.com). Please see schematics and my code below. I used a LED to represent the "brake signal" and a button to represent the Hall-Sensor input. If you press the button a few times, the LED will turn off (no brake signal, throttle will work). After a few seconds of no changes in the Hall input (no button press or release), it will turn the LED back on (brake signal, no throttle).

Will update once I get all my parts and get it working (will be another month at least, will build the frame first).

thanks for the help!
kind regards, Michiel.

99nFZr2.jpg

Code:
// constants won't change. Used here to set a pin number :
const int ledPin =  13;
const long interval = 2500;
const int buttonPin = 2;

// Variables will change :
int ledState = HIGH;             
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;

unsigned long previousMillis = 0;        


void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  
  unsigned long currentMillis = millis();
  buttonState = digitalRead(buttonPin);
  
  if (ledState == HIGH) {
    digitalWrite(ledPin, LOW);
  } else {
    digitalWrite(ledPin, HIGH);
  }
  
  if (buttonState != lastButtonState) {
    buttonPushCounter++;
    lastButtonState = buttonState;
    delay(50);
    previousMillis = currentMillis;
  } 
  
  if (buttonPushCounter > 5){
    ledState = LOW;
  } else {
    ledState = HIGH;
  }
  
  if (currentMillis - previousMillis >= interval) {
    buttonPushCounter = 0;
  }
  
}
 
I have updated my code/circuit, now it does multiple things.

- If you stand still, the e-brake is engaged and throttle does not work
- if you kick the bike into movement, the e-brake is disengaged and throttle will work but limited in speed (resistor inline)
- if you kick the bike into movement and meanwhile push in a button, the e-brake is disengages and a relay is activated (bypassing the resistor) now you have full throttle. You can then release the button, full speed will remain untill you stop.
- pressing the pushbutton while riding has no effect at the moment, I may change it so that it turns the lights on/off.
 
Back
Top