DS18B20 sensor not working on new Arduino Nano Every

Hi! I just received some of the new Arduino Nano Every’s for a university project in which i need to regulate temperature using a heater and some DS18B20 sensors. I already made one regulator using the “old” Arduino Nano and there it worked just fine but when i made a second one using the new Nano Every it wouldn’t read out the temperature, it just says -127.00 over and over. I’m using the exact same code as i’m using on the “old” Nano and i update the Dallas as well as the OneWire library but i just can’t get it to work. Does any of you may have an idea what the problem could be? The code i’m using is attached below, thanks in advance!

Kind regards,

Kota

Temp_read_sketch_test.ino (1.65 KB)

Read the how to use this forum-please read sticky to see how to post code so that everyone can see it and not have to download your code.

#include <DallasTemperature.h>
#include <OneWire.h>

//Sensor pins
int temp_sensorI = A0;// Pin Sensor is connected to
int temp_sensorII = A1;
int temp_sensorIII = A2;

//Variables for storing purpose
float temperatureI = 0;
float temperatureII = 0;
float temperatureIII = 0;
//Limits
int lowerLimitI = 42;      //Lower limit for cambium T
int upperLimitI = 45;      //Upper limit for cambium T
int upperLimitII = 67;     //Upper limit for bark T
int upperLimitIII = 90;    //Upper limit for module T
//Onewire
OneWire oneWirePinI(temp_sensorI);
OneWire oneWirePinII(temp_sensorII);
OneWire oneWirePinIII(temp_sensorIII);
//Dallas
DallasTemperature sensorsI(&oneWirePinI);
DallasTemperature sensorsII(&oneWirePinII);
DallasTemperature sensorsIII(&oneWirePinIII);


void setup()
{
   Serial.begin(9600);

   //Setup the pins to act as outputs/inputs


   //starting sensors
   sensorsI.begin();
   sensorsII.begin();
   sensorsIII.begin();

   //setting the resolution for the sensors
   sensorsI.setResolution(12);
   sensorsII.setResolution(9);
   sensorsIII.setResolution(9);


}

void loop()
{
   //requesting temperature from sensors
   sensorsI.requestTemperatures();
   sensorsII.requestTemperatures();
   sensorsIII.requestTemperatures();

   //Adressing temperature to variable
   temperatureI = sensorsI.getTempCByIndex(0);
   temperatureII = sensorsII.getTempCByIndex(0);
   temperatureIII = sensorsIII.getTempCByIndex(0);

   //printing temperatures
   Serial.print("Temperature is ");
   Serial.print(temperatureI);
   Serial.print("\t");
   Serial.print(temperatureII);
   Serial.print("\t");
   Serial.print(temperatureIII);


   delay(500);
}

The new chip is still 8 bits? It might have confused the library's specific optimization for other processor chips.

Choose a simpler example. One sensor. If you can, use an example from the library instead of your own version.

Then you are going to have to dig a little deeper into the library to find out where it goes wrong for this new chip.

Oke, so i changed my code to the one featured on the Arduino project hub for using a DS18B20 sensor located here. Then my code looked like this:

/********************************************************************/
// First we include the libraries
#include <OneWire.h> 
#include <DallasTemperature.h>
/********************************************************************/
// Data wire is plugged into pin 2 on the Arduino 
#define ONE_WIRE_BUS A0 
/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices  
// (not just Maxim/Dallas temperature ICs) 
OneWire oneWire(ONE_WIRE_BUS); 
/********************************************************************/
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
/********************************************************************/ 
void setup(void) 
{ 
 // start serial port 
 Serial.begin(9600); 
 Serial.println("Dallas Temperature IC Control Library Demo"); 
 // Start up the library 
 sensors.begin(); 
} 
void loop(void) 
{ 
 // call sensors.requestTemperatures() to issue a global temperature 
 // request to all devices on the bus 
/********************************************************************/
 Serial.print(" Requesting temperatures..."); 
 sensors.requestTemperatures(); // Send the command to get temperature readings 
 Serial.println("DONE"); 
/********************************************************************/
 Serial.print("Temperature is: "); 
 Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?  
   // You can have more than one DS18B20 on the same bus.  
   // 0 refers to the first IC on the wire 
   delay(1000); 
}

(Credits to Konstantin Dimitrov for making this guide)

But this didn’t make a difference so i started looking in the OneWire library and there i found something suggesting that it had to do with me using an analog pin instead of a digital one. So i changed the code that it would extract data from a digital pin and reconnected the sensor to the digital pin and… it worked! I’m not quite sure why it won’t work on an analog pin but for now i’m oke with it. Thanks for all the help, i really appreciate it!

PS The new chip is indeed still 8 bit.

You need to upgrade to the latest version 2.3.5 of OneWire which just came out. I had the same problem with the Nano Every and this solved it straight away.

I am in the exact same situation, although I first created the circuit using an Arduino UNO Rev3.

I upgraded to the the latest version as you said (2.3.5) and it still does not work...
I think I might be confused with the pinout, I find it a bit confusing.

So the code states this:

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS A0

So I see 2 different information:

  • pin 2
  • A0

Could someone clarify which physical pin is being used here?

To be honest I'm very new in the Arduino world...

georgeslegros:
So the code states this:

// Data wire is plugged into pin 2 on the Arduino

#define ONE_WIRE_BUS A0




So I see 2 different information:

- pin 2
- A0


Could someone clarify which physical pin is being used here?

This comment:

// Data wire is plugged into pin 2 on the Arduino

has absolutely no effect on the code. It’s unfortunately quite common to find code where the program was changed (e.g., switching from pin 2 to pin A0), but the comment was not updated.

The correct pin is definitely A0.

All right, thanks for the clarification.

Now, it still does not work… What can I give you that will allow one to see where I’m being stupid?

Here is the code I’m using now (after lots of simplifications like removing the interrupt I was using before):

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS A0 
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

void setup() {
 Serial.begin(9600);
  // Start up the library 
 sensors.begin(); 
}

void loop() {  
  Serial.print("Requesting temperatures..."); 
  sensors.requestTemperatures();
  Serial.println("DONE"); 

  Serial.print("Temperature is: "); 
  Serial.println(sensors.getTempCByIndex(0)); 
  Serial.println("");
  delay(1000);
}

I’m using OneWire 2.3.5 as you can see in the attachments as well as a photo of the actual hardware.

If someone finds where I made a mistake, that’d be awesome…

How to post images so that we don't have to download them.

Same issue and nobody every resolved the problem in any topic across internet.

I use waterproof DS18B20 Buy Waterproof probe with temperature sensor Botland - Robotic Shop

My board is Arduino Nano Sense BLE (one of most problematic board I every used), almost nothing works normally on this board and must be modded. For now I find this board perfect for flashing with LEDs and highlight my ceiling. Forgive me my frustration.

I have connected the temp sensor to 3.3v, GDN and signal pin (tried two, 2 and A0). I have cut the wire on temp sensor to be 50 cm. A resistor of 2.2k attached between 3.3V and signal pin.

All I get is -127 as result. Somebody please can tell me how to make the sensors work on this board? I tried to run it on standard UNO board - works. There is something wrong with nano boards, it is common issue if you will search internet for such topics.

Anybody please? I am in a bit of rush, must finish my project within 4 days and I spent last 3 on fighting with the temp sensors. Insane.