Please help.
I have mega+esp8266 as a shield+local server.
I use arduino to read a reed sensor in actuator so I can monitor the actuator whether actuator extend or retract and the position.
When it runs without blynk it works fine and smooth, every position of actuator is represented by percentage. Here is the code without blynk.
#define A 53
#define B 52
int persen;
int counter = 0;
int diam;
int akhir;
void setup() {
pinMode(A, INPUT);
pinMode(B, INPUT);
Serial.begin(9600);
akhir=digitalRead(A);}
void loop() {
diam=digitalRead(A);
if (diam!=akhir){
if(digitalRead(B)== HIGH){
counter ++;
}else{
counter --;}
persen = map(counter, 0, 530, 0, 100);
Serial.print("OPEN: ");
Serial.print(persen);
Serial.println("%");}
delay(1);
akhir=diam;}
But when I want to monitor the actuator position through my phone use blynk, the percentage does not represent the position, the actuator keep extend or retract but the percentage does not show smoothly, sometime it get stuck. Here is the code with blynk.
#define A 53
#define B 52
int persen;
int counter = 0;
int diam;
int akhir;
#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[] = "d05e00cacfbf431e8061c8c2bc7d3b26";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "joni";
char pass[] = "1234567890";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115000
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
void sensor(){
diam=digitalRead(A);
if (diam!=akhir){
if(digitalRead(B)== HIGH){
counter ++;
}else{
counter --;}
persen = map(counter, 0, 530, 0, 100);
Serial.print("OPEN: ");
Serial.print(persen);
Serial.println("%");
akhir=diam;}
Blynk.virtualWrite(V5, persen);}
void setup (){
pinMode(A, INPUT);
pinMode(B, INPUT);
Serial.begin (9600);
akhir=digitalRead(A);
timer.setInterval(1, sensor);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(1);
Blynk.begin(auth, wifi, ssid, pass, "192.168.23.1", 8080);
delay(100);
}
void loop (){
timer.run();
Blynk.run();
}
I tried to put the code of the sensor in the void loop without blynk.timer but the result is the same.
I sent the picture of the actuator and sensor.
Thank you.