Menu
Microbots
0
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • Modules & Parts
    • Tools & Gears
    • Robots & Displays
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Sign in
  • English
  • Your Cart is Empty
Microbots
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • Modules & Parts
    • Tools & Gears
    • Robots & Displays
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Language

  • 0 0

CodeCell: Controlling a Servo-Motor

CodeCell Servo Control

CodeCell can drive low-power servo motors directly and uses its onboard motion sensor to bring interactive projects to life. 

How It Works

A servo motor is a rotary actuator that holds a specific angle based on an input signal (0°–180°). During setup, take note of the following points:

  • Power via USB-C (up to 500 mA) or LiPo battery (up to 1500 mA) for higher-torque servos.
  • Use the ESP32Servo library (available from Arduino Library Manager).
  • Connect the servo’s signal pin to a GPIO, and use CodeCell’s GND and VO pins for power.

Example – Control Servo with Pitch Angle

This example reads the Pitch angle from CodeCell and moves the servo accordingly. The servo follows your tilt, which can be used for testing motion-based control or creating simple balancing mechanisms.


#include <CodeCell.h>
#include <ESP32Servo.h>

CodeCell myCodeCell;
Servo myservo;

float Roll = 0.0;
float Pitch = 0.0;
float Yaw = 0.0;
int servo_angle = 0;

void setup() {
  Serial.begin(115200);
  myCodeCell.Init(MOTION_ROTATION); // Enable rotation sensing
  myservo.attach(1);                // Connect servo to pin 1
}

void loop() {
  if (myCodeCell.Run(10)) {         // Run at 10 Hz
    myCodeCell.Motion_RotationRead(Roll, Pitch, Yaw);

    // Map Pitch angle to servo position
    servo_angle = abs((int)Pitch);
    servo_angle = 180 - servo_angle;

    // Limit movement range (0–60°)
    if (servo_angle > 60) servo_angle = 60;
    else if (servo_angle < 0) servo_angle = 0;

    Serial.println(servo_angle);
    myservo.write(servo_angle);     // Move servo to mapped angle
  }
}

Customization Tips

  • Adjust Range: Modify servo_angle limits to match your servo’s mechanical range.
  • Combine Sensors: Mix rotation control with proximity or light sensing for adaptive behavior.
  • Use for Stabilization: Apply feedback logic for gimbals, camera mounts, or balancing platforms.
  • Share:

Follow

Github

  • About
  • Software
  • Education
  • Contact
  • FAQs
  • Terms
  • Refund Policy
  • Privacy Policy

Join our Community ~ Be the first to know about new products and get exciting deals!

© 2026 Microbots.

★ Reviews

Let customers speak for us

53 reviews
Write a review
85%
(45)
4%
(2)
2%
(1)
4%
(2)
6%
(3)
21
49
G
CodeCell C6 Drive
Gerhard Weidenauer

Great board with many funktions in small space

User picture
L
MotorCell
Lennart Lange

Nice packaging, good follow up on the delivery, need to look up some online resources now for my first actual project wiht the cell

B
CodeCell C6 Drive
Brandon

Awesome product with great tutorials and example code

G
MotorCell
Gerald Kendrick

Very happy with my MotorCell. I'm incorporating it into a prototype project that will hopefully result in me needing a few more!

User picture
A
CodeCell C6 Drive
Anonymous

Great product! Having the IMU, motor driver, and battery management directly on the board is incredibly handy for quick prototyping. Love it!

Improvement ideas:
- using an ESP32 other than the C6 to get more cores. On a single-core chip, WiFi tasks often interfere with real-time applications.
- adding two more motor drivers (with a slightly higher current rating) would be awesome for drone projects!
- I know the compactness of the board is a huge selling point and really optimised, but exposing a few more pins would be great. With the motor drivers already occupying 4 pins, having only 4 GPIOs left can be tight for complex projects (though I’m nitpicking, I’m really pushing this board to its limits!).

123