EasyManua.ls Logo

SunFounder 3in1 Kit - Push Data to Blynk

Default Icon
351 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder 3in1 Kit
6. If you want to use Blynk on mobile devices, please refer to How to use Blynk on mobile device?.
How it works?
The difference between the code in this project and the code in the previous chapter 1.4 Connecting the R4 board to
Blynk is the following lines.
const int ledPin=6;
BLYNK_WRITE(V0)
{
int pinValue = param.asInt(); // assigning incoming value from pin V0 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
digitalWrite(ledPin,pinValue);
}
void setup()
{
pinMode(ledPin,OUTPUT);
}
Regarding the pinMode and digitalWrite of the ledPin, I’m sure you’re already familiar with them, so I won’t go
over them again. What you need to focus on is the BLYNK_WRITE(V0) function.
What it will do is that when the value of Blynk’s V0 changes, Blynk.Cloud will tell your device “I am writing to Virtual
Pin V0”, and your device will be able to perform something once it gets this information.
We created the V0 Datastream in the previous step and applied it to the Switch Widget. This means that every time we
operate the Switch Widget, BLYNK_WRITE(V0) will be triggered.
We write two instructions in this function.
int pinValue = param.asInt();
Get the value of V0 and assign it to the variable pinValue.
digitalWrite(ledPin,pinValue);
Write the value of V0 obtained to the ledPin, so that the Switch widget on Blynk can control the LED.
6.3 3. Push Data to Blynk
This chapter will show you how to send data to Blynk.
We create a door and window detection device here. The circuit with the reed switch is placed next to the door and
window, and the magnet is mounted on the edge of the door and window. When the door or window is closed, the
Reed Switch will be turned on by the magnetic force and the corresponding pin value on the R4 board will change.
Blynk.cloud will receive this value so that you can see if your house’s doors and windows are closed even when youre
away from home.
Now we will use an LED widget in Blynk to indicate if your windows and doors are closed (i.e. if the Reed Switch is
on or off).
Required Components
290 Chapter 6. IoT Projects

Related product manuals