Have set up the DS18B20 sensor connected to Arduino Uno + WiFi shield and my problem is that the Cayenne dashboard value displayed is static at 1.00 C or 33.8 F rather than the true temperature. I have some experience of the DS18B20 with RasPi and have a python-based internal/external 2-sensor system working for some time, but I’m not as familiar with Arduino. The DS18B20 is an Ltech model with two integrated resistors (1K and 10K) on the board, one for the LED and one for pull down I presume. There are 3 pins on the board: + (to 5V) - (to GND) and DG to pin 2 on Arduino (which is the pin specified in sketch (const int tmpPin = 2;) and on Cayenne widget settings.
Hi Ian,
thanks for quick response …sketch follows:
…Brendan
/*
Cayenne DS18B20 Example
This sketch shows how to send temperature data to a DS18B20 Sensor in the Cayenne Dashboard.
The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
Steps:
1. Install the OneWire library (http://www.pjrc.com/teensy/td_libs_OneWire.html) from the Arduino Library Manager.
2. Install the DallasTemperature library (http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library#Code.2FLibrary) from the Arduino Library Manager.
3. In the Cayenne Dashboard add a new DS18B20 widget.
4. Set the widget to Value Display.
5. Select Virtual Pins and a virtual pin number.
6. Set VIRTUAL_PIN to the pin number you selected.
7. Attach a DS18B20 to an digital pin on your Arduino.
Schematic:
[Ground] -- [DS18B20] -- [4.7k resistor] -- [5V]
|______________|
|
Digital Pin
8. Set the tmpPin variable to match the pin used to connect the DS18B20.
9. Set the token variable to match the Arduino token from the Dashboard.
10. Compile and upload this sketch.
11. Once the Arduino connects to the Dashboard it should automatically update the DS18B20 widget with data.
*/
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneEthernet.h>
// Virtual Pin of the DS18B20 widget.
#define VIRTUAL_PIN V1
// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
const int tmpPin = 2;
OneWire oneWire(tmpPin);
DallasTemperature sensors(&oneWire);
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "xxxxxxxxx";
void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
sensors.begin();
}
void loop()
{
Cayenne.run();
}
// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(VIRTUAL_PIN)
{
// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
Cayenne.celsiusWrite(VIRTUAL_PIN, sensors.getTempCByIndex(0));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}
Well I’m making a little progress. I was able to determine that the Arduino and DS18B20 were capable of playing nice together. I loaded up the sketch that comes with the OneWire library found here-
I ran the example script for OneWire+DS18B20 and, like you, I also get the correct temperature output via the serial monitor. So I can conclude that I have a properly functioning Uno + sensor - so it seems to be the Cayenne interfacing that is the issue. Unfortunately I’m out of my depth trouble-shooting this.
…Bren
Hi Ian,
as you can see I’ve got it working. I resorted to removing the Uno from my dashboard and re-adding it, then adding the sensor. I don’t know what the root cause of the problem was but suspect it was lack of communication between my Uno and the cloud. Thanks for your input.
…Bren
Arduino Uno clone, W5100 ethernet shield, waterproof DS18B20 with 4.7kΩ pu attached to digital pin 2.
Here’s the code-
/*
Cayenne DS18B20 Example
This sketch shows how to send temperature data to a DS18B20 Sensor in the Cayenne Dashboard.
The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
Steps:
1. Install the OneWire library (http://www.pjrc.com/teensy/td_libs_OneWire.html) from the Arduino Library Manager.
2. Install the DallasTemperature library (http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library#Code.2FLibrary) from the Arduino Library Manager.
3. In the Cayenne Dashboard add a new DS18B20 widget.
4. Set the widget to Value Display.
5. Select Virtual Pins and a virtual pin number.
6. Set VIRTUAL_PIN to the pin number you selected.
7. Attach a DS18B20 to an digital pin on your Arduino.
Schematic:
[Ground] -- [DS18B20] -- [4.7k resistor] -- [5V]
|______________|
|
Digital Pin
8. Set the tmpPin variable to match the pin used to connect the DS18B20.
9. Set the token variable to match the Arduino token from the Dashboard.
10. Compile and upload this sketch.
11. Once the Arduino connects to the Dashboard it should automatically update the DS18B20 widget with data.
*/
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneEthernet.h>
// Virtual Pin of the DS18B20 widget.
#define VIRTUAL_PIN V1
// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
const int tmpPin = 2;
OneWire oneWire(tmpPin);
DallasTemperature sensors(&oneWire);
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "5mk7xgvwuf";
void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
sensors.begin();
}
void loop()
{
Cayenne.run();
}
// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(VIRTUAL_PIN)
{
// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
Cayenne.celsiusWrite(VIRTUAL_PIN, sensors.getTempCByIndex(0));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}
@bbrohan, I don’t think this is any different than what you posted yesterday. Again, what didn’t seem to work yesterday seems to today.
I was having exactly the same problems you were yesterday. I don’t think the code I was using yesterday that didn’t work is any different than the code that is working today. I’m gonna blame the ‘cloud’ .
Brendan,
I changed the status of this thread to ‘Helped’. Please let us know if you continue to have difficulties, and we’ll move it back to an ‘open’ status.
Thank you for taking the time to contribute to the group discussion!
And a personal thanks from me for prompting me to get my favorite sensor working on the Arduino!
I’m having the same problem. I’ve tried everything. I can get a reading on the monitor with the temp. Sensor but through the app and the web page I get 33.8. Any clue? I’ve deleted and reinstalled everything. I’m at a loss but I’m also new to this as well.