Servo myServo; // Create a servo object
const int servoPin = 9; // PWM pin for servo signal
const int receiverPin = 9; // Same pin if direct connection (else change)
void setup() {
myServo.attach(servoPin); // Attaches the servo to the pin
pinMode(receiverPin, INPUT); // Set receiver pin as input
Serial.begin(9600); // For debugging (optional)
}
void loop() {
// Read PWM pulse width from receiver (typical range: 1000-2000 microseconds)
int pulseWidth = pulseIn(receiverPin, HIGH, 25000); // Timeout after 25ms
// Map the pulse width (1000-2000µs) to servo angle (0-180°)
int angle = map(pulseWidth, 1000, 2000, 0, 180);
myServo.write(angle); // Move the servo
// Optional: Print values to Serial Monitor
Serial.print("Pulse Width: ");
Serial.print(pulseWidth);
Serial.print(" | Angle: ");
Serial.println(angle);
delay(20); // Small delay to stabilize
}
For receivers with PPM/SBUS output (single wire for all channels), use libraries like SBUS or PPMReader
#include <SBUS.h>
SBUS receiver(Serial1); // Use hardware serial
welcome to the arduino-forum.
I'm pretty sure that you agree and will follow the way how to solve your problem mimimum 200 minutes faster.
This requires to invest 20 minutes of your precious time to read how to speedup solving your problems.
Directly after registering you got presented informations how to speed up solving your problem.
You should really read it.
you get quicker help if your code is well formatted like shown in this tutorial
Walk me through what you have going on, you seem to be reading in a value and setting the servo to that value, correct? Now you want it to return back to its "original" position? What is the original position, 90 degrees?
How long after the servo position is set does it need to return to its original position, immediately after its set? 0.5 seconds after its set? How about when you send nothing, should it return then?