Cool ProjectsGeneral

Greenhouse automation with LattePanda

userHead VM1 2021-02-03 09:54:59 5853 Views0 Replies
Hello, Ive been working on temperature based relay activation using LattePanda V1. Main use for this is my future greenhouse where Id like to grow chilies. I want to water the plants and ventilate the greenhouse automatically. It is not designed to be a 100% human interaction free, but it should make it possible to stay away for a week or so without the plants getting too dry.

In short, the code checks the temperature from the sensor and based on the reading it can set diffrent types of relay sequences that last 24 hours at a time. These sequences can be easily modified and its highly likely that I need to do so because I dont have the greenhouse yet. Hopefully I can start building the greenhouse in few months or so.
In the future Id like to add a Telegram bot to send messeges to my smartphone if the water supply is running low. I think I could use a float swich as an analog sensor but Im not sure how to embed all of that in to the existing code yet.

All of the above runs with LattePandas built-in Arduino but Im also using the LP's Windows OS to create a webcam stream from the greenhouse in the future. Also its easy to adjust parameters via remote-desktop without being on-site if needed.

P.S.
This is my first ever Arduino code so I think there is probably a million things someone with more experience could do better. But hey, its a start!

The code can be found here:

Code: Select all

// Green house automatic ventilation and watering with LattePanda V1 built-in Arduino module, DHT22 temperature and humidity sensor and a four-channel relay board (VMA400). // Based on: https://www.electroschematics.com/arduino-dht22-am2302-tutorial-library/ #include <DHT.h> #include "DHT.h" #define DHTPIN 6 // What pin DHT22 data is coming from - LattePanda physical pin 14 #define DHTTYPE DHT22 // DHT 22 (AM2302) // DEFINE TEMPERATURES IN CELSIUS int maxTemp = 27; int medTemp = 20; int lowTemp = 15; DHT dht(DHTPIN, DHTTYPE); // DEFINE RELAY PINS int R1 = 12; // Relay 1, connected to digital pin 12 - LattePanda physical pin 11 int R2 = 21; // Relay 2, connected to digital pin 21 - LattePanda physical pin 15 int R3 = 22; // Relay 3, connected to digital pin 22 - LattePanda physical pin 17 int R4 = 23; // Relay 4, connected to digital pin 23 - LattePanda physical pin 19 // R1 is for water pump // R2 is for fans // R3 is not used // R4 is not used void setup() { pinMode(R1, OUTPUT); // sets digital pins as output pinMode (R2, OUTPUT); pinMode (R3, OUTPUT); pinMode (R4, OUTPUT); Serial.begin(9600); dht.begin(); } void loop() { // Wait a few seconds between measurements. delay(3000); // Read temperature as Celsius float t = dht.readTemperature(); // Check if any reads failed and exit early (to try again). if (isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } // Print temperature data to serial monitor Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(t); Serial.println(" *C "); // WATERING AND VENTILATION DURATIONS BASED ON TEMPERATURE // IF TEMPERATURE IS LOWER THAN 15C: if(t < lowTemp) { digitalWrite(R1, HIGH); delay (60000); // Water pump ON for 1 minute digitalWrite (R1, LOW); // Pump OFF digitalWrite (R2, HIGH); // Fans ON delay (3600000); // Fans ON duration (1 hour) digitalWrite (R2, LOW); // Fans OFF // TOTAL TIME: 1 HOUR 1 MINUTE delay (82740000); // 22 hour 59 minute delay to start the code again next day. } // IF TEMPERATURE IS 20C ... 26.9C: if (t > medTemp && t <= maxTemp) { digitalWrite(R1, HIGH); delay (120000); // Water pump ON for 2 minutes digitalWrite (R1, LOW); // Pump OFF delay (7200000); // 2 hour delay digitalWrite (R2, HIGH); // Fans ON delay (3600000); // Fan ON duration (1 hour) digitalWrite (R2, LOW); // Fan OFF delay (7200000); // 2 hour delay digitalWrite (R2, HIGH); // Fans ON delay (3600000); // Fan ON duration (1 hour) digitalWrite (R2, LOW); // Fan OFF // TOTAL TIME: 6 HOURS 2 MINUTES delay (64680000); // 17h 58min delay to start the code again next day. } // IF TEMPERATURE IS HINGER THAN 27C: if(t > maxTemp) { digitalWrite(R1, HIGH); delay (300000); // Water pump ON for 5 minutes digitalWrite (R1, LOW); // Pump OFF delay (7200000); // 2 hour delay digitalWrite (R2, HIGH); // Fans ON delay (14400000); // Fan ON duration (4 hours) digitalWrite (R2, LOW); // Fans OFF // TOTAL TIME: 6 HOURS 5 MINUTES delay (64500000); // 17h 55min delay to start the code again next day. } } Attachments gardenpanda.jpg gardenpanda.jpg (2.7 MiB) Viewed 4377 times