Nano Pullup problem

I have been experimenting with INPUT_PULLUP on the Nano. Everything was going well and PinMode(2,INPUT_PULLUP); worked on a little sketch I modified to show how a floating pin would stay high if I designated it as INPUT_PULLUP.
But when I tried to incorporate it into a temperature sensor sketch it wouldn't work.
If I physically hook up a pullup resistor to pin 2 & 5v Vcc, it works and I get valid readings.

I have tried other pins, but no soap. I suspect it is the way the sensor is being interrogated. I am using the Onewire & DallasTemperature libraries. I can leave the resistor on the breadboard and it works, but it is messy and I would like to be able to use the pullup feature, which is new to me.
attached is my sketch. Any suggestions ? It has been a long time since I posted, and I hope I am including the code correctly.

/*
  Arduino DS18B20

  Created: 04/20/2016
  By Gus
  Modified N/A
  By Gus

  https://arduinomylifeup.com/arduino-ds18b20-temperature-sensor
*/
#include <OneWire.h>
#include <DallasTemperature.h>

int temp_sensor = 2;       // Pin DS18B20 Sensor is connected to Digital Pin 2
float temperature = 0;			//Variable to store the temperature in

OneWire oneWirePin(temp_sensor);
DallasTemperature sensors(&oneWirePin);

void setup(void){
  Serial.begin(9600);
  pinMode(2,INPUT);   //  Doesn't work if I physically remove the resistor and use pinMode(2,INPUT_PULLUP);
  sensors.begin();
}

void loop(){
 // Serial.print("Requesting Temperatures from sensors: ");
  sensors.requestTemperatures(); 
 // Serial.println("DONE");
  
  temperature = sensors.getTempFByIndex(0);
  int rndTemp = round(temperature);
   
  Serial.print("Temperature is ");
  //Serial.print(temperature);
  Serial.print(rndTemp);
  Serial.print("\xC2\xB0");    // This prints the Degree symbol
  Serial.println("f");
 
  delay(1000);
}

The device needs a stronger pull up is all.

What value resistor did you find worked?

Check the datasheet for the microprocessor on the board you use, you will find the equivalent ohms of its internal pull-up, it is considered weak. And only spec is a range.

Some ppl, like me, are old fashioned and always use real resistors for this.

Mostly always, unless I'm just experimenting and lazy. But if something isn't working then, I go to the minor trouble of believing my own superstitions. :expressionless:

a7

Yep …..It needs a 4k7 pull up resistor on the data line

OneWire sets the pin to "INPUT" during initialization so an external pullup is required. Even though I have not tried this, you may be able to use the internal pullup like this:

#define ONEWIRE_PIN 2

OneWire oneWire;
DallasTemperature sensors;

void setup()
{
  oneWire.begin(ONEWIRE_PIN);
  pinMode(ONEWIRE_PIN, INPUT_PULLUP);
  sensors.setOneWire(&oneWire);
  sensors.begin();
}

Hello pratto
Take a view to gain the hardware knowledge.
Many thanks to LarryD


Have a nice day and enjoy coding in C++.
Дайте миру шанс!

The usual temperature sensor used with onewire, the DS18B20, needs that external resistor. The sensor is powered through the pullup resistor.

I don't understand this. I don't see how in internal pullup is used in the schematic.

4.7k
when you say stronger, do you mean a higher value ?

thanks. I coded it in. it compiled and ran, but I am getting the same constant erroneous temperature reading of -197.

I looked at the Nano datasheet (or maybe it is a specsheet) but I could not find anything about pullups anywhere.
but it didn't look like this.
I'll keep looking.

If you get -196.6F (rounded to -197), that would indicate an error with the communication as per DallasTemperature source. The external pullup seems inavoidable.

Is there a way I can check the value of the IPU resistor ? Ohm's between pins, etc. I can't find anything in writing about what the actual value is.

Look at the spec sheet for the device.

It recommends 4k7 pullup.

Yes, smaller value resistors mean stronger pullup.

4k7, 10K might work, dunno. The weak internal pullup has been shown to be inadequate by… you!

Stop resisting taking all the advices here. <- see what I did there?

a7

you misunderstand. i'm not resisting. i'm appreciative. but i am such a dunce that i have to ask dumb questions to see if there is an approach others see but i don't.

Yeah, that's an error code (see post #11). The library "thinks" your sensor is disconnected. Its thinking correctly because INPUT_PULLUP is only 30K-50K which is really really weak (high resistance) compared to the required stronger 4.7K (lower resistance) external resistor that's required.

Therefore, adding INPUT_PULLUP Resistance is Futile!

From the library:

#define DEVICE_DISCONNECTED_F -196.6

There isn't, anymore than there is an "approach" to taking a bath without getting wet.

But good on you for going to ground on the matter to add to your knowledge and experience.

Next time you have a flakey or non-functioning input line, you might remember to see if the pull up provision is correct for you circumstances.

a7

thanks for your help. it looks like i'm in the hardwired resistor business.

thank you for helping me.

Yeah the full data sheet will say. Note in the diagram @paulpaulson shared #5 above in the tiny print

  Internal Pull Up 20-50K

As for using real resistors being "messy" there's all kindsa messiness all over every aspect of this undertaking or hobby or profession. Lotsa times it can be discretely hidden… but it be there.

a7

If I connect my Amp meter between Nano pin 2 (set to INPUT_PULLUP) and GND, with Vcc of 4.7V, I get a current of 130 microAmps, so R = 4.7V / 0.00013A = approximately 36000 Ohms, way too high for DS18B20 pullup, use the recommended 4.7k.