personal Bird Scooter controlled by arduino

This is a personal scooter bought from XiaoMi, they manufacture for bird

So I unplugged the accelerator wires and the brake wires and plugged them into a breadboard. (the voltage already maintained until 5V's in the scooter).

each had 3 wires

  • red
  • black
    *green (guessing a pwm reader)

therefore, I've written this code

#define pin1 2 // Accelerator +
#define pin2 3 // Brake –
#define pw1 9 // speed value Accelerator
#define pw2 10 // brake value 
// connect black to ground

void setup() {
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pw1, OUTPUT);
pinMode(pw2, OUTPUT);

digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
analogWrite(pw1, 50);
analogWrite(pw2, 50);


void loop() {
  digitalWrite(pin1, HIGH); // sets the accelerator on
  analogWrite (pw1, 1023);  
  delay(10000);  // waits 10 second
  digitalWrite(pin2, HIGH);// Turns the brake on for one second. (BRYCE, theoritcally, when we turn the brake on it will auto cancel the accelerator so this simple code should be able to give us a result)
  analogWrite (pw1, 0);
  analogWrite (pw2, 1023);
  delay(1000);            // waits for a second
  analogWrite (pw2, 0); 
  digitalWrite(pin2, LOW); // turns brake off

What I was trying to accomplish with this code was acceleration for 10 seconds, then turn the brakes on (pin2, high) the microcontroller in the scooter already has a brake override so I think I do not have to turn the pin to low. then, I want to turn the brake off and start the accelerator again.

Is this code reasonable?
Is 0-1024 the correct range for these scooters? How do I know? is there other ranges (ex. 0-180)

Please advise,


Is this code reasonable?

Try it.

delay() is hardly ever a good thing to use.

analogWrite(pin, value)

pin: the Arduino pin to write to. Allowed data types: int.
value: the duty cycle: between 0 (always off) and 255 (always on). Allowed data types: int.”

what would you recommend instead or delay?
I figured delay would initially, then change the timing as needed. I plan on testing with this code, not actually riding it…

when I get home I will be trying it. I thought it would be nice to get some eyes on it first.

delay() millis()

Robin2 as a great discussion here:

Also, a state machine can be used in complicated situations.

Always best to try things yourself first, if you run into problems then ask for assistance.

Hi !
did it work ? are signals 0-5V ? ou 0-3.3V ?