Ds18b20

Hello!
i’m using ds18b20 in my project and sensor is showing negitive value.
A picture of reading is attached.
kindly someone help me .it wil be a great help in final year project.

Capture.PNG

No code. No connection diagram. How are we to help?

Read the forum guidelines for advice on how to ask a question and how to properly post code.

A photo showing the wiring is often helpful.

opsss sorry .here is the code im using.

#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SoftwareSerial.h>
#include <stdlib.h>
//SoftwareSerial nodemcu(2,3);
//SoftwareSerial blue(7,8); // bluetooth module connected here

// Variables
const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED13 = 13; // The on-board Arduino LED, close to PIN 13.
int Threshold = 550; // Determine which Signal to “count as a beat” and which to ignore.
// Use the “Gettting Started Project” to fine-tune Threshold Value beyond default setting.
// Otherwise leave the default “550” value.

PulseSensorPlayground pulseSensor; // Creates an instance of the PulseSensorPlayground object called “pulseSensor”

// for ds18b20 temperature sensor

#define ONE_WIRE_BUS 4
#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Celcius=0;
float Fahrenheit=0;

String cdata; // complete data, consisting of sensors values
int sdata1 = 0; // temperature centigrade
int sdata2 = 0; // temperature Farenheit

char buff[10];
String tempc;
String tempf;
void setup() {

Serial.begin(9600); // For Serial Monitor
// nodemcu.begin(9600);
//blue.begin(9600);
// set up the LCD’s number of columns and rows:
// Configure the PulseSensor object, by assigning our variables to it.
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED13); //auto-magically blink Arduino’s LED with heartbeat.
pulseSensor.setThreshold(Threshold);

// Double-check the “pulseSensor” object was created and “began” seeing a signal.
if (pulseSensor.begin()) {
Serial.println(“Reading Pulse and temprature !”); //This prints one time at Arduino power-up, or on Arduino reset.

}
}

void loop() {

int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an “int”.
// “myBPM” hold this BPM value now.

if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if “a beat happened”.
Serial.print(“MY Beat:”);
Serial.println(myBPM);
}
delay(20);
sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.toFahrenheit(Celcius);

//TEMPERATURE SENSOR DS18B20

tempc = dtostrf(Celcius, 3, 2, buff);
tempf = dtostrf(Fahrenheit, 3, 2, buff);
Serial.print("Temprature in Celcius: ");
Serial.println(tempc);
Serial.print("Temprature in Fahrenheit: ");
Serial.println(tempf);

cdata = cdata + tempc+","+tempf +","+myBPM; // comma will be used a delimeter
Serial.print("Complete temprature in celcius and fahrenheit with Pulses: ");
Serial.println(cdata);
// nodemcu.println(cdata);
// blue.println(“Patient Monitoring.”);
// blue.println(cdata);
delay(200);
cdata = “”;
Serial.println(“ReadingAgain”);
delay(20);

}

and also .
i’m using ds18b20 temprature sensor with arduino’s pin d4
and a pulse sensor SEN-11574 with arduino’s A0 pin also using 4.7k ohm pull up resistor.

and also thanks for reply Sir .

Does the sensor work by itself with any of the examples that come with the DallasTemprature library?

Using more than one software serial library can cause problems. I would use a Mega (or other board with multiple hardware serial ports) instead of an Uno.

Read the how to use this forum-please read stickies to see how to post code.

So what are suggesting me to do ? and i just attached the diagram .
Actually i’m using arduino nano in this project.
Can you suggest me what i will change in code ?

Thanks !

The 5V output from the 7805 should go to the 5V pin, not Vin.

Is it a 330 Ohm pull-up for the 18B20 or the (recommended) 4.7K?

Does the 18B20, in a circuit by itself, work with the library examples?

What I said about software serial applys to the Nano.

-127 means no connection. Time to check your wiring.

Chances are that the code is kosher but you would be better off using a simple library example to prove the sensor stuff. Learn to walk before you run.

I see that you have commented the print stuff, so I guess it's not an immediate problem, but using software serial twice is a really bad idea and you should think seriously about whether you really need it for Bluetooth. You probably don't, you just think you do.

Each individual DS18B20 sensor has a unique address.
Please connect your DS18B20 to your Nano (5V, GND, pin D11, 4.8kOhm pull up resistor between 5V and pin 11, then run te following DS18B20 address finder

introduce the DS18B20 address into the proper line of your sketch and voila, should work.

// DS18B20_address finder
// This sketch looks for 1-wire devices and
// prints their addresses (serial number) to
// the UART, in a format that is useful in Arduino sketches
// Tutorial: 
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

#include <OneWire.h>

OneWire  ds(11);  // Connect your 1-wire device to pin 8

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

void discoverOneWireDevices(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  
  Serial.print("Looking for 1-Wire devices...\n\r");
  while(ds.search(addr)) {
    Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
    for( i = 0; i < 8; i++) {
      Serial.print("0x");
      if (addr[i] < 16) {
        Serial.print('0');
      }
      Serial.print(addr[i], HEX);
      if (i < 7) {
        Serial.print(", ");
      }
    }
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        Serial.print("CRC is not valid!\n");
        return;
    }
  }
  Serial.print("\n\r\n\rThat's it.\r\n");
  ds.reset_search();
  return;
}

void loop(void) {
  // nothing to see here
}

@ photoncatcher
While I subscribe to your approach to using DS18B20, there is nothing in it to fix OPs problem, indeed it is misleading, and there is probably no voila! to be seen..

  1. OP is using one sensor only
  2. OP is already using the "by index" code, thereby being excused from knowing the address, which is probably quite reasonable in this case.

OP's problem may simply be slack-arsed wiring, particularly the 330ohm pullup. God only knows who told him to do that.

@Nick: My standard procedure when a sensor does not work is to rip the thing out of its (experimental) setup and test it 'bare', that is with a Nano with as little wiring as possible. With DS18B20s it is often pin assignment in the sketch. A 4.7K pull up resistor is obligatory.

330 ohms is FAR too low for a pull-up resistor for the OneWire bus. Use 10k or 4k7 if on a long cable.

If on a long lead add a 100nF ceramic decoupling capacitor from 5V to GND at the sensor itself to improve reliability.

But first test the sensor works locally with a 4k7 or 10k pullup.

Dear rslankhawar

I downloaded your December 31, 2019 sketch and connected one of my own DS18B20s in the correct way:
Arduino Nano
5V on Nano to 5V pin of sensor
pin D4 on Nano to data pin of sensor
GND to GND
4k7 resistor between 5V and pin 4.

and the DS18B20 part of your sketch worked perfectly. Nice actual temperature readings on Serial Monitor

conclusion: sketch works in DS18B20 mode. Double check your sensor and the wiring

...... forgot to mention that I had commented out in your sketch anything that has to do with pulse measurements..... :confused:

sorry! - but your sketch worked for the DS18B20!