Project tutorial
ds18b20 Address Recorder

ds18b20 Address Recorder © GPL3+

I needed to set a large number of ds18b20 sensors up and I had to record the address and position of each sensor.

  • 422 views
  • 1 comment
  • 5 respects

Components and supplies

11113 01
SparkFun Arduino Pro Mini 328 - 5V/16MHz
×1
4634197
Memory Socket, SD Card
×1
i2c 20x4 LCD module
×1
Copper strip board
×1
Wires generic
×1

Necessary tools and machines

09507 01
Soldering iron (generic)
4966285
Solder Wire, Lead Free
Knife, file or multi tool
for cutting slits in the strip board.

About this project

I had to set up a number of ds18b20 sensors in a specific order so I needed to record their address and number them so I could position them correctly.

I made a small device to make this job easier for me.

you select the sensor number you want the sensor address to be recorded against. insert a ds18b20 sensor in the female header sockets and press the next button.

The device then displays the address of the sensor its reading and the number you chose for it. it then records all this information onto an SD card so you can simply copy the results into a spread sheet or whatever you want.

Then after correctly placing the sensor where you need it simply press the next button again to start the process for the next sensor.

I soldered the components to a strip board and soldered wires where necessary and cut the strips to avoid shorts where necessary.

The arduino is powered from the Vcc and Gnd pins via a modified usb cable.

Below is what the file on the SD card looks like its called DATALOG.TXT

The addresses are the same as I could not be bothered to change the sensor when making this quick file example.

Below is a video of it in operation to if needed.

I thought this might be helpful for other people so shared it quickly sorry if it inst in detail enough for people.

Code

condition-test-ds18b20.inoArduino
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include <SD.h>
#include <SPI.h>

#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 14

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address


float tempC;
 int n = 1;
int numberOfDevices; 
int i=0;

int change = 0;      int counter = 0;   
int len = 30;
    const int buttonPin = 7;     
    const int buttonPin1 = 9;     
    const int buttonPin2 = 8;     

    int buttonState = HIGH;  
    int buttonState1 = HIGH;  
    int buttonState2 = HIGH; 
    
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices 
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. 
DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address



void setup(void)
{

     lcd.begin(20,4);   // initialize the lcd for 16 chars 2 lines, turn on backlight
     lcd.noCursor();
  
 sensors.begin();  // Start up the library

  
 numberOfDevices = sensors.getDeviceCount();   // Grab a count of devices on the wire

  
 

}

void printTemperature(DeviceAddress deviceAddress) // function to print the temperature for a device
{
  if ( i > (numberOfDevices - 1)) {i = 0;}

  tempC = sensors.getTempC(deviceAddress);
  lcd.setCursor(0,2);
  lcd.print("Reading: ");
  lcd.setCursor(8,2);


  lcd.print(" ");
  lcd.setCursor(10,2);
  
  lcd.print(tempC);


  delay(50);
}

