How to control a servo motor with a potentiometer (10 k)

how to control a servo motor with a potentiometer (10 k)

Google:

how to control a servo motor with a potentiometer

I already did that

sorry I didn’t explain it right

#include <Servo.h>

Servo myservo;

int val;

void setup() {

myservo.attach(9);

}

void loop() {
 val = analogRead(1);
 val = map(val, 0, 1023, 0, 180);
 myservo.write(val);
 delay(1);

}

is this supposed to work because the servo just turns by itself randomly and won’t listen tom the potentiometer

did I do everything right

  • Show us good images of your actual wiring.

okay

Trey the Servo library's "Knob" example:

  • See time @ 19:00

You are using pin A1 so your code shd be something like this:

val = analogRead(A1) //Not analogRead(1)

This is wrong

Yes, the code works. Your wiring, or your power supply, is not correct.

I just wanted how did you get the code working cuz it didnt work when I tried. It worked only after i made a couple of changes. Basically instead of reading from 1 I was reading from A1 for the potentiometer.

Also I think it is advisable to test the components individually.

For the potentiometer could you pls upload real pictures. Also if your wiring is identical to the diagram, you wont get a reading from the potentiometer because the potentiometer and the wires are on different side of the breadboard.
The mistake may be this:

The correct wiring would be something like this:

Also separately test the servo but i do suspect that the issue is with potentiometer.

Connected the components correctly, compiled and uploaded the code... I might have edited the "A1" but I do not remember doing that.