Back
Balancing Robot

Balancing Robot

90 Views9 Likes0 Comments12/29/2025

Build a self-balancing two-wheeled robot. Learn about PID control, gyroscopes, and real-time stabilization.

Code Examples

1 example
Motor Control Example
Arduino
35 lines
motor_control.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
500 italic">// Robot Motor Control Example
500 italic">// Controls two DC motors for a robot car

500 italic">#define MOTOR_A1 5
500 italic">#define MOTOR_A2 6
500 italic">#define MOTOR_B1 9
500 italic">#define MOTOR_B2 10

void setup() {
  pinMode(MOTOR_A1, OUTPUT);
  pinMode(MOTOR_A2, OUTPUT);
  pinMode(MOTOR_B1, OUTPUT);
  pinMode(MOTOR_B2, OUTPUT);
}

void forward() {
  analogWrite(MOTOR_A1, 200);
  analogWrite(MOTOR_A2, 0);
  analogWrite(MOTOR_B1, 200);
  analogWrite(MOTOR_B2, 0);
}

void stop() {
  analogWrite(MOTOR_A1, 0);
  analogWrite(MOTOR_A2, 0);
  analogWrite(MOTOR_B1, 0);
  analogWrite(MOTOR_B2, 0);
}

void loop() {
  forward();
  delay(2000);
  stop();
  delay(1000);
}
Comments (0)

Please login to leave a comment

No comments yet. Be the first to comment!

K

keyestudio Robot

Creator