Hello!
I want to control my servo motor with my DHT11 for an art project. When my sensor humidity is at 95%, i want that my motor make a 180° rotation then stop, then return at his initial position after 20 sec.
This my code (but it didn't work). Can someone help me?
#include "DHT.h"
#include <Servo.h>
#define DHTPIN A0
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
float h = 0;
int sure;
void setup() {
// put your setup code here, to run once:;
myservo.attach(9); //We introduced the ninth pin arduino to the servo motor
dht.begin();
Serial.begin(9600);
}
void loop() {
myservo.write(0);
Serial.begin(9600);
sure = pulseIn(A0, HIGH);
h = (A0/29.1)/2;
// put your main code here, to run repeatedly:
float h = dht.readHumidity();
Serial.print("Humidity: ");
Serial.print(h);
Serial.println();
delay(1000);
if (h > 95) {
myservo.write(180);
delay(20000);
}