Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- Pleasedontcode gives you this package free of charge and you
- can use it for your personal projects. We will not be held liable for
- any loss or damage of any kind. For all terms and conditions,
- please visit pleasedontcode.com/termsandconditions
- - Project: Asmodeus
- - Source Code created on: 2023-05-02 22:34:33
- - Source Code generated by: Alessandro
- ********* Pleasedontcode.com **********/
- /****** DEFINITION OF LIBRARIES *****/
- #include "Arduino.h"
- #include "DHT.h"
- #include "LiquidCrystal_I2C.h"
- /***** DEFINITION OF ANALOG INPUT PINS *****/
- #define soilMoistureSensor_PIN_A0 A0
- #define LDRSensor_PIN_A5 A5
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- #define BuzzerPin_PIN_D8 8
- #define fanPin_PIN_D9 9
- /***** DEFINITION OF INPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- unsigned int soilMoistureSensor_PIN_A0_rawData = 0; // Analog Input
- unsigned int LDRSensor_PIN_A5_rawData = 0; // Analog Input
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool BuzzerPin_PIN_D8_rawData = 0;
- bool fanPin_PIN_D9_rawData = 0;
- /***** DEFINITION OF INPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float soilMoistureSensor_PIN_A0_phyData = 0.0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float BuzzerPin_PIN_D8_phyData = 0.0;
- float fanPin_PIN_D9_phyData = 0.0;
- /***** DEFINITION OF DHT SENSOR *****/
- #define DHTPIN 2
- #define DHTTYPE DHT11
- DHT dht(DHTPIN, DHTTYPE);
- /***** DEFINITION OF LCD *****/
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- void setup()
- {
- // put your setup code here, to run once:
- pinMode(soilMoistureSensor_PIN_A0, INPUT);
- pinMode(LDRSensor_PIN_A5, INPUT);
- pinMode(BuzzerPin_PIN_D8, OUTPUT);
- pinMode(fanPin_PIN_D9, OUTPUT);
- lcd.init();
- lcd.backlight();
- dht.begin();
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- readDHTandPrintLCD();
- readSoilMoisturePrintLCD();
- readLDRsensorPrintOnLCD();
- turnOnFan();
- }
- void updateInputs()
- {
- soilMoistureSensor_PIN_A0_rawData = analogRead(soilMoistureSensor_PIN_A0);
- LDRSensor_PIN_A5_rawData = analogRead(LDRSensor_PIN_A5);
- }
- void updateOutputs()
- {
- digitalWrite(BuzzerPin_PIN_D8, BuzzerPin_PIN_D8_rawData);
- digitalWrite(fanPin_PIN_D9, fanPin_PIN_D9_rawData);
- }
- void readDHTandPrintLCD()
- {
- /***** REQUIREMENT 1 *****/
- /* use library "DHT.h" and "LiquidCrystal_I2C.h" */
- /***** REQUIREMENT 2 *****/
- /* DHT Type is DHT11 and is connected to pin 2 */
- /***** REQUIREMENT 3 *****/
- /* wait 4 seconds before to exit from function */
- /***** REQUIREMENT 4 *****/
- /* read average of humidity and temperature and print */
- /* on LCD. Print temperature on first row in degree */
- /* Celsius and humidity on second row with */
- /* percentage. */
- float h = dht.readHumidity();
- float t = dht.readTemperature();
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Temp: ");
- lcd.print(t);
- lcd.print("C");
- lcd.setCursor(0, 1);
- lcd.print("Humidity: ");
- lcd.print(h);
- lcd.print("%");
- delay(4000);
- }
- void readSoilMoisturePrintLCD()
- {
- /***** REQUIREMENT 1 *****/
- /* read soil Moisture from analog sensor and convert */
- /* it into percentage from 0 to 100%. */
- /***** REQUIREMENT 2 *****/
- /* print on LCD in first row the percentage. */
- /***** REQUIREMENT 3 *****/
- /* if percentage is lower than 80%, so print on LCD */
- /* in second row the sentence "Need water" otherwise */
- /* "No Water Needed". */
- /***** REQUIREMENT 4 *****/
- /* if percentage is lower than 80%, so turn on the */
- /* buzzer with value to HIGH otherwise turn off the */
- /* buzzer with value to LOW. */
- /***** REQUIREMENT 5 *****/
- /* wait 4 seconds before to exit from function */
- soilMoistureSensor_PIN_A0_rawData = analogRead(soilMoistureSensor_PIN_A0);
- soilMoistureSensor_PIN_A0_phyData = map(soilMoistureSensor_PIN_A0_rawData, 0, 1023, 0, 100);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Soil Moisture: ");
- lcd.print(soilMoistureSensor_PIN_A0_phyData);
- lcd.print("%");
- if (soilMoistureSensor_PIN_A0_phyData < 80)
- {
- lcd.setCursor(0, 1);
- lcd.print("Need water");
- BuzzerPin_PIN_D8_rawData = HIGH;
- }
- else
- {
- lcd.setCursor(0, 1);
- lcd.print("No Water Needed");
- BuzzerPin_PIN_D8_rawData = LOW;
- }
- delay(4000);
- }
- void readLDRsensorPrintOnLCD()
- {
- /***** REQUIREMENT 1 *****/
- /* read lux value from LDR sensor and convert from */
- /* analog value to lux multiplying by 500. Then print */
- /* on LCD in first row the lux value. */
- /***** REQUIREMENT 2 *****/
- /* wait 4 seconds before to exit from function */
- LDRSensor_PIN_A5_rawData = analogRead(LDRSensor_PIN_A5);
- float lux = LDRSensor_PIN_A5_rawData * 500.0 / 1023.0;
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("LDR Sensor: ");
- lcd.print(lux);
- lcd.print(" lux");
- delay(4000);
- }
- void turnOnFan()
- {
- /***** REQUIREMENT 1 *****/
- /* turn On Fan with fanPin to HIGH if temperature */
- /* value is above 30 degree celsius. Turn OFF Fan */
- /* with fanpin to LOW if temperature value is lower */
- /* than 30 degree celsius. */
- /***** REQUIREMENT 2 *****/
- /* Use histeresis to manage the control of activation */
- /* of fan depending by temperature value. */
- float t = dht.readTemperature();
- if (t > 32)
- {
- fanPin_PIN_D9_rawData = HIGH;
- }
- else if (t < 28)
- {
- fanPin_PIN_D9_rawData = LOW;
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement