1°³ÀÇ ÇÉÀ¸·Î ¿Âµµ°ªÀ» ÀоîµéÀÏ ¼ö ÀÖ´Â ¼¾¼ÀÔ´Ï´Ù.
ºÎ°¡ÀûÀ¸·Î Ç®¾÷ÀúÇ×ÀÌ ÇÊ¿äÇÕ´Ï´Ù.
µðÁöÅÐ Çü½ÄÀ¸·Î ½ÅÈ£¸¦ Ãâ·ÂÇϱ⿡ ¶óÁ¸®ÆÄÀ̵¼µµ ½±°Ô »ç¿ëÀÌ °¡´ÉÇÕ´Ï´Ù.
´ëü »óÇ° : ¹ÝµµÃ¼ ¿Âµµ¼¾¼(TMP36 - Temperature Sensor) ¶Ç´Â KEV-6601 À» °Ë»öÇØÁÖ¼¼¿ä.
µ¥ÀÌÅͽÃÆ®: http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf
¼Ò½ºÄÚµå
#include
int SensorPin = 13; //Our sensor is connected to digital pin 10
//Initiate OneWire communication OneWire ds(SensorPin);
void setup(void) { //Initiate serial communication with our computer Serial.begin(9600); digitalWrite(8,HIGH); }
void loop(void) {
float T = readT(); // call function to read from sensor Serial.print("Temperature is: "); // print out results to us Serial.print(T); Serial.println(" deg.C"); // print out results to us delay(750);
}
float readT(){ //returns the temperature from our sensor
byte data[12]; byte addr[8];
if ( !ds.search(addr)) { ds.reset_search(); return -300; // if there is no sensor on OneWire Bus, return -300 value }
ds.reset(); ds.select(addr); ds.write(0x44,1); // tell sensor to start converting ds.reset(); ds.select(addr); ds.write(0xBE); // tell sensor to start sending data
for (int i = 0; i < 9; i++) { // we receive data in this loop data[i] = ds.read(); }
ds.reset_search();
byte MSB = data[1]; byte LSB = data[0];
float raw = ((MSB << 8) | LSB); // move MSB left for 8 spaces, join that with LSB float realTempC = raw / 16; // move decimal point left for 4 spaces, result our temperature return realTempC;
}
|