DHT 22 data shown with 2 Servos

I have a school project to do, which is using the data of the DHT 22 and display it with to Servos. I have programed the DHT 22 so that i can see its data on the serial monitor. But i cant make it to steer the Servos.

This is my programm:

#include “DHT.h” // Bibliothek für DHT22 laden
#include “Servo.h” // Bibliothek für Servos laden
#define DHTPIN 2 // Sensor wird an PIN 2 angeschlossen
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);
Servo myservo;
Servo myservo2;

void setup() {
Serial.begin(9600); // startet serielle Verbindung
myservo.attach (9); // PIN 9 für Servo 1
myservo2.attach (10); // PIN 10 für Servo 2

dht.begin(); // startet den Sensor
}

void loop() {

delay(2000); // 2 Sekunden warten bis Sensor startet

float h = dht.readHumidity(); // Luftfeuchtigkeit auslesen und unter h speichern
float t = dht.readTemperature(); // Temperatur auslesen und unter t speichern
int err;

Serial.print(“Luftfeuchtigkeit: “);
Serial.print(h);
Serial.println(” %”);
Serial.print(“Temperatur: “);
Serial.print(t);
Serial.println(” Grad Celsius”);

if (t < 0) { //Befehle für Servo eins was wenn t
myservo.write (0);
} else;

if (t < 5) {
myservo.write (10);
} else ;

if (t < 10) {
myservo.write (20);
} else;

if (t < 15) {
myservo.write (30);
} else ;

if (t < 20) {
myservo.write (40);
} else ;

if (t < 25) {
myservo.write (50);
} else ;

if (t < 30) {
myservo.write (60);
} else ;

if (t < 35) {
myservo.write (70);
} else ;

if (t < 40) {
myservo.write (80);
} else ;

if (h < 50) { // Befehle für Servo 2 was wenn h
myservo2.write (50);
} else;

if (t < 55) {
myservo2.write (55);
} else ;

if (t < 60) {
myservo2.write (60);
} else ;

if (t < 65) {
myservo2.write (65);
} else ;

if (t < 70) {
myservo2.write (70);
} else ;

if (t < 75) {
myservo2.write (75);
} else ;

if (t < 80) {
myservo2.write (80);
} else ;

if (t < 85) {
myservo2.write (85);
} else ;

if (t < 90) {
myservo2.write (90);
} else ;

if (t < 95) {
myservo2.write (95);
} else ;

if (t < 100) {
myservo2.write (100);
} else ;

}

Can somebody help me and say me whats wrong here??

sketch_jun23c.ino (2.13 KB)

  if (t < 5) {
    myservo.write (10);
  } else ;

What is the point of the empty else block?

Can somebody help me and say me whats wrong here??

No, because you haven’t told us how you are powering the servos and/or whether or not you can make them move with the Sweep example.

Servos are not driven by PWM, so you do not have to use PWM. I’d move the servos to other pins, just to see what happens.

Since all values below 40°C will move the temperature servo to 80 and values of 40°C or higher will not move the servo I expect the temperature servo to go to 80 and stay there. Yes, if the temperature value is below 0°C the servo will be directed to 0 but since that value is also <40°C it will be re-directed to 80 before it can move to 0.

To get the effect you want, take out the ‘;’ statements after the ‘else’ keywords.