Hi the servo won't stop going; what have I missed in this code?
#include <ESP32Servo.h>
Servo myservo; // create servo object to control a servo
// 16 servo objects can be created on the ESP32
int pos = 0; // variable to store the servo position
// Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33
int servoPin = 26;
void setup() {
Serial.begin(9600);
myservo.attach(servoPin); // attaches the servo on pin 26 to the servo object
myservo.write(180);
delay(2000);
}
void loop() {
for (pos = 80; pos <= 179; pos += 1) { // goes from 80 degrees to 179 degrees in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 81; pos -= 1) { // goes from 180 degrees to 81 degrees in setps of 1 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
In setup, you instruct the servo to move to 180 degrees, and then you pause for 2 second.
Each time through your loop function, you instruct the servo to move from 80 to 180 degrees, then back to 80 degrees. Since loop is repeated ad infinitum, the servo will keep doing that forever. After that initial 2 second pause in setup, I don't see anywhere where you've told it to stop ever again.
Is this program from your farm kit, the one I edited (I recognize the corrected comments in the second "for()" loop - their comments were completely wrong)? What do you want this code to do? What does the farm kit instructions say?
The farm kit is walking you through testing each device. When all devices are tested, the kit will tell you to upload a system program for all devices to work together.