Hi All, I am creating a Blynk based irrigation system using a Wiolink with the following sensors:
- Valve Control Output Relay
- 1 ADC Soil Humidity Sensor
- 2 I2C ADS1015 connected Soil Humidity Sensors
- BMP085 Pressure Sensor
- Basic DHT Humidity/Temperature Sensor
- TSL2561 Light (UV) Sensor
- Battery Voltage Sensing (Via ADS1015)
All the code works (although a bit messy - im new to this so lots of copy paste) except I currently am using direct control of the relay on pin13 via GP13 in the App. However when switched on in the app, the relay goes on then randomly switches off (uncommanded) - likely due to the time it takes to execute the code somehow, is there a way of preventing this? Should connect the relay switch in the app to a virtual pin then code the relay to switch instead, any ideas of some code to do this? Thanks all, just a bit stuck at the moment
/*************************************************************
Irrigation System Controller
Based on WioLink Board with:
- Valve Control Output Relay
- 1 ADC Soil Humidity Sensor
- 2 I2C ADS1015 connected Soil Humidity Sensors
- BMP085 Pressure Sensor
- Basic DHT Humidity/Temperature Sensor
- TSL2561 Light (UV) Sensor
- Battery Voltage Sensing (Via ADS1015)
/*************************************************************/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
#include <DHT.h>
#include <Wire.h>
#include <wiring_private.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#include <Digital_Light_TSL2561.h>
#include <Adafruit_ADS1015.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "048ea82e09c24f768c80a047d2888326";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "SKY36D33";
char pass[] = "FPFXCAYC";
///////////////////////
// Hardware Settings //
///////////////////////
#define LED_PIN 5
#define RELAY_PIN 13
#define DHTPIN 12
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
Adafruit_ADS1015 ads1015; // Construct an ads1015 at the default address: 0x48
int analogPin = 0;
int moi0;
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void setup()
{
// Debug console
Wire.begin();
TSL2561.init();
ads1015.begin();
ads1015.setGain(GAIN_TWOTHIRDS); // 1x gain +/- 4.096V 1 bit = 2mV
Serial.begin(9600);
//Setup for Grove Modules
pinMode(15, OUTPUT);
digitalWrite(15, 1);
//INIT HARDWARE
pinMode(LED_PIN, OUTPUT); // LED output
pinMode(RELAY_PIN, OUTPUT); // RELAY
//Init Blynk
Blynk.begin(auth, ssid, pass);
dht.begin();
timer.setInterval(1000L, sendSensor);
/* Initialise the sensor */
if(!bmp.begin())
{
/* There was a problem detecting the BMP085 ... check your connections */
Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
while(1);
}
}
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
sensors_event_t event;
bmp.getEvent(&event);
float p = event.pressure;
float lx = TSL2561.readVisibleLux();
int16_t moi1 = ads1015.readADC_SingleEnded(0);
int16_t moi2 = ads1015.readADC_SingleEnded(1);
int16_t moi3 = ads1015.readADC_SingleEnded(2);
int16_t vcx = ads1015.readADC_SingleEnded(3);
moi0 = analogRead(analogPin);
float vcxcal;
float vxres;
float px;
vcxcal = (float)vcx/168.0; //Calculate Voltage
vxres = round(vcxcal*100)/100.0; //Round Voltage
px = (float)p + 10.6; //Calculate Pressure
px = round(px*10)/10.0; //Round Pressure
moi0= (float)moi0/8.61;
moi2= (float)moi2/11.9;
moi3= (float)moi3/11.9;
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
Blynk.virtualWrite(V7, px);
Blynk.virtualWrite(V8, lx);
Blynk.virtualWrite(V9, moi1);
Blynk.virtualWrite(V10, moi2);
Blynk.virtualWrite(V11, moi3);
Blynk.virtualWrite(V12, vxres); //Voltage Value Output
Blynk.virtualWrite(V13, moi0);
Blynk.virtualWrite(V14, vcx); //Voltage Calibration
}
void loop()
{
Blynk.run();
timer.run();
}