본문 바로가기

프로그래밍/아두이노03- 연습

아두이노 개발 연습 - 온도센서(ds18b20 waterproof)활용


이번엔 DEVICEMART에서 구입한 waterproof temperature sensor - ds18b20 모델이 도착하였다.


해당 모델은 기존에 쓰이던 ds18b20(트렌지스터처럼생긴)온도센서가 있는데 이것을


수축튜브로 감싸서 만든 수중용 즉, 방수 온도측정 센서라고 보면된다.














위 그림처럼 해당 센서는 수축튜브로 감싸져 있으며


끝부분만 빵판 혹은 pcb기판에 접촉하기 위한 전선이 나와있으므로


반대 끝부분은 물속이나 액체속에 넣어 온도를 측정이 가능 토록


방수역할을 해준다.




원래는 4.7k옴을 사용하여 저항을 연결해야되지만 해당 저항이 없어


기존에 가지고 있던 저항으로 구성하였다.


1K 1K 1K 470 + 235(470병렬) = 4.705


약 오차범위 +-5% 안쪽이므로 크게 문제가 되지 않는다.








온도센서가 뱀처럼 꽈리를 틀고있다.




최종 센서에 대한 콘솔값, 손으로 잡고 잇엇는데 온도가 


정상적으로 점점 올라가는것을 볼 수 있다.

(정상작동한다는 뜻)



==================================== 소스코드 =============

#include <OneWire.h>

#include <DallasTemperature.h>

 

// Data wire is plugged into pin 2 on the Arduino

#define ONE_WIRE_BUS 2

 

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

 

void setup(void)

{

  // start serial port

  Serial.begin(9600);

  Serial.println("Dallas Temperature IC Control Library Demo");


  // Start up the library

  sensors.begin();

}

 

 

void loop(void)

{

  // call sensors.requestTemperatures() to issue a global temperature

  // request to all devices on the bus

  Serial.print(" Requesting temperatures...");

  sensors.requestTemperatures(); // Send the command to get temperatures

  Serial.println("DONE");


  Serial.print("Temperature for Device 1 is: ");

  Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? 

    // You can have more than one IC on the same bus. 

    // 0 refers to the first IC on the wire

 

}


==================================== 소스코드끝 =============


<참고한 사이트>

아두이노 onewire(sensor) library 

DallasTemperature library