I'm working on a greenhouse automation project.
I have two sensors reading values from the Arduino pins and sending serial values over to the rpi for processing. Then I have values coming from the RPI for manual overrides such as manual turn off of lamp, pump, etc.
I've gotten it working but:
when I open the serial monitor it prints normal values.
Then, when I send a value from the monitor or raspberry pi to it, it produces an error when reading the sensor and doesn't work until reboot(keeps printing errors.)
What could be the issue?
Arduino Uno, DHT22 sensor.
#include <idDHTLib.h>
idDHTLib DHTLib(2, idDHTLib::DHT22);
unsigned long previousMillis = 0;
const long interval = 10000;
void setup() {
pinMode(6, INPUT_PULLUP);
Serial.begin(115200);
pinMode(6,OUTPUT);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval && Serial.available() == 0) {
previousMillis = currentMillis;
int result = DHTLib.acquireAndWait();
int soilmoisture = analogRead(0);
if (result == IDDHTLIB_OK) {
Serial.print(DHTLib.getCelsius());
Serial.print("\t");
Serial.print(DHTLib.getHumidity());
Serial.print("\t");
Serial.print(soilmoisture);
Serial.println("");
Serial.flush();
} else {
Serial.println(result);
Serial.flush();
}
}
if (Serial.available() > 0 ) {
char kar = Serial.read();
switch(kar){
case 'H':
digitalWrite(6,HIGH);
break;
case 'L':
digitalWrite(6,LOW);
break;
}
}
}