help a noob out!! simple button trigger A servo.
Posted: Thu Oct 23, 2025 4:11 pm
by Antlearns
Sory this is probably easy to the esp masses all i want to do is trigger a servo for a set time im using a dmx relay so basicaly when closed trigger the esp32 to make the servo close. hope that makes sense
Re: help a noob out!! simple button trigger A servo.
Posted: Tue Oct 28, 2025 11:17 pm
by ESP32_kid
Do you have any code to share?
What coding language?
If you have nothing yet then use online Ai bot and ask it to write you a short program for Arduino IDE or microPython for what you want to do.
DDG gave me this, but probably needs to be modified using some other gpio to monitor for your trigger.
#include <ESP32Servo.h>
Servo myServo; // Create a servo object
const int servoPin = 26; // Pin connected to the servo
const int relayPin = 2; // Pin connected to the DMX relay
void setup() {
myServo.attach(servoPin); // Attach the servo to the pin
pinMode(relayPin, INPUT); // Set relay pin as input
}
void loop() {
if (digitalRead(relayPin) == HIGH) { // Check if relay is closed
myServo.write(90); // Move servo to 90 degrees
delay(2000); // Wait for 2 seconds
myServo.write(0); // Move servo back to 0 degrees
}
}