Hello, I have searched for a way to fix my problem from cleaning the void loop, and such. But my journey is not successful!!
The thing is my Blynk APP and Codes works perfectly if these conditions are met, Arduino is connected to my computer via USB, and the power jack is connected to 12v power supply (optional) plus the esp8266 connection is established.
12V power supply is mainly used to power up my 12v fan.
I am using Arduino UNO and Esp8266.
Now what I am trying to do now is to remove that USB connection and only use the 12V power supply as my main power source (for now).
My guess is that when my project is connected to the computer, it is not disconnecting because of the serial monitoring being used at the time. On the other hand, it automatically disconnects because blynk server describe it as something unrelevant, cant find the words.
Codes:
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
BlynkTimer timer;
WidgetRTC rtc;
String currentTime;
String currentDate;
int sensorValue;
int PWM = 3;
int PWMVal;
//ARDUINO CONNECTION
int ledpin5 = 5;
// 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[] = "***"; //Network SSID for HOME: ***, SPHONE: ***
char pass[] = "***"; //Network PASS for HOME: ***, PHONE: ***
// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&Serial);
void setup()
{
// Debug console
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
Serial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
rtc.begin();
timer.setInterval(5000L, sendUptime);
timer.setInterval(5100L, clockDisplay);
timer.setInterval(5200L, sensorDataSend);
}
void sendUptime() {
Blynk.virtualWrite(0, millis() / 1000);
}
void clockDisplay()
{
// You can call hour(), minute(), ... at any time
// Please see Time library examples for details
int HOUR = hour();
if ( HOUR > 12 ) {
HOUR = HOUR - 12;
String currentTime = String(HOUR) + ":" + minute() + ":" + second() + " PM";
Blynk.virtualWrite(V2, currentTime); // Send PM time to the App
} else {
String currentTime = String(hour()) + ":" + minute() + ":" + second() + " AM"; ;
Blynk.virtualWrite(V2, currentTime); // Send AM time to the App
}
String currentDate = String(month()) + "-" + day() + "-" + year();
Blynk.virtualWrite(V1, currentDate); // Send date to the App
}
void sensorDataSend(){
sensorValue = analogRead(1);
Blynk.virtualWrite(A1, sensorValue);
Serial.print("Air Quality = ");
Serial.print(sensorValue, DEC); // prints the value read
Serial.println(" PPM");
delay(100);
if(sensorValue >50){
sensorValue = 100;
analogWrite(ledpin5, HIGH);
}
PWMVal = map(sensorValue, 50, 100, 15, 255);
if(sensorValue <25){
PWMVal = 0;
}
if(sensorValue <90){
analogWrite(ledpin5, LOW);
}
analogWrite(PWM, PWMVal);
}
void loop()
{
Blynk.run();
timer.run();
}