프로젝트

아두이노와 온도센서(18B20) 활용한 물온도 센싱

페이지 정보

작성자 대디 작성일16-07-27 09:06 조회5,420회 댓글0건

본문

TMP36, 적외선 온도센서, 써미스터 등 많은 온도센서가 있는데, 제가 소개하려는 센서는 18B20이라는 온도센서입니다. 

 

많은 공간에서 혹은 여러 지점의 온도를 측정할 경우, I2C 방식의 센서를 사용할 수도 있지만, 18B20이라는 온도센서는 1-wire라는 프로토콜을 사용하여 디지털핀 1개만으로도 다수의 온도 센싱이 가능하다는 장점이 있습니다. 

 

소개할 데모는 가장 기초적으로 18B20 온도센서를 사용하여 아기의 목욕물 온도를 만들어보는 프로젝트입니다. 

 

필요한 준비물

1. 18B20온도센서: http://storefarm.naver.com/mechatool/products/451480856

2. 아두이노 우노 호환보드: http://storefarm.naver.com/mechatool/products/451487565

3. 400핀 브레드보드: http://storefarm.naver.com/mechatool/products/451021228

4. USB 케이블: http://storefarm.naver.com/mechatool/products/451486334

5. 4.7K 저항: http://storefarm.naver.com/mechatool/products/451481323

6. 9V 배터리: http://storefarm.naver.com/mechatool/products/451484978

7. 9V 배터리 스냅잭: http://storefarm.naver.com/mechatool/products/451484027

8. 40핀 점퍼와이어: http://storefarm.naver.com/mechatool/products/445775618

 

 

 

영상을 보시면, 왼쪽의 뜨거운 물과 오른쪽의 차가운 물에 반응하여 RGB LED를 제어하는 것을 볼 수 있습니다. 녹색은 35~38도로 아기의 적정 목욕 온도인데, 두 물을 섞어서 나중에 녹색으로 만들게 됩니다. 

방수처리가 되어 있기 때문에 물에 넣어도 되는 온도센서와 모듈형태로 아두이노에 끼워서 사용할 수도 있는 RGB LED 모듈, 그리고 아두이노가 만든 간단한 프로젝트입니다. 5분이면 충분히 만들 수 있습니다~!

 

제작하기

1. 아두이노 우노와 온도센서 연결

- 온도센서의 빨간선: 아두이노의 5V

- 온도센서의 검정선: 아두이노의 GND

- 온도센서의 노랑선: 아두이노의 디지털2번핀

- 4.7K 저항은 디지털2번핀과 아두이노 5V를 연결

 

2. RGB LED는 다음과 같이 우노에 연결

f1da6361d49e8b085a8b5631707a1189_1469577
RGB LED의 'R'핀은 우노의 11번, 'G'핀은 우노의 12번, 'B'핀은 우노의 13번, 그리고 GND를 맞춰서 끼웁니다. 

 

3. 프로그래밍

라이브러리는 자료실에서 다운로드 받을 수 있습니다.

 #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)

{

  pinMode(11,OUTPUT);

  pinMode(12,OUTPUT);

  pinMode(13,OUTPUT);

  // start serial port

  Serial.begin(9600);

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

  // Start up the library

  sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement

}

 

 

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: ");

  float temperature = 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

  if(temperature >= 38)

  {

    digitalWrite(11,HIGH);

    digitalWrite(12,LOW);

    digitalWrite(13,LOW);

  }

  else if(temperature < 38 && temperature > 35)

  {

    digitalWrite(11,LOW);

    digitalWrite(12,HIGH);

    digitalWrite(13,LOW);

  }

  else

  {

    digitalWrite(11,LOW);

    digitalWrite(12,LOW);

    digitalWrite(13,HIGH);

  }

  

}

댓글목록

등록된 댓글이 없습니다.


모바일 버전으로 보기