void loop(void)
{ 
  lcd.clear();        
  delay(1000);
  sensors.begin();  // Start up the library

  
  numberOfDevices = sensors.getDeviceCount();   // Grab a count of devices on the wire
      pinMode(buttonPin, INPUT);
     digitalWrite(7, HIGH); 
     buttonState = digitalRead(7);

     lcd.print("Sensor");
     lcd.setCursor(7,0);
     lcd.print(n);




     pinMode(buttonPin2, INPUT);
     digitalWrite(8, HIGH); 
     buttonState2 = digitalRead(8);

    
     pinMode(buttonPin1, INPUT);
     digitalWrite(7, HIGH);
     digitalWrite(9, HIGH); 
     buttonState = digitalRead(7);
     lcd.clear();
      while (buttonState == 1){
        lcd.print("Sensor: ");
        lcd.print(n);
        lcd.setCursor(0,3);
        lcd.print("Next");
        delay(100);
        lcd.setCursor(0,0);
        buttonState1 = digitalRead(9);
        buttonState2 = digitalRead(8);
        buttonState = digitalRead(7);

        if (buttonState1 == 0){
          n =  n+ 1;
          digitalWrite(9, HIGH); 
          delay(100);}
        

        if (buttonState2 == 0){
          n = n - 1;
          digitalWrite(9, HIGH); 
          delay(100);}
         }

     lcd.clear();        
     delay(500);
  

 lcd.clear();
 pinMode(buttonPin2, INPUT);
 pinMode(buttonPin1, INPUT);
 digitalWrite(5, HIGH); 
 digitalWrite(6, HIGH); 


  numberOfDevices = sensors.getDeviceCount();   // Grab a count of devices on the wire

  
  lcd.print("Scanning Sensors");  // locate devices on the bus
  
  delay (200);lcd.print("."); delay (200);lcd.print(".");delay (200);lcd.print(".");
  delay (200);lcd.print(".");delay (200);
  lcd.setCursor(0,1);

  lcd.print(numberOfDevices, DEC);
  lcd.print(" Sensor"); 
  lcd.setCursor(7,0);
  lcd.print(n);
  delay(1000);
  lcd.clear();
        sensors.requestTemperatures(); // Send the command to get temperatures
  
  for(i=0;i<numberOfDevices; i++) {  // Loop through each device, print out temperature data
     if(sensors.getAddress(tempDeviceAddress, i))
  {
    // Output the device ID
    // It responds almost immediately. Let's print out the data
    printTemperature(tempDeviceAddress); // Use a simple function to print out the data
  } 
  
  }
  // Loop through each device, print out address
  for(int i=0;i<numberOfDevices; i++)
  {
    // Search the wire for address
    if(sensors.getAddress(tempDeviceAddress, i))
  {
      String dataString = "";
      dataString += String("Sensor: ");
      dataString += String(n, DEC);
      dataString += String(" addr: ");

    SD.begin(10);
    File dataFile = SD.open("datalog.txt", FILE_WRITE);    //write adresses to sd card 
       if (dataFile) {
        dataFile.print(dataString);
        dataFile.close();
       }
 
  lcd.setCursor(0,0);
    lcd.print("Sensor: ");
    lcd.print(n, DEC);
    lcd.print(" addr: ");
    lcd.setCursor(0,1);
    printAddress(tempDeviceAddress);


    delay(2000);

  }
  }

     pinMode(buttonPin1, INPUT);
     digitalWrite(7, HIGH); 
     buttonState = digitalRead(7);
      while (buttonState == 1){

  sensors.requestTemperatures(); // Send the command to get temperatures
  
  for(i=0;i<numberOfDevices; i++) {  // Loop through each device, print out temperature data
     if(sensors.getAddress(tempDeviceAddress, i))
	{
		// Output the device ID
		// It responds almost immediately. Let's print out the data
		printTemperature(tempDeviceAddress); // Use a simple function to print out the data
	} 
	
  }
        lcd.setCursor(0,3);
        lcd.print("Next");
        lcd.setCursor(0,2);
        buttonState = digitalRead(7);

    delay (100);  }
 
   

               


}


// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (  i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    
       String dataString = "";

      dataString += String(deviceAddress[i], HEX);

    SD.begin(10);
    File dataFile = SD.open("datalog.txt", FILE_WRITE);
       if (dataFile) {
        dataFile.print(dataString);
        dataFile.close();
       }
  
    lcd.print(deviceAddress[i], HEX);
  }
      File dataFile = SD.open("datalog.txt", FILE_WRITE);
       if (dataFile) {
        dataFile.print("   Reading");
        dataFile.print(" :");
        dataFile.print(tempC);
        dataFile.print(" \n");        dataFile.print(" \n");
        dataFile.close();}
}

Custom parts and enclosures

tester_7y7uzBjh02.fzz
tester_7y7uzBjh02.fzz

Schematics

screenshot_20191130_141014_Upp1IlwbjQ.png
Screenshot 20191130 141014 upp1ilwbjq

Comments

Similar projects you might like

Fan Controlled By DS18B20 Temperature Sensor With 20x4 LCD

Project in progress by makeeuropeanu

  • 12,891 views
  • 2 comments
  • 18 respects

DIY SMD Rework Station

Project tutorial by Alexander and Maker B R

  • 12,421 views
  • 114 comments
  • 50 respects

How To Use DS18B20 Water Proof Temperature Sensor

Project showcase by Team IoTBoys

  • 83,741 views
  • 13 comments
  • 24 respects

WALTER - The Arduino Photovore Insect

Project tutorial by Martedi

  • 32,641 views
  • 17 comments
  • 127 respects

Simple Arduino Battery Capacity Tester

Project showcase by sim-flynn-13

  • 20,965 views
  • 1 comment
  • 33 respects
Add projectSign up / Login