Black Friday Offer 🔥 Use code BLKFRI at checkout to get 15% OFF on orders above €60!

CodeCell can drive low-power servo motors directly and uses its onboard motion sensor to bring interactive projects to life.
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:
ESP32Servo library (available from Arduino Library Manager).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
}
}
servo_angle limits to match your servo’s mechanical range.Join our Community ~ Be the first to know about new products and get exciting deals!
© 2025 Microbots.