Thank you very much for the reply! really appreciate it. I have been trying to use a serial.print to display the excution time but I cant seem to get the serial monitor to display anyhing except the BLYNK logo, connected, etc, ready. I dont think i have the proper understanding. I am trying to graph the data over time with the super chart widget so I would only need to send each sensor data once every minute or so. I have looked into the Lambda timeout timer and also not grasping the understanding of it. I just feel like I am making it more complicated then it needs to be .
With the pump, I originally was trying to control the duration of the pump relay by a blynk step widget 100-5000 mL with 100 mL steps. With each step of 100 mL calibrated with an equation and variable to determine length of time a relay is on depending on the pump flow output. I was then told I cant do this and have to incorporate the terminal to display this information and a widget displaying 0-80 to calculate desired mL of water output and then mL outputted to terminal which doesnt make sense to me.
#include <SPI.h>
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "*******";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "******";
char pass[] = "******";
#define WATER_PUMP1 27 // relay pin
#define VPIN_PUMP1ON V14 // Blynk button to control relay
#define VPIN_SLIDERTIMEON_PUMP1 V16 // blynk app Numeric Input Widget
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial3
// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
int buttonState; //expecting 0 or 1
float stepValue; //expecting 0.00-80.00
float ml; //Step Widget to determine amount of ml/Output 0-80/Step 0.2
uint32_t startCount; //Millis reference used to calculate stopCount
uint32_t stopCount; //
uint32_t multiplier = 858; //Number of milliseconds for motor to produce 1ml of liquid
BlynkTimer timer; // Announcing the timer
WidgetTerminal terminal(V18);
//int solenoidPin = 30; // solenoid valve pin
const int AirValue = 620; //you need to replace this value with Value_1
const int WaterValue = 280; //you need to replace this value with Value_2
int soilMoistureValue = 0;
int soilmoisturepercent = 0;
unsigned long sensortime;
void checkPump()
{
if (buttonState == 1)
{
ml = stepValue * multiplier; //Step Widget Value times Calibration Multiplier
startCount = millis(); //Reference the Millis count
stopCount = ml + startCount;
terminal.print("stepValue is: ");
terminal.println(stepValue);
terminal.print("ml: ");
terminal.println(ml);
terminal.print("startCount is: ");
terminal.println(startCount);
terminal.print("stopCount is: ");
terminal.println(stopCount);
Blynk.virtualWrite(buttonState, 0);
terminal.flush();
}
if (stopCount <= (millis() - startCount)) //If V0 x multi + start is less than or equal to total millis
{
digitalWrite(WATER_PUMP1, HIGH);
terminal.println("LED");
terminal.flush();
}
else buttonState = 0;
{
ml = 0;
startCount = 0;
stopCount = 0;
digitalWrite(WATER_PUMP1, LOW);
}
}
// This function tells Arduino what to do if there is a Widget
// which is requesting data for Virtual Pin (5)
//BLYNK_READ(V0)
// Push Soil Sensor values to Blynk graph
void soilsensorDataSend()
// Capacitive Soil Moisture Sensor V1.2 A1
{
Serial.print("Sensor Start Time: ");
sensortime = millis();
Serial.println(sensortime); //prints time since program started
{
soilMoistureValue = analogRead(A4); // reading sensor from analog pin
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
soilmoisturepercent = constrain(soilmoisturepercent, 0, 100);
Blynk.virtualWrite(V0, soilmoisturepercent); // sending sensor value to Blynk app
// Capacitive Soil Moisture Sensor V1.2 A2
soilMoistureValue = analogRead(A5); // reading sensor from analog pin
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
soilmoisturepercent = constrain(soilmoisturepercent, 0, 100);
Blynk.virtualWrite(V1, soilmoisturepercent); // sending sensor value to Blynk app
// Capacitive Soil Moisture Sensor V1.2 A3
soilMoistureValue = analogRead(A6); // reading sensor from analog pin
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
soilmoisturepercent = constrain(soilmoisturepercent, 0, 100);
Blynk.virtualWrite(V2, soilmoisturepercent); // sending sensor value to Blynk app
// Capacitive Soil Moisture Sensor V1.2 A4
soilMoistureValue = analogRead(A7); // reading sensor from analog pin
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
soilmoisturepercent = constrain(soilmoisturepercent, 0, 100);
Blynk.virtualWrite(V3, soilmoisturepercent); // sending sensor value to Blynk app
// Capacitive Soil Moisture Sensor V1.2 B1
soilMoistureValue = analogRead(A8); // reading sensor from analog pin
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
soilmoisturepercent = constrain(soilmoisturepercent, 0, 100);
Blynk.virtualWrite(V4, soilmoisturepercent); // sending sensor value to Blynk app
// Capacitive Soil Moisture Sensor V1.2 B2
soilMoistureValue = analogRead(A9); // reading sensor from analog pin
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
soilmoisturepercent = constrain(soilmoisturepercent, 0, 100);
Blynk.virtualWrite(V5, soilmoisturepercent); // sending sensor value to Blynk app
// Capacitive Soil Moisture Sensor V1.2 B3
soilMoistureValue = analogRead(A10); // reading sensor from analog pin
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
soilmoisturepercent = constrain(soilmoisturepercent, 0, 100);
Blynk.virtualWrite(V6, soilmoisturepercent); // sending sensor value to Blynk app
// Capacitive Soil Moisture Sensor V1.2 B4
soilMoistureValue = analogRead(A11); // reading sensor from analog pin
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
soilmoisturepercent = constrain(soilmoisturepercent, 0, 100);
Blynk.virtualWrite(V7, soilmoisturepercent); // sending sensor value to Blynk app
// Capacitive Soil Moisture Sensor V1.2 C1
soilMoistureValue = analogRead(A12); // reading sensor from analog pin
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
soilmoisturepercent = constrain(soilmoisturepercent, 0, 100);
Blynk.virtualWrite(V8, soilmoisturepercent); // sending sensor value to Blynk app
// Capacitive Soil Moisture Sensor V1.2 C2
soilMoistureValue = analogRead(A13); // reading sensor from analog pin
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
soilmoisturepercent = constrain(soilmoisturepercent, 0, 100);
Blynk.virtualWrite(V9, soilmoisturepercent); // sending sensor value to Blynk app
// Capacitive Soil Moisture Sensor V1.2 C3
soilMoistureValue = analogRead(A14); // reading sensor from analog pin
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
soilmoisturepercent = constrain(soilmoisturepercent, 0, 100);
Blynk.virtualWrite(V10, soilmoisturepercent); // sending sensor value to Blynk app
// Capacitive Soil Moisture Sensor V1.2 C4
soilMoistureValue = analogRead(A15); // reading sensor from analog pin
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
soilmoisturepercent = constrain(soilmoisturepercent, 0, 100);
Blynk.virtualWrite(V11, soilmoisturepercent); // sending sensor value to Blynk app
Serial.print("Sensor Stop Time: ");
time = millis();
Serial.println(sensortime); //prints time since program started
}
}
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(WATER_PUMP1, OUTPUT);
//pinMode(solenoidPin, OUTPUT);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
Blynk.begin(auth, wifi, ssid, pass);
while (Blynk.connect() == false) {}
timer.setInterval(2000L, soilsensorDataSend); //timer will run every 2 sec
delay(500);
timer.setInterval(3000L, checkPump); //timer will run every 3 sec
Blynk.syncVirtual(V14);
// You can also specify server:
//Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);
}
void loop()
{
Blynk.run();
timer.run(); // run timer every second
}
// set as globals
BLYNK_WRITE(V14) { // blynk button
buttonState = param.asInt(); // set the global button state as ON or OFF
Serial.println(String("button state = ") + buttonState); // will output 1 or 0 to serial monitor
Blynk.syncVirtual(V1); // trigger V1 function below to set current stepValue from widget, also put this line in setup() right after connecting to update on boot
}
BLYNK_WRITE(V16) { //blynk step widget
stepValue = param.asFloat(); // set the global step value
Serial.println(String("stepValue = ") + stepValue ); // will output stepValue to serial
}