Devices & Components
40 colored female-female jumper wires
16x2 LCD display with I²C interface
Capacitor 1000uF
RFP30N06LE 30A 60V Mosfet
Arduino Power Supply
Water Level Sensor
DHT11 Digital Temperature and Humidity Sensor DHT11 module
ELEGOO UNO R3 Board
Resistor 100k ohm
ELEDIY 10K Potentiometers
Ultrasonic Water Atomizer Module
5V DC Fan
Hardware & Tools
Solder Flux, Rosin
Tape, Black
soldering iron
Software & Tools
Arduino IDE
KiCad
Project description
Code
Main Code
cpp
None
1#include <Adafruit_Sensor.h> 2#include "dht.h" 3#include "Wire.h" // Library for I2C communication 4#include "LiquidCrystal_I2C.h" // Library for LCD 5dht DHT; 6 7const int supplyPin = 8; 8int potPin = A0; 9int waterSensor = A1; 10int lcDelayPin = A2; 11#define DHT11_PIN 7 //Setting Up Pin 7 as the DHT Sensor input, based on DHT sensor conventions 12 13LiquidCrystal_I2C mylcd = LiquidCrystal_I2C(0x27, 16, 2); //Defining the LCD Display 14 15void setup(){ 16 mylcd.init(); //Initiate LCD 17 mylcd.backlight(); //Turn on Backlight 18 pinMode(supplyPin,OUTPUT); //Pin 8 is output pin 19 pinMode(potPin,INPUT); //Pin A0 is Input 20 pinMode(waterSensor,INPUT); //Pin A1 is Input 21} 22//Line 23 - 43 are user defined functions 23 24int potIn(int x){ //Return potentiometer value as a % humidity 25 int result; 26 result = 0.06884*analogRead(x)+ 10; // The Lowest value 10%, Heighest is 80% 27 return result; 28} 29 30int waterlevel(){ //If the water level is below a certain threshold, it stops everything 31 while(analogRead(waterSensor)< 150){ 32 digitalWrite(supplyPin,LOW); 33 mylcd.clear(); 34 mylcd.setCursor(0,0); 35 mylcd.print("Low Water"); 36 delay(2000); 37 } 38} 39 40int lcDelay_function(int x){// Return Value from LC Network as Voltage Value, making sure 25 seconds have passed. 41 int result; 42 result = 0.0049*analogRead(x)+0.0174; 43 return result; 44} 45 46 47void loop(){ 48 49 waterlevel(); //Check Water Level 50 while(lcDelay_function(lcDelayPin)<4){//Check RC delay 51 52 delay(1000); 53 } 54 55 int chk = DHT.read11(DHT11_PIN);// Read Value of the DHT Sensor 56 mylcd.setCursor(0, 0); 57 mylcd.print("Humidity "); 58 mylcd.print(DHT.humidity); 59 60 mylcd.setCursor(0,1); 61 mylcd.print("Target ="); 62 mylcd.print(potIn(potPin)); 63 64 if (DHT.humidity < potIn(potPin)){ //if DHT value is less than Pot Value, turn on humidifier 65 digitalWrite(supplyPin,HIGH); 66 }else{ 67 digitalWrite(supplyPin,LOW); 68 } 69 70 71 delay(1000); 72}
Comments
Only logged in users can leave comments