Hallo,
Ich möchte mit einem Arduino ein Servo Temperaturabhängig steuern.
Wenn die Temperatur von 24C untern oder überschritten wird soll das
servo schrittweise nach links oder rechts drehen bis die Temperatur
wieder die 24C erreicht hat.
Eine Thermostat Funktion also.
Das auslesen des Sensors bekomme ich hin, auch die Ansteuerung des
Servos einzeln.
Hier etwas Code der Rest ist im Anhang:
1 | #include <Wire.h>
|
2 | #include <Servo.h>
|
3 | Servo servo1;
|
4 | #include <LiquidCrystal_I2C.h>
|
5 | LiquidCrystal_I2C lcd(0x3F,20,4); // set the LCD address to 0x3F for a 16 chars and 4 line display
|
6 |
|
7 | void setup() {
|
8 | #define HYT_ADDR 0x28 // I2C address of the HYT 221, 271, 371 and most likely the rest of the family
|
9 | Wire.begin(); // Join I2c Bus as master
|
10 | pinMode(13, OUTPUT); // Set pin 13 to output for status LED
|
11 | // I2C Pins on the Arduino Uno are A4 for SDA and A5 for SCL
|
12 | Serial.begin(9600); // Start serial communication for serial console output
|
13 | lcd.init();
|
14 | lcd.backlight();
|
15 |
|
16 |
|
17 | float val3;
|
18 | val3 = 50;
|
19 | servo1.attach(33);
|
20 |
|
21 | servo1.writeMicroseconds(1500); // set servo to mid-point
|
22 | delay(3000);
|
23 |
|
24 |
|
25 | }
|
26 |
|
27 | void loop() {
|
28 | float humidity;
|
29 | float temperature;
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | temperature = getTemp();
|
35 | humidity = getHum();
|
36 | Serial.println(temperature);
|
37 | Serial.println(humidity);
|
38 | lcd.clear();
|
39 | lcd.setCursor(0,0);
|
40 | lcd.print(temperature);
|
41 | lcd.setCursor(0,1);
|
42 | lcd.print(humidity);
|
43 |
|
44 |
|
45 | float val2;
|
46 | float val3;
|
47 | float soll;
|
48 | soll = 24;
|
49 | Serial.println(val3);
|
50 | delay(3500);
|
51 |
|
52 | if(temperature < soll){
|
53 |
|
54 | val3++;
|
55 |
|
56 | }
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | val2 = map(val3, 0, 100, 1600, 1400);
|
62 | servo1.writeMicroseconds(val2);
|
63 | delay(500);
|
64 | //blinkWait();
|
65 | }
|
Das Problem ist das mir die Variable "val3" immer als 0 ausgegeben wird.
Obwohl ich sie im setup mit dem wert 50 belegt habe und durch die
if-Funktion sie erhöht werden sollte.
Was hab ich da falsch gemacht?
Schonmal danke im voraus ;)