воскресенье, 2 октября 2011 г.

Цифровой датчик температуры DS18B20+

В общем попробовал различные схемы подключения аналогового датчика температуры LM35 - не удалось его заставить правильно работать совместно с фоторезистором.
Вынужден был купить цифровой датчик температуры, который не имеет такой как LM35 проблемы.
Датчик брал в промэлектронике, впрочем как всю элементную базу DS18B20+
Обошелся в 55,13 рублей.
Подключил его...
В схему необходимо включить сопротивление на 4,7кОм.
Код:

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 4 on the Arduino
#define ONE_WIRE_BUS4

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

// 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 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
delay (10000);
}

Для нормальной работы необходимо подключить библиотеки:
#include <OneWire.h>
#include <DallasTemperature.h>

В понимание работы помогли материалы:
http://pobot.ru/topic/show/122/
http://bildr.org/2011/07/ds18b20-arduino/ 

Комментариев нет:

Отправить комментарий