Hi Kevin.
You need a widget in the blynk application that allows you to display the values, such as a labeled value, an LCD, a terminal, or even a led, a button, etc.
After put the widget in the app configure the pin associated od that widget to a virtual pin like V0 and in your program code…
Blynk.virtualWrite(V0,“magnet is Found”) if the widget can handle text, some widgets has their own way to do this… like WidgetLCD.print(…) etc.
if is something else like a led you can do this:
Blynk.virtualWrite(V0,0); // if no magnet found
Blynk.virtualWrite(V0,255); // if yes
And forget another thing, you do not need to do more than use the code line for the correct state…
For the next time you have any questions it would be very helpful if you included your source code, so we would know better what you want to do, what things you have available (sensors, type of mainboard, etc) and we could assist you in a more satisfactory way.
This is an example:
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(4, 5); // RX, TX
#define ESP8266_BAUD 115200
char auth[] = "YourAuthCode";
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
const int pinSwitch = 2; //Pin Reed
const int pinLed = 9; //Pin LED
ESP8266 wifi(&EspSerial);
BLYNK_CONNECTED()
{
Blynk.syncAll();
}
void magnetFound()
{
bool isFound=digitalRead(pinSwitch);
digitalWrite(pinLed, isFound);
Serial.print((isFound)?"MAGNET FOUND":"MAGNET NOT FOUND");
Blynk.virtualWrite(V0,isFound);
}
void setup()
{
Serial.begin(9600);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
pinMode(pinLed, OUTPUT); //Imposto i PIN
pinMode(pinSwitch, INPUT);
attachInterrupt(digitalPinToInterrupt(pinSwitch), magnetFound, CHANGE);
}
void loop()
{
Blynk.run();
}
I don’t know why you want to use interrupts… but keep in mind that:
Within the Interrupt function, delay () will not work and the value returned by Millis () will not increase. Serial data received, while the function is active can be lost. You must declare as volatile any variable that is modified within the interruption function.
So is better to use timers to check sensor value instead use interrupts…
Something like
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
#include <Tasker.h>
#define ESP8266_BAUD 115200
Tasker Task(true);
bool PrevValue;
SoftwareSerial EspSerial(4, 5); // RX, TX
char auth[] = "YourAuthCode";
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
const int pinSwitch = 2; //Pin Reed
const int pinLed = 9; //Pin LED
ESP8266 wifi(&EspSerial);
BLYNK_CONNECTED()
{
Blynk.syncAll();
}
void magnetFound()
{
bool isFound=digitalRead(pinSwitch);
if (PrevValue!=IsFound)
{
PrevValue=IsFound;
digitalWrite(pinLed, isFound);
Serial.print((isFound)?"MAGNET FOUND":"MAGNET NOT FOUND");
Blynk.virtualWrite(V0,isFound);
}
}
void setup()
{
Serial.begin(9600);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
pinMode(pinLed, OUTPUT); //Imposto i PIN
pinMode(pinSwitch, INPUT);
PrevValue=digitalRead(pinSwitch);
Task.setInterval(magnetFound, 100L);
}
void loop()
{
Blynk.run();
Task.loop();
}