zhexo

Smart Agriculture - controlling the water level

Jan 24th, 2024
1,255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.38 KB | Source Code | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include "IFTTTWebhook.h"
  3.  
  4. #define WIFI_SSID "your SSID here"
  5. #define WIFI_PASSWORD "your password here"
  6. #define IFTTT_API_KEY "ceubX8trC3ZXKFTrEMXc-Z"  //the Webhooks key.
  7. #define IFTTT_EVENT_NAME "oximetry_heart_rate_sensor" //the event name.
  8.  
  9. int adc_id = 0;
  10. int HistoryValue = 0;
  11. char printBuffer[128];
  12.  
  13. // constants won't change
  14. const int RELAY_PIN = A5;  // the Arduino pin, which connects to the IN pin of relay
  15.  
  16. void setup()
  17.  WiFi.mode(WIFI_STA);
  18.  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  19.  
  20.   IFTTTWebhook wh(IFTTT_API_KEY, IFTTT_EVENT_NAME);
  21.   wh.trigger(value);
  22.  
  23. {
  24.   Serial.begin(9600);
  25.   pinMode(RELAY_PIN, OUTPUT); // initialize digital pin A5 as an output.
  26.   digitalWrite(RELAY_PIN, LOW);  // turn off pump
  27. }
  28.  
  29. void loop()
  30. {
  31.     int value = analogRead(adc_id); // get adc value from A0
  32.  
  33.     if(((HistoryValue>=value) && ((HistoryValue - value) > 10)) || ((HistoryValue<value) && ((value - HistoryValue) > 10)))
  34.     {
  35.       sprintf(printBuffer,"ADC%d level is %d\n",adc_id, value);
  36.       Serial.print(printBuffer);
  37.       HistoryValue = value;
  38.     }
  39.     if(value < 50)  // parameter should be adjusted to the waterer low level
  40.     {
  41.       digitalWrite(RELAY_PIN, HIGH); // turn on pump
  42.     }
  43.     if(value > 600)  // parameter should be adjusted to the waterer high level
  44.     {
  45.       digitalWrite(RELAY_PIN, LOW);  // turn off pump
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment