Advertisement
pleasedontcode

Program for Asmodeus

May 2nd, 2023
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 5.60 KB | Source Code | 0 0
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     Pleasedontcode gives you this package free of charge and you
  7.     can use it for your personal projects. We will not be held liable for
  8.     any loss or damage of any kind. For all terms and conditions,
  9.     please visit pleasedontcode.com/termsandconditions
  10.  
  11.     - Project: Asmodeus
  12.     - Source Code created on: 2023-05-02 22:34:33
  13.     - Source Code generated by: Alessandro
  14.  
  15. ********* Pleasedontcode.com **********/
  16.  
  17. /****** DEFINITION OF LIBRARIES *****/
  18. #include "Arduino.h"
  19. #include "DHT.h"
  20. #include "LiquidCrystal_I2C.h"
  21.  
  22. /***** DEFINITION OF ANALOG INPUT PINS *****/
  23. #define soilMoistureSensor_PIN_A0   A0
  24. #define LDRSensor_PIN_A5    A5
  25.  
  26. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  27. #define BuzzerPin_PIN_D8    8
  28. #define fanPin_PIN_D9   9
  29.  
  30. /***** DEFINITION OF INPUT RAW VARIABLES *****/
  31. /***** used to store raw data *****/
  32. unsigned int soilMoistureSensor_PIN_A0_rawData = 0; // Analog Input
  33. unsigned int LDRSensor_PIN_A5_rawData = 0; // Analog Input
  34.  
  35. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  36. /***** used to store raw data *****/
  37. bool BuzzerPin_PIN_D8_rawData = 0;
  38. bool fanPin_PIN_D9_rawData = 0;
  39.  
  40. /***** DEFINITION OF INPUT PHYSICAL VARIABLES *****/
  41. /***** used to store data after characteristic curve transformation *****/
  42. float soilMoistureSensor_PIN_A0_phyData = 0.0;
  43.  
  44. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  45. /***** used to store data after characteristic curve transformation *****/
  46. float BuzzerPin_PIN_D8_phyData = 0.0;
  47. float fanPin_PIN_D9_phyData = 0.0;
  48.  
  49. /***** DEFINITION OF DHT SENSOR *****/
  50. #define DHTPIN 2
  51. #define DHTTYPE DHT11
  52. DHT dht(DHTPIN, DHTTYPE);
  53.  
  54. /***** DEFINITION OF LCD *****/
  55. LiquidCrystal_I2C lcd(0x27, 16, 2);
  56.  
  57. void setup()
  58. {
  59.     // put your setup code here, to run once:
  60.     pinMode(soilMoistureSensor_PIN_A0, INPUT);
  61.     pinMode(LDRSensor_PIN_A5, INPUT);
  62.     pinMode(BuzzerPin_PIN_D8, OUTPUT);
  63.     pinMode(fanPin_PIN_D9, OUTPUT);
  64.     lcd.init();
  65.     lcd.backlight();
  66.     dht.begin();
  67. }
  68.  
  69. void loop()
  70. {
  71.     // put your main code here, to run repeatedly:
  72.     readDHTandPrintLCD();
  73.     readSoilMoisturePrintLCD();
  74.     readLDRsensorPrintOnLCD();
  75.     turnOnFan();
  76. }
  77.  
  78. void updateInputs()
  79. {
  80.     soilMoistureSensor_PIN_A0_rawData = analogRead(soilMoistureSensor_PIN_A0);
  81.     LDRSensor_PIN_A5_rawData = analogRead(LDRSensor_PIN_A5);
  82. }
  83.  
  84. void updateOutputs()
  85. {
  86.     digitalWrite(BuzzerPin_PIN_D8, BuzzerPin_PIN_D8_rawData);
  87.     digitalWrite(fanPin_PIN_D9, fanPin_PIN_D9_rawData);
  88. }
  89.  
  90. void readDHTandPrintLCD()
  91. {
  92.     /***** REQUIREMENT 1 *****/
  93.     /* use library "DHT.h" and "LiquidCrystal_I2C.h" */
  94.  
  95.     /***** REQUIREMENT 2 *****/
  96.     /* DHT Type is DHT11 and is connected to pin 2 */
  97.  
  98.     /***** REQUIREMENT 3 *****/
  99.     /* wait 4 seconds before to exit from function */
  100.  
  101.     /***** REQUIREMENT 4 *****/
  102.     /* read average of humidity and temperature and print */
  103.     /* on LCD. Print temperature on first row in degree */
  104.     /* Celsius and humidity on second row with */
  105.     /* percentage. */
  106.  
  107.     float h = dht.readHumidity();
  108.     float t = dht.readTemperature();
  109.  
  110.     lcd.clear();
  111.     lcd.setCursor(0, 0);
  112.     lcd.print("Temp: ");
  113.     lcd.print(t);
  114.     lcd.print("C");
  115.     lcd.setCursor(0, 1);
  116.     lcd.print("Humidity: ");
  117.     lcd.print(h);
  118.     lcd.print("%");
  119.  
  120.     delay(4000);
  121. }
  122.  
  123. void readSoilMoisturePrintLCD()
  124. {
  125.     /***** REQUIREMENT 1 *****/
  126.     /* read soil Moisture from analog sensor and convert */
  127.     /* it into percentage from 0 to 100%. */
  128.  
  129.     /***** REQUIREMENT 2 *****/
  130.     /* print on LCD in first row the percentage. */
  131.  
  132.     /***** REQUIREMENT 3 *****/
  133.     /* if percentage is lower than 80%, so print on LCD */
  134.     /* in second row the sentence "Need water" otherwise */
  135.     /* "No Water Needed". */
  136.  
  137.     /***** REQUIREMENT 4 *****/
  138.     /* if percentage is lower than 80%, so turn on the */
  139.     /* buzzer with value to HIGH otherwise turn off the */
  140.     /* buzzer with value to LOW. */
  141.  
  142.     /***** REQUIREMENT 5 *****/
  143.     /* wait 4 seconds before to exit from function */
  144.  
  145.     soilMoistureSensor_PIN_A0_rawData = analogRead(soilMoistureSensor_PIN_A0);
  146.     soilMoistureSensor_PIN_A0_phyData = map(soilMoistureSensor_PIN_A0_rawData, 0, 1023, 0, 100);
  147.  
  148.     lcd.clear();
  149.     lcd.setCursor(0, 0);
  150.     lcd.print("Soil Moisture: ");
  151.     lcd.print(soilMoistureSensor_PIN_A0_phyData);
  152.     lcd.print("%");
  153.  
  154.     if (soilMoistureSensor_PIN_A0_phyData < 80)
  155.     {
  156.         lcd.setCursor(0, 1);
  157.         lcd.print("Need water");
  158.         BuzzerPin_PIN_D8_rawData = HIGH;
  159.     }
  160.     else
  161.     {
  162.         lcd.setCursor(0, 1);
  163.         lcd.print("No Water Needed");
  164.         BuzzerPin_PIN_D8_rawData = LOW;
  165.     }
  166.  
  167.     delay(4000);
  168. }
  169.  
  170. void readLDRsensorPrintOnLCD()
  171. {
  172.     /***** REQUIREMENT 1 *****/
  173.     /* read lux value from LDR sensor and convert from */
  174.     /* analog value to lux multiplying by 500. Then print */
  175.     /* on LCD in first row the lux value. */
  176.  
  177.     /***** REQUIREMENT 2 *****/
  178.     /* wait 4 seconds before to exit from function */
  179.  
  180.     LDRSensor_PIN_A5_rawData = analogRead(LDRSensor_PIN_A5);
  181.     float lux = LDRSensor_PIN_A5_rawData * 500.0 / 1023.0;
  182.  
  183.     lcd.clear();
  184.     lcd.setCursor(0, 0);
  185.     lcd.print("LDR Sensor: ");
  186.     lcd.print(lux);
  187.     lcd.print(" lux");
  188.  
  189.     delay(4000);
  190. }
  191.  
  192. void turnOnFan()
  193. {
  194.     /***** REQUIREMENT 1 *****/
  195.     /* turn On Fan with fanPin to HIGH if temperature */
  196.     /* value is above 30 degree celsius. Turn OFF Fan */
  197.     /* with fanpin to LOW if temperature value is lower */
  198.     /* than 30 degree celsius. */
  199.  
  200.     /***** REQUIREMENT 2 *****/
  201.     /* Use histeresis to manage the control of activation */
  202.     /* of fan depending by temperature value. */
  203.  
  204.     float t = dht.readTemperature();
  205.  
  206.     if (t > 32)
  207.     {
  208.         fanPin_PIN_D9_rawData = HIGH;
  209.     }
  210.     else if (t < 28)
  211.     {
  212.         fanPin_PIN_D9_rawData = LOW;
  213.     }
  214.  
  215.     delay(1000);
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement