I’ve posted another topic before this asking this:
I Have a simple push-button with 4 pins and a simple micro servo. I'm using an Arduino nano. I don't have any resistors and don't know if I will need them. What I'm trying to do is this:
When I start the process, the servo starts at 0 degrees
When I press down the button (hold) the servo moves from 0 to 180 degrees, not more
When I let go of the button, the servo moves from 180 degrees back to 0 degrees
I'd love for someone to help me with regards to the code, and the pins to attach my wires to on the arduino.
I received this code which I believe is the solution, but didn’t receive where to put my wires on the arduino. (I’m a beginner btw) :
const byte ServoPin = 3;
const byte ButtonPin = 4;
// * When I start the process,
// the servo starts at 0 degrees
// NOTE: The internal pull-up resistor will keep the
// pin reading HIGH when not connected. The pin
// will read LOW when connected to Ground through
// a closed switch.
// * When I press down the button (hold)
if (digitalRead(ButtonPin) == LOW)
// the servo moves from 0 to 180 degrees, not more
else // * When I let go of the button,
// the servo moves from 180 degrees back to 0 degrees
Would someone be able to let me know where I put my wires. I HAVE AN ARDUINO NANO
These lines tell you which pins to attach the button and servo.
The button should be attached between the Arduino pin and ground. No resistor needed. Use a diagonal pair of pins on the button, leave the other pins unconnected.
The servo should be connected to 5V, ground and the Arduino pin. No resistors required. Only one servo can be connected like this. 2 servos would be too much for the Arduino and a separate power supply would be needed. Ideally an separate power supply should be used even for one servo.