Blynk Arduino DS18B20 Thermometer Display on IOS or Android

34K5324

Intro: Blynk Arduino DS18B20 Thermometer Display on IOS or Android

Temperature being displayed on my Android device.

STEP 1: Introduction

In this Instructable I am going to attempt to show you how to put together a little project to use the Blynk app (optainable at http://www.blynk.cc/) to display the temperature remotely on a iOS or Android device.

I came across an posting on my Google+ where somebody required some help with this. It looked interesting, so I decided to have a try myself.

This is my first attempt to write an Instructable. I have found many articles published here useful. So I thought it is time to do my part.

The main parts I used are:

Arduino UNO clone

Ethernet shield

Dallas DS18B20 sensor

A 4k7 resistor is also required as a pull-up resistor for the data line.

Optional Breadboard

An iOS or Android device

STEP 2: The DS18B20 Sensor

The DS18B20 sensor connections are as follows, looking at the label:

Left leg = GND

Middle leg = Data

Right leg = 5 V

STEP 3: Let's Start

I used a mini breadboard just to connect the pull-up resistor to the 5 V and Data connection. You could just solder the resistor straight onto the legs.

STEP 4: Wiring

That is how it is all wired up.

Vcc -> 5V

GND -> Gnd

Data -> pin 7

4k7 resistor between 5 V and Data legs

STEP 5: Getting Some Code to Work

I don't believe in reinventing the wheel. Download the library from the Blynk website and install it into your Arduino libraries folder.

I used the BlynkBlink scetch from the Blynk examples and the DS18x20_temperature example from the OneWire Library. I combined the two into one sketch. I did change the pin for the DS18B20 data into the Arduino to pin 7. The reason for this is because pin 10 is used by the Ethernet shield. I also added a line to the end of the DS18x20 data processing section. Blynk.virtualWrite(V5, celsius); This sends the celsius result. You can change that to Blynk.virtualWrite(V5, fahrenheit); to send the Fahrenheit result.

STEP 6: Result

On the device side, you have to use V5 as an input and set up the range. Detailed instructions relating to the software side and iOS and Android device setup are in the sketch and on the Blynk website. Once you worked out the basics, it is easy to change it to use a different display mode on your device, like "Value Display", "Gauge", "LCD" and "Graph".

I want to thank all the people who made this possible. The people who designed and made the hardware and wrote the software that I have used for this project. Without them life would be different.

Do not hesitate to make suggestions and ask questions, if you get stuck. I'm still learning how to write a good Instructable.

STEP 7: The Code

The first file is for a single display only. The second one is a demo using different types of displays.

STEP 8: Multi Display Demo

Screenshot of several different displays using the second code file.

23 Comments

I like the approach, thanks...

but dude!

// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!

delay(10000);


really???

First of all I'm a total newbie.

How can I do this via USB connection? Thanks

Hello, need a little help,

Used the Multiple ds18b20 and when i added a gauge or value widget a strange thing happens. it scrolls threw all the six ds18b20's i have connected. basically i cannot create a widget for each temp prob because it rolls threw all the temps.

hello did you finde wath was wrong

best regards gunnar

Hi,

Sorry for the delay, but I was unable to reply up to now.

Please send me the code that you are using and give me details of your setup. Tell me how many sensors you are using and their addresses.

I am currently not able to use Blink as I am no longer using it, but I am sure we can get the problem resolved.

Regards

Maroelawerner

now i wanne connect 1 cannel relais bord

i used this one works :


#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).

OneWire ds(D2); // on pin D4 op wemos d1 (a 4.7K resistor is necessary)

char auth[] = "822b2ffc4ccc44c0af582a582f91d8a7";

void setup(void)
{
Serial.begin(9600);
Blynk.begin(auth, "telenet-xxxxx", "xxxxxxxxxxx");
}

void loop(void)
{
Blynk.run();byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;

if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}

Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(addr[i], HEX);
}

if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();

// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
Serial.println(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
Serial.println(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
Serial.println(" Chip = DS1822");
type_s = 0;
break;
default:
Serial.println("Device is not a DS18x20 family device.");
return;
}

ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end

delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.

present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

Serial.print(" Data = ");
Serial.print(present, HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print(OneWire::crc8(data, 8), HEX);
Serial.println();

// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius);
Serial.print(" Celsius, ");
Serial.print(fahrenheit);
Serial.println(" Fahrenheit");
Blynk.virtualWrite(V5, celsius);
}

Hi,

Figured it out. In the sketch, do not use OneWire ds(7);, but use OneWire ds(2);.

I used a NodeMCU v0.9 to test it. Connect sensor to D4.

This will only read and send data for a single sensor.

Also change the first Delay time from 10000 to 100. If that delay is too long, it disconnects from the network.

Regards

Maroelawerner

Hi, can you help me?

I try this, the blynk app says "d1 wemos is not in network"

It works with a led and wifi standalone, but after adding the one wire i cant connect???

#define BLYNK_PRINT Serial // Enables Serial Monitor
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>

// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control...

OneWire ds(7); // on pin 7 (a 4.7K resistor is necessary) make sure you change this from the original pin 10 to an unused pin.


char auth[] = "822b2ffc4ccc44c0af582a582f91d8a7"; // Put your Auth Token here. (see Step 3 above)

void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "xxx", "xxx"); // Here your Arduino connects to the Blynk Cloud.
}

void loop()
{
Blynk.run(); // All the Blynk Magic happens here...

// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
delay(10000);
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;

if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}

Serial.print("ROM =");
for ( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(addr[i], HEX);
}

if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();

// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
Serial.println(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
Serial.println(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
Serial.println(" Chip = DS1822");
type_s = 0;
break;
default:
Serial.println("Device is not a DS18x20 family device.");
return;
}

ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end

delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.

present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

Serial.print(" Data = ");
Serial.print(present, HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print(OneWire::crc8(data, 8), HEX);
Serial.println();

// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius);
Serial.print(" Celsius, ");
Serial.print(fahrenheit);
Serial.println(" Fahrenheit");
Blynk.virtualWrite(V5, celsius);

}

if you resolve this problem can you please share the code?

I'm having the exact same problem.

I will aprpriciated you help :)

Hi,

Yes, there problem. After trying your sketch I got the same problem.

A quick look at the code revealed that there is no code to connect to the WiFi network.

Need to fix that.

Regards

Maroelawerner

i find the working code !!!!! Simply put me well on the right track . Some adjustments made for the Wemos d1r2

Hi,

I’m irinakim and I’m work in the Wiznet.

Thank you for using our product.

We are collecting so much data using ourproduct.

And I will post the this project on our Web site.( http://wiznetmuseum.com)

Can I post your product on our Web site?

Hi,

Yes, you may post my project on your website.

Regards

maroelawerner

This is very cool... Any have this on a wireless module instead of the Ethernet module they can share?

This is very cool... Any have this on a wireless module instead of the Ethernet module they can share?

This is great! Is there anyway you could get it to work with a 4 channel rely?

Yes, what do you want the 4 relays to do?

This is great! Is there anyway you could get it to work with a 4 channel rely?

This is great! Is there anyway you could get it to work with a 4 channel rely?

More Comments