-
DHT11
ESP8266 WIFI
Спойлер/************************************************************* This example shows how value can be pushed from Arduino to the Blynk App. WARNING : For this example you'll need Adafruit DHT sensor libraries: https://github.com/adafruit/Adafruit_Sensor https://github.com/adafruit/DHT-sensor-library App dashboard setup: Value Display widget attached to V5 Value Display widget attached to V6 *************************************************************/ /* Fill-in information from Blynk Device Info here */ #define BLYNK_TEMPLATE_ID "TMPxxxxxx" #define BLYNK_TEMPLATE_NAME "Device" #define BLYNK_AUTH_TOKEN "YourAuthToken" /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> #include <DHT.h> // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "YourNetworkName"; char pass[] = "YourPassword"; #define DHTPIN 2 // What digital pin we're connected to // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321 //#define DHTTYPE DHT21 // DHT 21, AM2301 DHT dht(DHTPIN, DHTTYPE); BlynkTimer timer; // This function sends Arduino's up time every second to Virtual Pin (5). // In the app, Widget's reading frequency should be set to PUSH. This means // that you define how often to send data to Blynk App. void sendSensor() { float h = dht.readHumidity(); float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V5, h); Blynk.virtualWrite(V6, t); } void setup() { // Debug console Serial.begin(115200); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); // You can also specify server: //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80); //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(91,204,228,77), 8480); dht.begin(); // Setup a function to be called every second timer.setInterval(1000L, sendSensor); } void loop() { Blynk.run(); timer.run(); }
ESP32 WIFI
Спойлер/************************************************************* This example shows how value can be pushed from Arduino to the Blynk App. WARNING : For this example you'll need Adafruit DHT sensor libraries: https://github.com/adafruit/Adafruit_Sensor https://github.com/adafruit/DHT-sensor-library App dashboard setup: Value Display widget attached to V5 Value Display widget attached to V6 *************************************************************/ /* Fill-in information from Blynk Device Info here */ #define BLYNK_TEMPLATE_ID "TMPxxxxxx" #define BLYNK_TEMPLATE_NAME "Device" #define BLYNK_AUTH_TOKEN "YourAuthToken" /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial #include <WiFi.h> #include <WiFiClient.h> #include <BlynkSimpleEsp32.h> #include <DHT.h> // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "YourNetworkName"; char pass[] = "YourPassword"; #define DHTPIN 2 // What digital pin we're connected to // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321 //#define DHTTYPE DHT21 // DHT 21, AM2301 DHT dht(DHTPIN, DHTTYPE); BlynkTimer timer; // This function sends Arduino's up time every second to Virtual Pin (5). // In the app, Widget's reading frequency should be set to PUSH. This means // that you define how often to send data to Blynk App. void sendSensor() { float h = dht.readHumidity(); float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V5, h); Blynk.virtualWrite(V6, t); } void setup() { // Debug console Serial.begin(115200); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); // You can also specify server: //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80); //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(91,204,228,77), 8480); dht.begin(); // Setup a function to be called every second timer.setInterval(1000L, sendSensor); } void loop() { Blynk.run(); timer.run(); }
ARDUINO UNO|MEGA (Arduino Ethernet shield (W5100))
Спойлер/************************************************************* This example shows how to use Arduino Ethernet shield (W5100) to connect your project to Blynk. NOTE: Pins 10, 11, 12 and 13 are reserved for Ethernet module. DON'T use them in your sketch directly! WARNING: If you have an SD card, you may need to disable it by setting pin 4 to HIGH. Read more here: https://www.arduino.cc/en/Main/ArduinoEthernetShield This example shows how value can be pushed from Arduino to the Blynk App. WARNING : For this example you'll need Adafruit DHT sensor libraries: https://github.com/adafruit/Adafruit_Sensor https://github.com/adafruit/DHT-sensor-library App dashboard setup: Value Display widget attached to V5 Value Display widget attached to V6 *************************************************************/ /* Fill-in information from Blynk Device Info here */ #define BLYNK_TEMPLATE_ID "TMPxxxxxx" #define BLYNK_TEMPLATE_NAME "Device" #define BLYNK_AUTH_TOKEN "YourAuthToken" /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial #include <SPI.h> #include <Ethernet.h> #include <BlynkSimpleEthernet.h> #include <DHT.h> #define W5100_CS 10 #define SDCARD_CS 4 #define DHTPIN 2 // What digital pin we're connected to // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321 //#define DHTTYPE DHT21 // DHT 21, AM2301 DHT dht(DHTPIN, DHTTYPE); BlynkTimer timer; // This function sends Arduino's up time every second to Virtual Pin (5). // In the app, Widget's reading frequency should be set to PUSH. This means // that you define how often to send data to Blynk App. void sendSensor() { float h = dht.readHumidity(); float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V5, h); Blynk.virtualWrite(V6, t); } void setup() { // Debug console Serial.begin(115200); pinMode(SDCARD_CS, OUTPUT); digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card Blynk.begin(BLYNK_AUTH_TOKEN); // You can also specify server: //Blynk.begin(BLYNK_AUTH_TOKEN, "blynk.cloud", 80); //Blynk.begin(BLYNK_AUTH_TOKEN, IPAddress(192,168,1,100), 8080); Blynk.begin(BLYNK_AUTH_TOKEN, IPAddress(91,204,228,77), 8480); dht.begin(); // Setup a function to be called every second timer.setInterval(1000L, sendSensor); } void loop() { Blynk.run(); timer.run(); }
FORMAT STRING
ESP8266 WIFI
Спойлер/************************************************************* You can construct and display any strings on a Value Display. App dashboard setup: Value Display widget attached to V5 *************************************************************/ /* Fill-in information from Blynk Device Info here */ #define BLYNK_TEMPLATE_ID "TMPxxxxxx" #define BLYNK_TEMPLATE_NAME "Device" #define BLYNK_AUTH_TOKEN "YourAuthToken" /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "YourNetworkName"; char pass[] = "YourPassword"; BlynkTimer timer; // This function sends Arduino's up time every second to Virtual Pin (5). // In the app, Widget's reading frequency should be set to PUSH. This means // that you define how often to send data to Blynk App. void sendTemperature() { // Generate random temperature value 10.0 to 30.0 (for example) float t = float(random(100, 300)) / 10; // Format: 1 decimal place, add ℃ String str = String(t, 1) + "℃"; // Send it to the server Blynk.virtualWrite(V5, str); } void setup() { // Debug console Serial.begin(115200); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); // You can also specify server: //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80); //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(91,204,228,77), 8480); // Setup a function to be called every second timer.setInterval(1000L, sendTemperature); } void loop() { Blynk.run(); timer.run(); }
ESP32 WIFI
Спойлер/************************************************************* You can construct and display any strings on a Value Display. App dashboard setup: Value Display widget attached to V5 *************************************************************/ /* Fill-in information from Blynk Device Info here */ #define BLYNK_TEMPLATE_ID "TMPxxxxxx" #define BLYNK_TEMPLATE_NAME "Device" #define BLYNK_AUTH_TOKEN "YourAuthToken" /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial #include <WiFi.h> #include <WiFiClient.h> #include <BlynkSimpleEsp32.h> // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "YourNetworkName"; char pass[] = "YourPassword"; BlynkTimer timer; // This function sends Arduino's up time every second to Virtual Pin (5). // In the app, Widget's reading frequency should be set to PUSH. This means // that you define how often to send data to Blynk App. void sendTemperature() { // Generate random temperature value 10.0 to 30.0 (for example) float t = float(random(100, 300)) / 10; // Format: 1 decimal place, add ℃ String str = String(t, 1) + "℃"; // Send it to the server Blynk.virtualWrite(V5, str); } void setup() { // Debug console Serial.begin(115200); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); // You can also specify server: //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80); //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(91,204,228,77), 8480); // Setup a function to be called every second timer.setInterval(1000L, sendTemperature); } void loop() { Blynk.run(); timer.run(); }
ARDUINO UNO|MEGA (Arduino Ethernet shield (W5100))
Спойлер/************************************************************* This example shows how to use Arduino Ethernet shield (W5100) to connect your project to Blynk. NOTE: Pins 10, 11, 12 and 13 are reserved for Ethernet module. DON'T use them in your sketch directly! WARNING: If you have an SD card, you may need to disable it by setting pin 4 to HIGH. Read more here: https://www.arduino.cc/en/Main/ArduinoEthernetShield You can construct and display any strings on a Value Display. App dashboard setup: Value Display widget attached to V5 *************************************************************/ /* Fill-in information from Blynk Device Info here */ #define BLYNK_TEMPLATE_ID "TMPxxxxxx" #define BLYNK_TEMPLATE_NAME "Device" #define BLYNK_AUTH_TOKEN "YourAuthToken" /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial #include <SPI.h> #include <Ethernet.h> #include <BlynkSimpleEthernet.h> #define W5100_CS 10 #define SDCARD_CS 4 BlynkTimer timer; // This function sends Arduino's up time every second to Virtual Pin (5). // In the app, Widget's reading frequency should be set to PUSH. This means // that you define how often to send data to Blynk App. void sendTemperature() { // Generate random temperature value 10.0 to 30.0 (for example) float t = float(random(100, 300)) / 10; // Format: 1 decimal place, add ℃ String str = String(t, 1) + "℃"; // Send it to the server Blynk.virtualWrite(V5, str); } void setup() { // Debug console Serial.begin(115200); pinMode(SDCARD_CS, OUTPUT); digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card Blynk.begin(BLYNK_AUTH_TOKEN); // You can also specify server: //Blynk.begin(BLYNK_AUTH_TOKEN, "blynk.cloud", 80); //Blynk.begin(BLYNK_AUTH_TOKEN, IPAddress(192,168,1,100), 8080); Blynk.begin(BLYNK_AUTH_TOKEN, IPAddress(91,204,228,77), 8480); // Setup a function to be called every second timer.setInterval(1000L, sendTemperature); } void loop() { Blynk.run(); timer.run(); }
SERVER AS DATA STORAGE SINGLE VALUE
ESP8266 WIFI
Спойлер/************************************************************* This example shows you how you can use server as storage for your data like EEPROM Project setup in the Blynk app (not necessary): Value display on V0 in PUSH mode. *************************************************************/ /* Fill-in information from Blynk Device Info here */ #define BLYNK_TEMPLATE_ID "TMPxxxxxx" #define BLYNK_TEMPLATE_NAME "Device" #define BLYNK_AUTH_TOKEN "YourAuthToken" /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "YourNetworkName"; char pass[] = "YourPassword"; BlynkTimer timer; int uptimeCounter; // This function will run every time Blynk connection is established BLYNK_CONNECTED() { //get data stored in virtual pin V0 from server Blynk.syncVirtual(V0); } // restoring counter from server BLYNK_WRITE(V0) { //restoring int value uptimeCounter = param.asInt(); } void increment() { uptimeCounter++; //storing int in V0 pin on server Blynk.virtualWrite(V0, uptimeCounter); } void setup() { // Debug console Serial.begin(115200); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); // You can also specify server: //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80); //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(91,204,228,77), 8480); timer.setInterval(1000L, increment); } void loop() { Blynk.run(); timer.run(); }
ESP32 WIFI
Спойлер/************************************************************* This example shows you how you can use server as storage for your data like EEPROM Project setup in the Blynk app (not necessary): Value display on V0 in PUSH mode. *************************************************************/ /* Fill-in information from Blynk Device Info here */ #define BLYNK_TEMPLATE_ID "TMPxxxxxx" #define BLYNK_TEMPLATE_NAME "Device" #define BLYNK_AUTH_TOKEN "YourAuthToken" /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial #include <WiFi.h> #include <WiFiClient.h> #include <BlynkSimpleEsp32.h> // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "YourNetworkName"; char pass[] = "YourPassword"; BlynkTimer timer; int uptimeCounter; // This function will run every time Blynk connection is established BLYNK_CONNECTED() { //get data stored in virtual pin V0 from server Blynk.syncVirtual(V0); } // restoring counter from server BLYNK_WRITE(V0) { //restoring int value uptimeCounter = param.asInt(); } void increment() { uptimeCounter++; //storing int in V0 pin on server Blynk.virtualWrite(V0, uptimeCounter); } void setup() { // Debug console Serial.begin(115200); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); // You can also specify server: //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80); //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(91,204,228,77), 8480); timer.setInterval(1000L, increment); } void loop() { Blynk.run(); timer.run(); }
ARDUINO UNO|MEGA (Arduino Ethernet shield (W5100))
Спойлер/************************************************************* This example shows how to use Arduino Ethernet shield (W5100) to connect your project to Blynk. NOTE: Pins 10, 11, 12 and 13 are reserved for Ethernet module. DON'T use them in your sketch directly! WARNING: If you have an SD card, you may need to disable it by setting pin 4 to HIGH. Read more here: https://www.arduino.cc/en/Main/ArduinoEthernetShield This example shows you how you can use server as storage for your data like EEPROM Project setup in the Blynk app (not necessary): Value display on V0 in PUSH mode. *************************************************************/ /* Fill-in information from Blynk Device Info here */ #define BLYNK_TEMPLATE_ID "TMPxxxxxx" #define BLYNK_TEMPLATE_NAME "Device" #define BLYNK_AUTH_TOKEN "YourAuthToken" /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial #include <SPI.h> #include <Ethernet.h> #include <BlynkSimpleEthernet.h> #define W5100_CS 10 #define SDCARD_CS 4 BlynkTimer timer; int uptimeCounter; // This function will run every time Blynk connection is established BLYNK_CONNECTED() { //get data stored in virtual pin V0 from server Blynk.syncVirtual(V0); } // restoring counter from server BLYNK_WRITE(V0) { //restoring int value uptimeCounter = param.asInt(); } void increment() { uptimeCounter++; //storing int in V0 pin on server Blynk.virtualWrite(V0, uptimeCounter); } void setup() { // Debug console Serial.begin(115200); pinMode(SDCARD_CS, OUTPUT); digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card Blynk.begin(BLYNK_AUTH_TOKEN); // You can also specify server: //Blynk.begin(BLYNK_AUTH_TOKEN, "blynk.cloud", 80); //Blynk.begin(BLYNK_AUTH_TOKEN, IPAddress(192,168,1,100), 8080); Blynk.begin(BLYNK_AUTH_TOKEN, IPAddress(91,204,228,77), 8480); timer.setInterval(1000L, increment); } void loop() { Blynk.run(); timer.run(); }