Search in Pinguino World !!

Thursday, June 2, 2011

Temperature Sensor

I built this very simple temperature sensor with a DS18B20. It is connected on a PIC32-PINGUINO and powered from the data line.


The DS18B20 library is very simple to use, just one line to check the temperature on the sensor:

#define ONEWIREBUS 9 // define the pin connected to the 18B20+ Dline

void setup()
{
Serial.begin(9600);
pinMode(8,OUTPUT);
digitalWrite(8,HIGH); // pin 8 is used to power the 18B20 ( +Vcc )
pinMode(10,OUTPUT);
digitalWrite(10,LOW); // pin 10 is used to power the 18B20 ( GND )
}

void loop()
{
TEMPERATURE t;

if (DS18B20.read(ONEWIREBUS, SKIPROM, RES9BIT, &t))
{
if (t.sign) Serial.printf("-");
else Serial.printf("+");
Serial.printf("%d",t.integer);
Serial.printf(".%d",t.fraction);
Serial.printf("\n\r");
}
}


Now it's time to connect the DS18B20 and the zigbee shield to have a wireless temperature sensor !!


back view


Front view

1 comment:

Temperature Sensor said...

Wow, great article, I really appreciate your thought process and having it explained properly, thank you! I really like this post.