Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill-in information from your Blynk Template here
- #define BLYNK_TEMPLATE_ID "TMPL3bTnPK_y"
- #define BLYNK_DEVICE_NAME "ZoneCommand"
- #define BLYNK_FIRMWARE_VERSION "0.1.2"
- #define BLYNK_PRINT Serial
- //#define BLYNK_DEBUG
- #define APP_DEBUG
- // Uncomment your board, or configure a custom board in Settings.h
- //#define USE_WROVER_BOARD
- //#define USE_TTGO_T7
- #include "BlynkEdgent.h"
- // Set Pin Assignments For Output Pins
- // MOSFETS:
- const int output[] = {4,16,17,18};
- //Motor Drivers:
- //U4 Motor Driver:
- const int mtrOutA1 = 22;
- const int mtrOutA2 = 23;
- //U7 Motor Driver:
- const int mtrOutB1 = 19;
- const int mtrOutB2 = 21;
- //Set Pin Assignments for Input Pins
- //Analog Inputs:
- //Moisture Sensors:
- const int sensPin[] = {35,34,39,36};
- //Water Level Sensors:
- const int wtrLvlTop = 26;
- const int wtrLvlBtm = 27;
- //Zone Loop Controls
- int zoneNumber = 0;
- int triggerHigh[] = {550,550,550,550};
- int triggerLow[] = {670,670,670,670};
- bool zoneActive[] = {true, true, true, true};
- bool zoneManual[] = {false,false,false,false};
- bool zoneAuto[] = {true,true,true,true};
- bool zoneAutoTimer[] = {false,false,false,false};
- bool zonePump[] = {false,false,false,false};
- bool zoneManualPump[] = {false,false,false,false};
- // Sensor Data:
- int sensor[] = {0, 0, 0, 0}; // Sensor reading values array
- int topWtrLvl = 0;
- int btmWtrLvl = 0;
- int lowWater = 700;
- int highWater = 500;
- // Timer Variables
- const int manualDayTimer[] = {86400000, 86400000, 86400000, 86400000}; // delay for once a day manual watering mode
- unsigned long lastManualDayTimer[] = {0, 0, 0, 0,};
- unsigned long pumpTimer[] = {60000, 60000, 60000, 60000}; //Pump timers in array
- unsigned long lastPumpTimer[] = {0, 0, 0, 0}; // last value of Pump timers in array
- BlynkTimer timer;
- void setup()
- {
- // Set OUT Pins to Output
- pinMode(output[0], OUTPUT);
- pinMode(output[1], OUTPUT);
- pinMode(output[2], OUTPUT);
- pinMode(output[3], OUTPUT);
- // Set Sensor Pins to Input
- pinMode(sensPin[0], INPUT);
- pinMode(sensPin[1], INPUT);
- pinMode(sensPin[2], INPUT);
- pinMode(sensPin[3], INPUT);
- // set Water Level Pins to Input
- pinMode(wtrLvlTop, INPUT);
- pinMode(wtrLvlBtm, INPUT);
- //Blynk Timers
- BlynkEdgent.begin();
- timer.setInterval(1000,sensorRead);
- timer.setInterval(1000,blynkData);
- timer.setInterval(1000,waterLevel);
- //timer.setInterval(500, zonePump);
- Serial.begin(115200);
- delay(100);
- }
- void sensorRead()
- {
- for (zoneNumber = 0; zoneNumber < 3; zoneNumber++) {
- if (zoneActive[zoneNumber]) {
- sensor[zoneNumber] = analogRead(sensPin[zoneNumber]);
- Serial.println(sensor[zoneNumber];
- }
- }
- for (zoneNumber = 3; zoneNumber > 0; zoneNumber = 0) {
- if (zoneActive[zoneNumber]) {
- sensor[zoneNumber] = analogRead(sensPin[zoneNumber]);
- }
- }
- }
- void blynkData()
- {
- Blynk.virtualWrite(V0, sensor[0]);
- Blynk.virtualWrite(V1, sensor[1]);
- Blynk.virtualWrite(V2, sensor[2]);
- Blynk.virtualWrite(V3, sensor[3]);
- }
- void waterLevel()
- {
- int topWtrLvl = analogRead(wtrLvlTop);
- int btmWtrLvl = analogRead(wtrLvlBtm);
- if (btmWtrLvl > lowWater) {
- digitalWrite(mtrOutA1, HIGH);
- digitalWrite(mtrOutA2, LOW);
- Blynk.virtualWrite(V4, HIGH);
- }
- if (topWtrLvl < highWater) {
- digitalWrite(mtrOutA1, LOW);
- digitalWrite(mtrOutA2, LOW);
- Blynk.virtualWrite(V4, LOW);
- }
- }
- void loop() {
- BlynkEdgent.run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement