Problem with LED display to read temperature from DS18B20

Hello,
I am a beginner with Arduino and I wanted to make a simple temperature display.

The sensor I use is a DS18B20.

In my prototype, the sensors worked good (I can check it with the serial monitor) but it doesn't work together with my 4 digit 7 segment LED display. With the software I only get the number -127 on my display (and also in the serial monitor).

HERE IS THE SOFTWARE:

#include <SevenSeg.h>
#include <Wire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 // Data DS18B20 on pin 2

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int temp;

SevenSeg disp(15,3,4,5,6,7,8);
const int numOfDigits=4;
int digitPins[numOfDigits]={9,10,11,12};
int temp;

void setup() {
sensors.begin();

disp.setDigitPins(numOfDigits,digitPins);

//Control brightness (values 0-100);
disp.setDutyCycle(80);

disp.setTimer(2);
disp.startTimer();

Serial.begin(9600);
}

void loop() {
sensors.requestTemperatures();
temp = sensors.getTempCByIndex(0);
delay(1000);
Serial.println(sensors.getTempCByIndex(0));
disp.write(temp,0);

}
ISR(TIMER2_COMPA_vect){
disp.interruptAction();
}

When I switch off the timer in the setup:
//disp.setTimer(2);
//disp.startTimer();

and the part in the loop:
//ISR(TIMER2_COMPA_vect){
//disp.interruptAction();
//}

I can see the temperature with the LED display, but it flickers (I see the temperature, but the number is flashing very quick, most of the time the display is off).

I cant find what I do wrong? Is there some one to give advice?
See also attachment (ino file) .

Thanks for help,
Greeting, Guido

TestTemperatuurSevenSegmentLED.ino (845 Bytes)

The decimal value of -127 that you are getting corresponds to 0xFF which means that all bits are high.

When you get that value from a DS18B20 it generally indicates that the sensor is disconnected, so I would start by checking the connections to your sensor.

Don

Thanks Don, for your quick response at my question! :wink:
I check the sensor and when I switch off the lines

in setup:
//disp.setTimer(2);
//disp.startTimer();

and the part in the loop:
//ISR(TIMER2_COMPA_vect){
//disp.interruptAction();
//}

And I look to the serial monitor the temperature seems to be correct... So I think the sensor is right connected?
My sensor is connected with Vdd and GND to 0 volt
With DO to pin 2 and DO is with 4.7K Ohm to +5 volt

Is it possible I need to connect the sensor on an other way? (one leg to 5 volt, the other leg to 0 volt and DO to pin 2)?

Greeting, Guido

The temp on the screen only has to be something not -127 to suggest that you don't have a problem, yet -127 is the code for non-connection. Maybe you have a power problem that is only manifest when you want to activate the LEDs i.e. something very marginal.

You haven't shown us how your LEDs are interfaced. Do you have resistors in series with the segment pins (15,3,4,5,6,7,8)? If not, that could certainly lead to the type of problem that Nick is suggesting.

If you do have the resistors there still could be a power problem. Try disconnecting the digit connections (9,10,11,12) and see if the serial display now gives the correct values.

Don

Hi Don and Nick,

Thanks again for your help and suggestions!

The Arduino is connected to the 4 digit display with 470 ohm resistors to the 7 segments. It's a display with common anode.

I checked the power consumption (from USB in my computer), that was about 20mA and the voltage is 5,07 volt. Also when I use another 5,0 volt power supply I still have the same problem. Does the Arduino have a voltage regulator inside? Than the voltage could be a problem if I give exactly 5 volt?

I also find out that when I only disable the code "disp.setTimer(2)" in the setup, that the temperature in the serial monitor and on the display is right (So the DS18B20 seems to work fine I think?), but the number on the LED display flash (always very short on).

When I enable the code "disp.setTimer(2) in the setup, I have the number -127, it is on constantly. So I think the LED display is working fine too?

Guido

I can't see what the problem is, but the -127 cannot be a coincidence, it can only come from the DS18B20, and therefore that is where the problem lies. It indicates improper connection, which includes inadequate power.

I can only suggest that you remove all reference to the LED display and ensure that everything works perfectly on serial monitor, then add the LED to see if you have grief. In the event, you know the cause, the LED. I can only guess it is still power, short pulses you cannot see on the meter, perhaps.

In reply #4 I suggested that he leave the LED code in place but disable the LEDs themselves. It is not clear whether he tried that or not.

Don

That sounds like a better way.

I downloaded your ino and radically stripped everything dealing with the 7-segment display. Then I tested this ino with one of my own DS18B20 probes (data wire connected to pin 12 on a Nano; 470 kOhm pullup resistor (between data and 5V). Worked fine with good serial monitor values.

Conclusion: your problem has to do with controlling the 7-segment display. Concentrate on having a perfectly working display (e.g. use a constant in lieu of a variable temp measurement) and then merge both inos. Unfortunately I have no experience only with 16x2 and 20x4 LCD and with TFT displays.

Here is the correctly working ino I stripped out of your TestTemperatuurSevenSegmentLED.ino:

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

#define ONE_WIRE_BUS 12 // Data DS18B20 on pin 12

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

int temp;

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

void loop() {
sensors.requestTemperatures();
temp = sensors.getTempCByIndex(0);
delay(1000);
Serial.println(sensors.getTempCByIndex(0));

}

Excuse me! The pullup is a 4.7 kOhm !

Dear photoncatcher, Don and Nick,

I tried with data wire to arduino, with pull up resistor and Vcc to 5v and GND to 0V and with this connection it works fine! :slight_smile: I'm very happy!

When I disconnect the DS18B20, I get the value on the display "-127". So, the only problem was the connection of the DS18B20!

I also change the value disp.write(temp,0); into disp.write(temp,1); and now I get also tenths of a degree. I didn't know that this was possible...

To all... thanks again for your help for my project!

Greetings, Guido

gvlaere:
I get also tenths of a degree. I didn't know that this was possible...

Glad to hear you have it going. The DS18B20 will return values to two decimal places by default.

How fitting for this to show up on on Groundhog Day.

Reply #11, Feb 2

When I disconnect the DS18B20, I get the value on the display "-127". So, the only problem was the connection of the DS18B20!

Reply #1, Jan 26

When you get that value from a DS18B20 it generally indicates that the sensor is disconnected, so I would start by checking the connections to your sensor.

Don