-1

ive used one DS1820B sensor in a AVR bread board circuit and it works there, now i tried attaching it to a arduino mega board with the code below and also another library below that.

currently the data pin is connected to pin 10 on the arduino board, but i also tried pin 2 as in this picture:

https://lastminuteengineers.com/wp-content/uploads/2018/12/Wiring-Multiple-DS18B20-Temperature-Sensors-With-Arduino.png

i changed: #define ONE_WIRE_BUS 10 accordingly.

So after that i put the chip back onto the bread board and it still works. I also tried it with the 4.7k resistor on the data line as pullup....still -127.

Any ideas?

#include <SPI.h>
#include <SD.h>
/********************************************************************/
// 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 10
/********************************************************************/
// 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() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
 sensors.begin(); 
}


void loop() {

  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); 


}

second code:

#include "DS18B20Events.h"

// Pin for DS18B20
#define ONE_WIRE_BUS 10

/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices  
// (not just Maxim/Dallas temperature ICs) 
OneWire oneWire(ONE_WIRE_BUS);

// Init DallasTemperature
DallasTemperature dallasTemperature(&oneWire);

//Init thermometer with index 0 (default)
DS18B20Events thermometer(0);

// the setup function runs once when you press reset or power the board
void setup() {  
  Serial.begin(9600);
  DS18B20Events::setup(&dallasTemperature); // Link DS18B20Events to DallasTemperature object
  DS18B20Events::setInterval(5000); // Set min interval in milliseconds between 2 measurements. Default 10000 set in setup() method.

  // subscribe to temperature changed event
  thermometer.onChange = temperatureChanged;
}

// the loop function runs over and over again until power down or reset
void loop() {
  thermometer.loop(); // Mandatory to measure temperature and fire an event if needed

  Serial.print(thermometer.getTempC()); // Get last measured tempC if needed.
  Serial.print(" measured ");
  Serial.print((millis() - thermometer.getMillis()) / 1000);
  Serial.println(" seconds ago.");

  delay(1000);
}

void temperatureChanged(uint8_t index, float tempC)
{
  Serial.print(tempC);
  Serial.print(" new tempC at index ");
  Serial.println(index);
}
  • Please post a photo of your wiring (including a clear view of the stripes on your pullup resistor). – Dougie Oct 19 '19 at 13:43
  • You need a photo of your ACTUAL wiring to your Arduino, not the Fritzing diagram of what your wiring should look like. – Dougie Oct 19 '19 at 14:59
1

127 error is a connection error, check the wiring:

| improve this answer | |
0

you probably forgot pull up resistor

| improve this answer | |
-1

Im not sure what it was, but its working now with the second code. the first one is probably right too.

Maybe i was just to cool(-127C) a few hours ago...oh no. Theres probably a stackoverflow page for that too.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.