-
Notifications
You must be signed in to change notification settings - Fork 8
Exercise 12: Internet of Things, Blynk
In this exercise, we will begin the journey of Practical Internet of Things (IoT) with Arduino.
You might have heard IoT somewhere ... in Seminar, Webinar, Podcast, YouTube or even from your closest family and friends. But what actually is IoT? In simple words, IoT is a network of connected devices over the Internet, thus you can either control or monitor the devices over the Internet. In much better definition, IoT is a system, consists of network of connected devices over the Internet via middleware enabling bidirectional communication between human-to-machine or machine-to-machine in exchanging on-demand information resulting in better decision making.
There are 4 key components in IoT:
-
Things: The devices, consists of microcontroller (including power supply, GPIO, etc such as ESP32), sensors (such as Temperature Sensor), actuators (LED & Buzzer) and Internet connectivity. Hibiscus Sense is an example of prototype IoT devices. UnarvuTemp is an example of end-product IoT devices. -
Middleware: The cloud/server, which handle the inbound/outbound of data transmission and communication over the Internet, including data ingestion, data storage, data management, data analytics, etc. These are available IoT platform such as Favoriot, Blynk, Thingspeak, Ubidots, Thingsboard, ParticleIO and more. -
App: The software interface, visualising or the story teller of the data from the IoT devices in form of human readable format such as alert, notification and dashboard and analytics interfaces. We can find the app in from of mobile app, desktop app or web app. -
Internet. The Internet technology, such as Wi-Fi, Ethernet, Cellular (GSM/GPRS, 3G, 4G, 5G) and Satellite.
Any project without one of the components, it is not an IoT project. Therefore, in any IoT project, first thing to do is to choose the right IoT platform for our IoT project.
In this exercise, we choose Blynk as our IoT platform.
Blynk is one of the most easiest IoT platform ever exist on the planet. Their solution, has most complete IoT components, which are:
- Things: They provide Blynk Arduino libraries - to enable the communication between the cloud and devices.
- Middleware: They provide Blynk Server - responsible for all the communications between the smartphone and the things.
- App: They provide Blynk app - we can create stunning dashboard or interfaces, using its various widgets.
- Internet: not provided by them, we can choose which technology we want to use on the Things, such as
WiFi (ESP32),Cellular (SIM900 GSM)orEthernet (ENC28J60).
Prior to start program the Hibiscus Sense to connect to Blynk on your smartphone. There are 2 steps we need to complete, follow the instructions below:
In this exercise, we want to monitor:
- Proximity
- Altitude
- Barometric pressure
- Humidity
- Temperature
- Accelerometer, x-axis
- Accelerometer, y-axis
- Accelerometer, z-axis
- Gyrometer, x-axis
- Gyrometer, y-axis
- Gyrometer, z-axis
Therefore in the sketch below, we program the ESP32 to acquire all the from APDS9960, BME280 and MPU6050. Then update the data to the Blynk app using Blynk.virtualWrite() function.
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Adafruit_APDS9960.h>
#include <Adafruit_BME280.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_NeoPixel.h>
Adafruit_APDS9960 apds;
Adafruit_BME280 bme;
Adafruit_MPU6050 mpu;
Adafruit_NeoPixel rgb(1, 16);
char auth[] = "YourAuthToken";
char ssid[] = "YourWiFiSSID";
char pass[] = "YourWiFiPassword";
sensors_event_t a, g, temp;
int R = 0, G = 0, B = 0;
long previousMillis = 0;
BLYNK_WRITE(V11){
R = param[0].asInt();
G = param[1].asInt();
B = param[2].asInt();
}
void setup(){
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
if (!apds.begin()){
Serial.println("Failed to find Hibiscus Sense APDS9960 chip");
}
apds.enableProximity(true);
if (!bme.begin()){
Serial.println("Failed to find Hibiscus Sense BME280 chip");
}
if (!mpu.begin()){
Serial.println("Failed to find Hibiscus Sense MPU6050 chip");
}
rgb.begin();
rgb.show();
}
void loop(){
if(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, pass);
while(WiFi.status() != WL_CONNECTED);
}
Blynk.run();
rgb.setPixelColor(0, R, G, B);
rgb.show();
if(millis() - previousMillis > 500){
previousMillis = millis();
Blynk.virtualWrite(V0, apds.readProximity());
Blynk.virtualWrite(V1, bme.readAltitude(1013.25));
Blynk.virtualWrite(V2, bme.readPressure()/1000.00);
Blynk.virtualWrite(V3, bme.readHumidity());
Blynk.virtualWrite(V4, bme.readTemperature());
mpu.getEvent(&a, &g, &temp);
Blynk.virtualWrite(V5, a.acceleration.x);
Blynk.virtualWrite(V6, a.acceleration.y);
Blynk.virtualWrite(V7, a.acceleration.z);
Blynk.virtualWrite(V8, g.gyro.x);
Blynk.virtualWrite(V9, g.gyro.y);
Blynk.virtualWrite(V10, g.gyro.z);
}
}Now, we can upload the complete sketch to ESP32, once done uploading observe the output on the Blynk App, while we can control the RGB LED and LED.
If you want to monitor and control Hibiscus Sense Blynk demo app, you can download the Blynk App and scan the QR code below:



