Qt Creator in Raspbery Pi (pyQT)
3D Design:
Actual Prototype:
Code Arduno Nano: (UART Serial Communication to Raspberry Pi)
#include <DHT.h>
// Define the pins
#define DHTPIN 2 // Pin connected to the DHT22 data pin
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define SOIL_MOISTURE_PIN A0 // Analog pin connected to soil moisture sensor
#define wet 210
#define dry 1023
// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Start serial communication
Serial.begin(9600);
// Initialize the DHT sensor
dht.begin();
}
void loop() {
// Read temperature as Celsius
float temp = dht.readTemperature();
// Read humidity
float humidity = dht.readHumidity();
// Read soil moisture sensor value
int soilMoistureValue = analogRead(SOIL_MOISTURE_PIN);
int moisturePercent = map(soilMoistureValue, dry, wet, 0, 100);
// Check if any reads failed and exit early (to try again)
if (isnan(temp) || isnan(humidity) || soilMoistureValue == 0) {
Serial.println("Failed to read from sensors!");
return;
}
// Create a string with the sensor values in the format val1,val2,val3
String sensorData = String(temp) + "," + String(humidity) + "," + String(moisturePercent);
// Send the string over Serial
Serial.println(sensorData);
// Delay for a second before sending the next values
delay(1000);
}