I am currently on a project on how to make the servo stop at a certain point like 1080 degrees. and how to reverse is. I already have a code but I can't make the servo stop and reverse it. Can anyone help me adjust the code? My servo motor is 20KG torque power and will work on 6.6v.
#include "DHT.h"
#include <Servo.h>
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define SERVOPIN 9
int maxHum = 60;
int maxTemp = 25;
DHT dht(DHTPIN, DHTTYPE);
Servo myservo; // create servo object to control a servo
void setup() {
pinMode(SERVOPIN, OUTPUT);
Serial.begin(9600);
dht.begin();
myservo.attach(9);
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
if( t < maxTemp) {
digitalWrite(SERVOPIN, 180); // tell servo to go to position in variable 'pos'
delay(5000);
} if( t > maxTemp) {
digitalWrite(SERVOPIN, 0); // tell servo to go to position in variable 'posi'
delay(5000);
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C ");
}