Hey there!
I'm kindda new at writing codes but I managed to make working ones for a DHT22 and an RD-SOIL3 sensor separately. However, I would need them to give serials together at the same time so I would need to combine my codes but I am not sure how to do it. Can someone please help in it ?
Code for DHT22:
#include <DHT.h>;
//Constants
#define DHTPIN 7 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
//Variables
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup()
{
Serial.begin(9600);
dht.begin();
}
void loop()
{
delay(2000);
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(1000); //Delay 2 sec.
}
Code for RD-SOIL3:
int sensorPin1 = A0;
int sensorPin2 = A1;
float sensorValue1;
float sensorValue2;
int limit = 340;
int limit2 = 617;
int limit3 = 715;
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
sensorValue2 = analogRead(sensorPin2);
if (sensorValue2>0) {
sensorValue2 = sensorValue2/limit3;
sensorValue2 = sensorValue2*100;
}
else {
sensorValue2;
}
Serial.print("RD-SOIL3|");
Serial.println(sensorValue2);
delay(4000);
}