lvennard
So my project is basically circulating a fluid through some membranes. I have temperature sensors, INA219 DC sensor etc…
My main challenge is the DC pump and a Valve assembly…
Requirements:I want to
1:Turn on DC Pump in intervals {delays} of 20 sec for 2 secs only.
2: After 10 times {of above} turn on the Valve +DC pump for 2 secs.
Lastly
3 :I’m using an ESP32 and the i2c {21,22 pins} are being used by the INA219 DC sensor can i add an LCD screen to use 2 i2c devices in BLYNK.
MY SAMPLE CODE: The problem is in the timers for the Valve and pump…
#define BLYNK_PRINT Serial
//****************************************************************************************************************************************************************************************
#include <WiFi.h>
#include <WiFiClient.h>
//****************************************************************************************************************************************************************************************
#include <OneWire.h>
#include<DallasTemperature.h>
#define ONE_WIRE_BUS 5 // GPI 05
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensorsA(&oneWire);
DallasTemperature sensorsB(&oneWire);
DallasTemperature sensorsC(&oneWire);
DallasTemperature sensorsD(&oneWire);
//********************************************************************For INA219 Electrical Current Voltage Power************************************************************************
#include <Wire.h>
#include <Adafruit_INA219.h>
//****************************************************************************************************************************************************************************************
#include <BlynkSimpleEsp32.h>
#include <TimeLib.h>
BlynkTimer timer;
//****************************************************************** CLOCK DETAILS ********************************************************************************************************
#include <WidgetRTC.h>//Blynk
WidgetRTC rtc;
//*****************************************************************For INA219 Electrical Current Voltage Power Sensor *********************************************************************
Adafruit_INA219 ina219 (0x40); // For INA219 Electrical Current Voltage Power Sensor
float shuntvoltage = 0; // For INA219 Electrical Current Voltage Power Sensor
float busvoltage = 0; // For INA219 Electrical Current Voltage Power Sensor
float current_mA = 0; // For INA219 Electrical Current Voltage Power Sensor
float loadvoltage = 0; // For INA219 Electrical Current Voltage Power Sensor
float power = 0;
float energy = 0;
float KiloJouleHour = 0;
float KiloJoule = 0;
//******************************************************************************** SECTION FOR YOU TO COMPLETE WITH YOUR DETAILS***********************************************************
char auth[] = "45b2a01b430d4849b756d31669692c31";
char ssid[] = "mifi";
char pass[] = "12345678";
char server[] = "blynk-cloud.com"; // URL for Blynk Cloud Server
int port = 8080;
//*********************************************************************************** SET PINS VARIBLES**************************************************************************************
uint8_t Valve = 13;
uint8_t Auger = 12;
uint8_t Mixer = 14;
uint8_t Pump = 27;
int PWM_Mixer;
int PWM_Auger;
int DeviceLED = 2;
String displaycurrenttime;
char Date[16];
char Time[16];
uint32_t currentFrequency; // For INA219 Current Sensor
//****************************************************************************************************************************************************************************************
void setup() {
pinMode(2, OUTPUT);
pinMode(Auger, OUTPUT);
pinMode(Mixer, OUTPUT);
pinMode(Valve, OUTPUT);
pinMode(Pump, OUTPUT);
//**************************************************************************************************************************************************************************************************************************************************
Blynk.begin(auth, ssid, pass);
Blynk.config(auth, server, port);
Blynk.connect();
rtc.begin(); //RTC CLOCK BEGIN
sensorsA.begin();
sensorsB.begin();
sensorsC.begin();
sensorsD.begin();
ina219.begin();
//**********************************************************************************************PWM SETTINGS****************************************************************************
ledcAttachPin(Auger, 1); // assign Auger pin to channels
ledcAttachPin(Mixer, 2); // assign Mixer pin to channels
ledcSetup(1, 100000, 12); // 100 kHz PWM, 12-bit resolution
ledcSetup(2, 100000, 12);
//****************************************************************************************************************************************************************************************
timer.setInterval(10000, readTemp);
timer.setInterval(30000, clockvalue);
timer.setInterval(1000, UpTime);
timer.setInterval(500, INA219);
timer.setInterval(20000, Pumpon);
timer.setInterval(70000, Valveon);
}
//****************************************************************************************************************************************************************************************
void loop() {
timer.run();
Blynk.run();
}
void Pumpon() {
digitalWrite(Pump, HIGH);
Blynk.virtualWrite(V7, 1);
timer.setTimeout(300, []() {
digitalWrite(Pump, LOW);
Blynk.virtualWrite(V7, 0);
});
}
void Valveon() {
digitalWrite(Valve, HIGH); //Turn yellow LED on
digitalWrite(Pump, HIGH); //Turn red LED on
Blynk.virtualWrite(V7, 1);
Blynk.virtualWrite(V8, 1);
timer.setTimeout(2000, []() {
digitalWrite(Valve, LOW); //Turn yellow LED off
Blynk.virtualWrite(V8, 0);
digitalWrite(Pump, LOW);
Blynk.virtualWrite(V7, 0);
});
}
void INA219() {
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
loadvoltage = busvoltage + (shuntvoltage / 1000); // V
power = (current_mA / 1000) * loadvoltage * 1000; // mW
energy = energy + (power / 1000 / 1000);
KiloJouleHour = ( power * 0.001 * 3.6);
KiloJoule = (energy * 0.001 * 3.6);
Blynk.virtualWrite(V10, current_mA * 0.001 ); //Convert from mA to Amps
Blynk.virtualWrite(V11, busvoltage);
Blynk.virtualWrite(V12, loadvoltage);
Blynk.virtualWrite(V13, power * 0.001); //Convert from mW to Watts
Blynk.virtualWrite(V14, energy * 0.001); //Convert from mWh to Wh
Blynk.virtualWrite(V15, KiloJouleHour); //Convert from mW to Watts
Blynk.virtualWrite(V16, KiloJoule); //Convert from mWh to Wh
}
void readTemp()
{
sensorsA.requestTemperatures();
sensorsB.requestTemperatures();
sensorsC.requestTemperatures();
sensorsD.requestTemperatures();
//*******************************************************************************
float floatTempA = sensorsA.getTempCByIndex(0);
char A_buffer[15];
dtostrf(floatTempA, 8, 9, A_buffer);
Blynk.virtualWrite(V20, A_buffer);
//*******************************************************************************
float floatTempB = sensorsB.getTempCByIndex(1);
char B_buffer[15];
dtostrf(floatTempB, 8, 9, B_buffer);
Blynk.virtualWrite(V21, B_buffer);
//*******************************************************************************
float floatTempC = sensorsC.getTempCByIndex(2);
char C_buffer[15];
dtostrf(floatTempC, 8, 9, C_buffer);
Blynk.virtualWrite(V22, C_buffer);
//*******************************************************************************
float floatTempD = sensorsD.getTempCByIndex(3);
char D_buffer[15];
dtostrf(floatTempD, 8, 9, D_buffer);
Blynk.virtualWrite(V23, D_buffer);
}
//****************************************************************************************************************************************************************************************
//****************************************************************************************************************************************************************************************
BLYNK_WRITE(V3) //slider in Virtual Pin 3 (0...4095)
{
PWM_Auger = param.asInt();
ledcWrite(1, PWM_Auger); // write red component to channel 1, etc. 0-4095
float voltage1 = map(PWM_Auger, 0, 4095, 0, 330);
Blynk.virtualWrite(V4, (voltage1) / 3.3);
}
//********************************************************************************************* Mixer always on ***********************************************************************************
BLYNK_WRITE(V5) //slider in Virtual Pin 5 (0...4095)
{
PWM_Mixer = param.asInt();
ledcWrite(2, PWM_Mixer); // write red component to channel 1, etc. 0-4095
float voltage2 = map(PWM_Mixer, 0, 4095, 0, 330);
Blynk.virtualWrite(V6, voltage2 / 3.3);
}
void clockvalue()
{
int gmthour = hour();
if (gmthour == 24) {
gmthour = 0;
}
String displayhour = String(gmthour, DEC);
int hourdigits = displayhour.length();
if (hourdigits == 1) {
displayhour = "0" + displayhour;
}
String displayminute = String(minute(), DEC);
int minutedigits = displayminute.length();
if (minutedigits == 1) {
displayminute = "0" + displayminute;
}
displaycurrenttime = displayhour + ":" + displayminute;
Blynk.virtualWrite(V40, displaycurrenttime);
}
void UpTime()
{
Blynk.virtualWrite(V30, millis() / 1000); // Send UpTime seconds to App
Blynk.virtualWrite(V31, (millis() / 1000) / 60); // Send UpTime minutes to App
digitalWrite(DeviceLED, !digitalRead(DeviceLED)); // Blink onboard LED
}