The SG90 holds a commanded angle rather than just spinning, which is what makes it useful for gates, dispensers and valves. You drive it with a PWM pulse whose width sets the position. Power it from the 5V rail rather than a logic pin — the stall current on a small servo is more than a GPIO can give, and a browning-out board that resets mid-move is the classic first failure here.
Every item is in the kit — nothing extra to buy.
All 24 parts in one box, with this project and 15 more to build from them.
One of each part. Packs (resistor assortment, jumper wires) already hold more than a single build needs. Backorder parts ship once they arrive — the kit above has every part boxed today. Delivery is free on orders AED 150.00+.
Written for the board in the kit. Copy it into the Arduino IDE; change the pin numbers if you wire it differently.
/*
09 — Servo gate or pet feeder
Board: ESP32. Parts: SG90 servo, tactile switch (optional trigger).
Library: "ESP32Servo" (the standard Servo library does not support the ESP32).
Wiring:
SG90: brown -> GND, red -> VIN (5 V), orange (signal) -> GPIO 13
Power it from the 5 V pin, never from a GPIO: a small servo can pull
more than a pin can give, and a browning-out board that resets
mid-move is the classic first failure here.
Button: one leg -> GPIO 27, other leg -> GND (press = open the gate now)
The SG90 HOLDS an angle rather than spinning: a 1–2 ms pulse every 20 ms
sets the position. That is what makes it a gate, a dispenser or a valve.
*/
#include <ESP32Servo.h>
const int SERVO_PIN = 13;
const int BUTTON_PIN = 27;
const int CLOSED_DEG = 10;
const int OPEN_DEG = 100;
const unsigned long OPEN_FOR_MS = 1500; // how long the gate stays open
const unsigned long FEED_EVERY_MS = 6UL * 60UL * 60UL * 1000UL; // 6 h timer (0 = button only)
Servo gate;
unsigned long lastFeed = 0;
void openGate() {
Serial.println("open");
for (int a = CLOSED_DEG; a <= OPEN_DEG; a += 2) { gate.write(a); delay(10); } // slow = quiet
delay(OPEN_FOR_MS);
for (int a = OPEN_DEG; a >= CLOSED_DEG; a -= 2) { gate.write(a); delay(10); }
Serial.println("closed");
}
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
gate.setPeriodHertz(50); // standard 50 Hz servo signal
gate.attach(SERVO_PIN, 500, 2400); // SG90 pulse range in microseconds
gate.write(CLOSED_DEG);
lastFeed = millis();
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) { // manual trigger
openGate();
lastFeed = millis();
delay(300); // crude debounce, fine here
}
if (FEED_EVERY_MS > 0 && millis() - lastFeed >= FEED_EVERY_MS) {
openGate();
lastFeed = millis();
}
}
Turn the knob, the motor changes speed. PWM switches power on and off faster than the motor can respond, so average voltage falls and so does speed. You also learn why a…
Run the same motor through both drivers and learn why there is more than one. The L9110 takes two pins per motor and you PWM one of them. The L293D separates the jobs: d…
Mount the ultrasonic sensor on the servo, sweep it through its range, and record distance at each angle. You now have a set of angle-and-distance pairs — a crude map of…