NodeMCU with 10x multiple DS18B20 Temperatures

Hello, i need help with my project.

Now i’m having a problems with the codes for NodeMCU with 10x multiple DS18B20 Temperatures, because enough to upload Can not see the true value.

So I want to ask for help

Thank you…

CODE

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

#define ONE_WIRE_BUS 3        // This is the ESP8266 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DeviceAddress tempSensor001 = { 0x28, 0x24, 0x67, 0xCA, 0x05, 0x00, 0x00, 0x23 };
DeviceAddress tempSensor002 = { 0x28, 0x2C, 0xCD, 0x15, 0x06, 0x00, 0x00, 0x73 };
DeviceAddress tempSensor003 = { 0x28, 0x9A, 0xFD, 0xC9, 0x05, 0x00, 0x00, 0xB5 };
DeviceAddress tempSensor004 = { 0x28, 0xAE, 0x09, 0xC5, 0x05, 0x00, 0x00, 0x2F };
DeviceAddress tempSensor005 = { 0x28, 0xBE, 0x5A, 0x16, 0x06, 0x00, 0x00, 0xC2 };
DeviceAddress tempSensor006 = { 0x28, 0xA5, 0x7D, 0xCA, 0x05, 0x00, 0x00, 0x3F };
DeviceAddress tempSensor007 = { 0x28, 0x95, 0xAF, 0xC5, 0x05, 0x00, 0x00, 0x95 };
DeviceAddress tempSensor008 = { 0x28, 0xA3, 0xAE, 0xCA, 0x05, 0x00, 0x00, 0x9D };
DeviceAddress tempSensor009 = { 0x28, 0x2B, 0x20, 0xC2, 0x05, 0x00, 0x00, 0xA3 };
DeviceAddress tempSensor010 = { 0x28, 0x8F, 0x7C, 0xCA, 0x05, 0x00, 0x00, 0x8B };

char auth[] = "66e10624ba3c4594852cd489c4fa986f";
char ssid[] = "Medicare";
char pass[] = "med250314med";

SimpleTimer timer;

int temperature001, temperature002, temperature003, temperature004, temperature005, temperature006, temperature007, temperature008, temperature009, temperature010;         // Variables for storing temperatures

void setup()
{
  Serial.begin(9600);
  Blynk.begin("66e10624ba3c4594852cd489c4fa986f", "Medicare", "med250314med");

  while (Blynk.connect() == false) {
    // Wait until connected
  }

  sensors.begin();
  sensors.setResolution(tempSensor001, 10);   // More on resolutions: http://www.homautomation.org/2015/11/17/ds18b20-how-to-change-resolution-9101112-bits/
  sensors.setResolution(tempSensor002, 10);
  sensors.setResolution(tempSensor003, 10);
  sensors.setResolution(tempSensor004, 10);
  sensors.setResolution(tempSensor005, 10);
  sensors.setResolution(tempSensor006, 10);
  sensors.setResolution(tempSensor007, 10);
  sensors.setResolution(tempSensor008, 10);
  sensors.setResolution(tempSensor009, 10);
  sensors.setResolution(tempSensor010, 10);

  // These timers are used to keep the loop() nice and leak... keeps Blynk from getting flooded.
  timer.setInterval(2000L, sendSensor001);
  timer.setInterval(2000L, sendSensor002);
  timer.setInterval(2000L, sendSensor003);
  timer.setInterval(2000L, sendSensor004);
  timer.setInterval(2000L, sendSensor005);
  timer.setInterval(2000L, sendSensor006);
  timer.setInterval(2000L, sendSensor007);
  timer.setInterval(2000L, sendSensor008);
  timer.setInterval(2000L, sendSensor009);
  timer.setInterval(2000L, sendSensor010);
}

void loop()
{
  Blynk.run();
  timer.run();
}

void sendSensor001() {
  sensors.requestTemperatures();                  // Polls the sensors
  temperature001 = sensors.getTempC(tempSensor001);   // Stores temp in F. Change getTempF to getTempC for celcius.
  Blynk.virtualWrite(V1, temperature001);            // Send temp to Blynk virtual pin 1
}

void sendSensor002() {
  sensors.requestTemperatures();
  temperature002 = sensors.getTempC(tempSensor002);
  Blynk.virtualWrite(V2, temperature002);
}

void sendSensor003() {
  sensors.requestTemperatures();
  temperature003 = sensors.getTempC(tempSensor003);
  Blynk.virtualWrite(V3, temperature003);
}

void sendSensor004() {
  sensors.requestTemperatures();
  temperature004 = sensors.getTempC(tempSensor004);
  Blynk.virtualWrite(V4, temperature004);
}

