Smart Home Automation Forum
[Arduino source code for KC868-A4]-18 one GPIO with multiple DS18B20 sensor - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KC868-A4 (https://www.kincony.com/forum/forumdisplay.php?fid=21)
+--- Thread: [Arduino source code for KC868-A4]-18 one GPIO with multiple DS18B20 sensor (/showthread.php?tid=2290)



[Arduino source code for KC868-A4]-18 one GPIO with multiple DS18B20 sensor - admin - 09-14-2022

these 10pcs of DS18B20 temperature sensors work with one ESP32 GPIO. program will print 10 sensor's value at the same time.
   
   
   
Code:
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 13
#define TEMPERATURE_PRECISION 9

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

// arrays to hold device addresses
DeviceAddress sensor1,sensor2,sensor3,sensor4,sensor5,sensor6,sensor7,sensor8,sensor9,sensor10;


void setup(void)
{
  // start serial port
  Serial.begin(115200);

  // Start up the library
  sensors.begin();

  // locate devices on the bus
  Serial.print("Locating devices...");
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  //
  // method 1: by index
  if (!sensors.getAddress(sensor1, 0)) Serial.println("Unable to find address for Device 0");
  if (!sensors.getAddress(sensor2, 1)) Serial.println("Unable to find address for Device 1");
  if (!sensors.getAddress(sensor3, 2)) Serial.println("Unable to find address for Device 1");
  if (!sensors.getAddress(sensor4, 3)) Serial.println("Unable to find address for Device 1");
  if (!sensors.getAddress(sensor5, 4)) Serial.println("Unable to find address for Device 1");
  if (!sensors.getAddress(sensor6, 5)) Serial.println("Unable to find address for Device 1");
  if (!sensors.getAddress(sensor7, 6)) Serial.println("Unable to find address for Device 1");
  if (!sensors.getAddress(sensor8, 7)) Serial.println("Unable to find address for Device 1");
  if (!sensors.getAddress(sensor9, 8)) Serial.println("Unable to find address for Device 1");
  if (!sensors.getAddress(sensor10, 9)) Serial.println("Unable to find address for Device 1");


  // set the resolution to 9 bit per device
  sensors.setResolution(sensor1, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor2, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor3, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor4, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor5, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor6, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor7, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor8, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor9, TEMPERATURE_PRECISION);
  sensors.setResolution(sensor10, TEMPERATURE_PRECISION);
}

void loop(void)
{
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
// sensors.requestTemperatures();
  float tempC1 = sensors.getTempC(sensor1);
  float tempC2 = sensors.getTempC(sensor2);
  float tempC3 = sensors.getTempC(sensor3);
  float tempC4 = sensors.getTempC(sensor4);
  float tempC5 = sensors.getTempC(sensor5);
  float tempC6 = sensors.getTempC(sensor6);
  float tempC7 = sensors.getTempC(sensor7);
  float tempC8 = sensors.getTempC(sensor8);
  float tempC9 = sensors.getTempC(sensor9);
  float tempC10 = sensors.getTempC(sensor10);   
  Serial.println(tempC1);
  Serial.println(tempC2);
  Serial.println(tempC3);
  Serial.println(tempC4);
  Serial.println(tempC5);
  Serial.println(tempC6);
  Serial.println(tempC7);
  Serial.println(tempC8);
  Serial.println(tempC9);
  Serial.println(tempC10);
  Serial.println("*************");
 
}



RE: [Arduino source code for KC868-A4]-18 one GPIO with multiple DS18B20 sensor - flatulentflamingo - 01-06-2023

Is there a builtin 4.7k Ohm resistor already between the data and vcc line on the board?

What a pity this board does not have ethernet...


RE: [Arduino source code for KC868-A4]-18 one GPIO with multiple DS18B20 sensor - admin - 01-07-2023

Yes, the "S" pin printed on PCB have 4.7K Ohm resistor already between the data and vcc line on the board.
developing new "A4S" version now, will add the ethernet.