Servo myservo; /* create servo object to control a servo */
int potpin = A0; /* analog pin used to connect the potentiometer */
int val; /* variable to read the value from the analog pin */
void setup() {
Serial.begin(9600);
myservo.attach(D0); /* attaches the servo on pin D0 to the servo object */
}
void loop() {
val = analogRead(potpin); /* reads the value of the potentiometer (value between 0 and 4095) */
Serial.print("Analog Value : ");
Serial.print(val);
Serial.print("\n");
val = map(val, 0, 4095, 0, 180); /* scale it to use it with the servo (value between 0 and 180) */
Serial.print("Mapped Value : ");
Serial.print(val);
Serial.print("\n\n");
myservo.write(val); /* sets the servo position according to the scaled value */
delay(100); /* waits for the servo to get there */
}
@Tejendra Welcome to the Particle Community.
Raspberry Pi is no longer supported by Particle hence why it is in the Archive topic area.
An obvious starting point for you might be to check your wiring connections and also is the servo getting sufficient power for it to operate. It may also require a logic level driver 5V against 3.3V from RPi.
Adding a schematic and details of the servo being used would help.
1 Like