How can i connect two DS18B20 Temperature sensor with cayenne

How can I connect two DS18B20 Temperature sensor with cayenne?
Please help me with this complete code and circuit connections.
Cayenne DS18B20 Example

This sketch shows how to send DS18B20 Sensor data to the Cayenne Dashboard.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.


  1. Install the OneWire library (OneWire Arduino Library, connecting 1-wire devices (DS18S20, etc) to Teensy) from the Arduino Library Manager.
  2. Install the DallasTemperature library (Miles Burton - Innovative engineering for pretty much anything) from the Arduino Library Manager.
  3. Attach a DS18B20 to a digital pin on your Arduino.
    [Ground] – [DS18B20] – [4.7k resistor] – [5V]
    Digital Pin
  4. Set the SENSOR_PIN value below to the pin number you used when connecting the sensor.
  5. Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of a DS18B20 Sensor widget you have added) in the Dashboard.
  6. Set the Cayenne authentication info to match the authentication info from the Dashboard.
  7. Compile and upload this sketch.
  8. Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the DS18B20 Sensor widget you have added) with data.
    To make a temporary widget permanent click the plus sign on the widget.

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “62c74310-b143-11e6-9ce1-1904e26cb7a0”;
char password = “f095c9b1072071dec0dfad2011e254e8b36f283c”;
char clientID = “3e70aa50-2658-11ea-8221-599f77add412”;

#define SENSOR_PIN 2 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define VIRTUAL_CHANNEL undefined

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

void setup()
Cayenne.begin(username, password, clientID);

void loop()

// This function is called at intervals to send sensor data to Cayenne.
// Send the command to get temperatures.
// This command writes the temperature in Celsius to the Virtual Channel.
Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors.getTempCByIndex(0));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL, sensors.getTempFByIndex(0));

you need to use code to read multiple ds18b20 and then send value of each ds18b20 to cayenne using:

Cayenne.celsiusWrite(VIRTUAL_CHANNEL, temp1);
Cayenne.celsiusWrite(VIRTUAL_CHANNEL, temp2);
Cayenne.celsiusWrite(VIRTUAL_CHANNEL, temp2);

where temp1, temp2 and temp3 are variables that store ds18b20 sensor data.

Thanks for your help shramik.

My sensor (DS18B20) isn’t working. So I decided to replace the sensor. Now I’m using mcp9701 sensor. It’s working fine in offline mode. I will share offline project details here but let me share some things.
I have Arduino Uno, Ethernet shield w5100 and mcp9701 sensor. I’m using the internet on my laptop via Mobile hotspot and connected ethernet shield with my laptop. I’m connected to cayenne and the dashboard appears. My sensor is working fine in offline mode but I want to make it online with cayenne. This is the project link which works fine in offline mode. Active Sensor Thermometer - Arduino Project Hub

Please share the complete code not just some lines and instructions.

From the mcp9701 code you send the sensor data is stored in vout. So you to publish you can use:

Cayenne.celsiusWrite(VIRTUAL_CHANNEL, vout);

I didn’t understand anything.

Did you understood the mcp9701 code?

No Vout is here and no pin number is here everything appears as Connectivity: virtual Select: channel. What are channels? How can I specify/select pin numbers?

A little bit.

are you familiar with basic cayenne code to send data to cayenne Cayenne-MQTT-Arduino/EthernetShieldW5100.ino at master · myDevicesIoT/Cayenne-MQTT-Arduino · GitHub
You need to add code of mcp9701 to the above cayenne code so that the variable vout which stores the mcp9701 sensor data can be published to cayenne using:

Cayenne.celsiusWrite(VIRTUAL_CHANNEL, vout);

where VIRTUAL_CHANNEL is the MQTT channel number used for communication between cayenne and the device.
when you run this code on the device, it will auto-generate the widget for VIRTUAL_CHANNEL on the cayenne dashboard.You need to add it by clicking on +