Last active
January 22, 2023 09:57
-
-
Save structure7/588d77a92c1a4364f6fa6cb4ba15fed4 to your computer and use it in GitHub Desktop.
Using Blynk for more than one DS18B20 sensor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SimpleTimer.h> | |
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space | |
#include <BlynkSimpleEsp8266.h> | |
#include <OneWire.h> | |
#include <DallasTemperature.h> | |
#define ONE_WIRE_BUS 2 // This is the ESP8266 pin | |
OneWire oneWire(ONE_WIRE_BUS); | |
DallasTemperature sensors(&oneWire); | |
DeviceAddress tempSensor1 = { 0x28, 0xFF, 0x35, 0x11, 0x01, 0x16, 0x04, 0x25 }; // Temperature probe #1 | |
DeviceAddress tempSensor2 = { 0x28, 0xC6, 0x89, 0x1E, 0x00, 0x00, 0x80, 0xAA }; // Temperature probe #2 | |
char auth[] = "fromBlynkApp"; | |
char ssid[] = "ssid"; | |
char pass[] = "pw"; | |
SimpleTimer timer; | |
int temperature1, temperature2; // Variables for storing temperatures | |
void setup() | |
{ | |
Serial.begin(9600); | |
Blynk.begin(auth, ssid, pass); | |
while (Blynk.connect() == false) { | |
// Wait until connected | |
} | |
sensors.begin(); | |
sensors.setResolution(tempSensor1, 10); // More on resolutions: http://www.homautomation.org/2015/11/17/ds18b20-how-to-change-resolution-9101112-bits/ | |
sensors.setResolution(tempSensor2, 10); | |
// These timers are used to keep the loop() nice and leak... keeps Blynk from getting flooded. | |
timer.setInterval(5000L, sendSensor1); | |
timer.setInterval(30000L, sendSensor2); | |
} | |
void loop() | |
{ | |
Blynk.run(); | |
timer.run(); | |
} | |
void sendSensor1() { | |
sensors.requestTemperatures(); // Polls the sensors | |
temperature1 = sensors.getTempF(tempSensor1); // Stores temp in F. Change getTempF to getTempC for celcius. | |
Blynk.virtualWrite(1, temperature1); // Send temp to Blynk virtual pin 1 | |
} | |
void sendSensor2() { | |
sensors.requestTemperatures(); | |
temperature2 = sensors.getTempF(tempSensor2); | |
Blynk.virtualWrite(2, temperature2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Обязательно сначала проверьте адрес каждого датчика. https://gist.github.com/structure7/6c3231af63a69e6aa6c353db8ffab257
Может быть их более новая версия.