background image

 

Published: 27.08.2018  

Copyright by Joy-IT 

 

Temperature Sensor 

The following code example requires two additional libraries. These consist of the 

OneWire Library 

by 

Paul Stoffregen

, published under the MIT License, and the 

Dallas Temperature Control Library 

by

 

Miles 

Burton

, published under the LGPL License. Both libraries are included in the package and must be copied 

to the "library" folder before starting the Arduino IDE. You can find it by default under the following path 
of your Windows installation: C:\Users\[Username]\Documents\Arduino\libraries

 

You can download the code example for Arduinos 

here

 or copy the following one:

 

3.  CODE EXAMPLE ARDUINO 

// Required libraries are imported

 

#include <DallasTemperature.h> 

 

#include <OneWire.h>           

 

 

 

// The input pin to which the sensor module is connected is declared here.

 

#define KY001_Signal_PIN 4

 

 

 

// Libraries are configured

 

OneWire 

oneWire

(KY001_Signal_PIN);          

 

DallasTemperature 

sensors

(&oneWire);   

 

 

 

 

 

void

 

setup

() {

 

 

 

    

// Initialization Serial output

 

    Serial.begin(

9600

);

 

    Serial.println("KY

-

001 Temperaturmessung");

 

     

 

    

// Sensor is initialized

 

    sensors.begin();  

 

}

 

 

 

// Main program loop

 

void

 

loop

()

 

{

 

    

// Temperature measurement is started...

 

    sensors.requestTemperatures(); 

 

    

// ... and display measured temperature

 

    Serial.print("Temperatur: ");

 

    Serial.print(sensors.getTempCByIndex(

0

));

 

    Serial.write(

176

); 

// UniCode specification of a char symbol for the "° symbol".

 

    Serial.println("C");

 

         

 

    delay(

1000

);    

// 5s Pause until next measurement

 

}

 

Summary of Contents for KY-001

Page 1: ...3 Temperature Sensor KY 001...

Page 2: ...ished 27 08 2018 Copyright by Joy IT 2 Temperature Sensor 1 Overview 2 Pin Assignment 3 Code Example Arduino 4 Code Example Raspberry Pi 5 Information and take back obligations 6 Support TABLE OF CONT...

Page 3: ...ing and use Should you encounter any unexpected problems during use please do not hesitate to contact us 1 OVERVIEW Chipset DS18B20 Communication protocoll 1 Wire Accuracy of Measurement 9 12 Bit Rang...

Page 4: ...Arduinos here or copy the following one 3 CODE EXAMPLE ARDUINO Required libraries are imported include DallasTemperature h include OneWire h The input pin to which the sensor module is connected is d...

Page 5: ...minal window and enter the following command to open the file Now add the following line to the opened file at the end Save the file with the key combination CTRL O and exit it with the combination CT...

Page 6: ...lished print Warte auf Initialisierung base_dir sys bus w1 devices while True try device_folder glob glob base_dir 28 0 break except IndexError sleep 0 5 continue device_file device_folder w1_slave Fu...

Page 7: ...lines 1 find t if equals_pos 1 temp_string lines 1 equals_pos 2 temp_c float temp_string 1000 0 return temp_c main loop The measured temperature is sent to the console between the individual measureme...

Page 8: ...om us free of charge when purchasing a new device Small appliances where no external dimensions are larger than 25 cm can be delivered in normal household quantities irrespective of the purchase of a...

Page 9: ...re any questions left or if you encounter any problems please feel free to contact us by mail phone or by our ticket system on our website E Mail service joy it net Ticket System http support joy it n...

Reviews: