Have you ever stared at your screen at 2 AM, desperately wishing the rubber duck on your desk could nod in agreement when your code finally compiles? Yeah, me too. Instead of descending further into madness and talking to inanimate plastic, we’re building a desktop companion robot. It won’t judge your spaghetti code, it won’t ask for a raise, and best of all, it only releases the magic blue smoke if you plug the servos in backwards (ask me how I know).
Let’s dive into building this little ESP32-powered desk buddy.
To keep things simple, our robot uses two servos for the arms, and a pan-tilt mechanism for the head. Be sure to test center your servos to 90 degrees before gluing them in!
Remember: your ESP32 runs at 3.3V logic, but the servos need 5V power and plenty of current. Hook your 5V 3A supply directly to the breadboard rails, connect the servo power lines there, and ensure you tie the ground of the power supply to the ground of the ESP32.
Using the standard ESP32Servo library, we can easily sweep the arms and head randomly, or even tie it to an ultrasonic sensor so it tracks your hand when you wave.
#include <ESP32Servo.h>
Servo headPan;
Servo armLeft;
Servo armRight;
void setup() {
headPan.attach(13);
armLeft.attach(12);
armRight.attach(14);
}
void loop() {
headPan.write(random(45, 135));
armLeft.write(random(0, 180));
armRight.write(random(0, 180));
delay(1000); // Look around randomly
}
Give it a try and enjoy your new robotic coworker!