void sendSensor005() {
  sensors.requestTemperatures();
  temperature005 = sensors.getTempC(tempSensor005);
  Blynk.virtualWrite(V5, temperature005);
}

void sendSensor006() {
  sensors.requestTemperatures();
  temperature006 = sensors.getTempC(tempSensor006);
  Blynk.virtualWrite(V6, temperature006);
}

void sendSensor007() {
  sensors.requestTemperatures();
  temperature007 = sensors.getTempC(tempSensor007);
  Blynk.virtualWrite(V7, temperature007);
}

void sendSensor008() {
  sensors.requestTemperatures();
  temperature008 = sensors.getTempC(tempSensor008);
  Blynk.virtualWrite(V8, temperature008);
}

void sendSensor009() {
  sensors.requestTemperatures();
  temperature009 = sensors.getTempC(tempSensor009);
  Blynk.virtualWrite(V9, temperature009);
}

void sendSensor010() {
  sensors.requestTemperatures();
  temperature010 = sensors.getTempC(tempSensor010);
  Blynk.virtualWrite(V10, temperature010);
}

Hello and welcome to the Blynk Forum.

First a few things… I fixed your post, but you need to read the Welcome Topic and learn how to properly format any posted code.

The next thing is that we are not really here to teach programming, or act as code mechanics :wink: But at least you have shown initiative in trying something before asking :+1: :smiley:

So… while you might want to spend some time reading various documents and forum topics about timers, here is some advice. You are using your timers incorrectly…

You have 10 separate timers, all set to happen every 2 seconds… but all at the same time?? :stuck_out_tongue: These little MCUs are not multitaskers, so basically your code is trampling all over itself.

Run one timer with all 10, or preferably split into two staggered sets of 5… Then read the groups of the sensors sequentially in the function(s) called by each timer.

e.g.

// Adjust longer gap between timers if required... currently 1/2 second between group reads
timer.setInterval(2000L, sendSensorsGroup1);
timer.setInterval(2500L, sendSensorsGroup2); 

void sendSensorsGroup1() {
  sensors.requestTemperatures();  // Polls the sensors
  Blynk.virtualWrite(V1, sensors.getTempC(tempSensor001));
  Blynk.virtualWrite(V2, sensors.getTempC(tempSensor002));
  Blynk.virtualWrite(V3, sensors.getTempC(tempSensor003));
  Blynk.virtualWrite(V4, sensors.getTempC(tempSensor004));
  Blynk.virtualWrite(V5, sensors.getTempC(tempSensor005));
}

void sendSensorsGroup2() {
  sensors.requestTemperatures();  // Polls the sensors
  Blynk.virtualWrite(V6, sensors.getTempC(tempSensor006));
  Blynk.virtualWrite(V7, sensors.getTempC(tempSensor007));
  Blynk.virtualWrite(V8, sensors.getTempC(tempSensor008));
  Blynk.virtualWrite(V9, sensors.getTempC(tempSensor009));
  Blynk.virtualWrite(V10, sensors.getTempC(tempSensor010));
}
1 Like

Do I need to add this code?

Now I try to do as you submit. But it’s still the same. Will there be any way to help me? It is urgent. :disappointed_relieved:

Stand aside @Gunner, it’s about DS18B20 sensors! :wink:

The difference between String and string are a bit fussy, but try string like this:

byte tempSensor001[] = { 0x28, 0x24, 0x67, 0xCA, 0x05, 0x00, 0x00, 0x23 };

getTempC() actually returns a float :slight_smile:

Life hack:

// set global resolution to 9, 10, 11, or 12 bits
    void setResolution(uint8_t);

Do it once for all sensors: sensors.setResolution(10); :wink:

In each sendSensor***() you have a requestTemperatures();. This command tells ALL sensors to start measure. You don’t have to do this each and every time because it slows down the overall execution. Take a look at the setWaitForConversion() function in the library to speed up things. I’ve written about this many times - use the search function :slight_smile:

Try to make it work with just one or two sensors first. Less things that could go wrong :slight_smile:

Good luck!

2 Likes

Yah, I just focused on the timers… I sorta assumed that the OP had at least gotten 1 or 2 sensors to work on their own… probably bad assumption :stuck_out_tongue:

1 Like

Hello,

I hope you understand my question, because I am from Germany and my English is not the best.

I am trying to program a NodeMCU. Unfortunately I’m not successful.

Your code looks very good.

Could you please send me the finished code in the version with two sensors?

And a picture of what the wiring with 10 sensors looks like?

I dont get any further…

thank you

greetings from Bavaria