The goal here is to plug the DS18B20 Temperature sensor to the Arduino Pro Mini.
For my project i decided to go with an already complete module with the sensor as well as the 4,7 kOhms ... less soldering !
The wiring :
The DS18B20 Module has 3 pins just like the DS18B20 sensor alone.
DS18B20 Module > Arduino Pro Mini
For my project i decided to go with an already complete module with the sensor as well as the 4,7 kOhms ... less soldering !
The wiring :
The DS18B20 Module has 3 pins just like the DS18B20 sensor alone.
DS18B20 Module > Arduino Pro Mini
- - (Negative) > GND
- + (Positive) > VCC
- Data > Pin 3
The software :
Once the wiring is all done, the next step is to try finding out what is the address of the sensor in order to get the temperature measure later on.
You need to install the OneWire and the DallasTemperature libraries
- One wire : http://www.hacktronics.com/code/OneWire.zip
- DallasTemperature : http://www.hacktronics.com/code/DallasTemperature.zip
The idea is to upload the following code to the Arduino Pro Mini with the sensor wired :
#include <OneWire.h>code source : http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
#include <DallasTemperature.h>
OneWire ds(3); // Connect your 1-wire device to pin 3
void setup(void) {
Serial.begin(9600);
discoverOneWireDevices();
}
void discoverOneWireDevices(void) {
byte i;
byte present = 0;
byte data[12];
byte addr[8];
Serial.print("Looking for 1-Wire devices...\n\r");
while(ds.search(addr)) {
Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
for( i = 0; i < 8; i++) {
Serial.print("0x");
if (addr[i] < 16) {
Serial.print('0');
}
Serial.print(addr[i], HEX);
if (i < 7) {
Serial.print(", ");
}
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.print("CRC is not valid!\n");
return;
}
}
Serial.print("\n\r\n\rThat's it.\r\n");
ds.reset_search();
return;
}
void loop(void) {
// nothing to see here
}
Once up and running with the program in the Arduino, go to :
Tool > Serial Monitor.
The sensor address will then show up on the monitor. In my case it was :
Upload the following code to the Arduino Pro MiniTool > Serial Monitor.
The sensor address will then show up on the monitor. In my case it was :
0x28, 0xFF, 0xED, 0x0F, 0x11, 0x14, 0x00, 0xD2With this address we can move on to the next and final step, measure some temperatures finally !
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
DeviceAddress Thermometer = { 0x28, 0xFF, 0xED, 0x0F, 0x11, 0x14, 0x00, 0xD2 };
void setup(void)
{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(Thermometer, 10);
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop(void)
{
delay(2000);
Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();
Serial.print("Inside temperature is: ");
printTemperature(Thermometer);
Serial.print("\n\r");
}
Code source : http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
Once the Arduino is running the program, go to the Serial Monitor again.
The temperature should be printed on the screen
Tada ! Temperature is displayed on screen !
Next step is to try and combine the temperature sensing and to send it via TX 433 Mhz to the Raspberry Pi to sniff !
If anyone has any idea on how to do that ... i am interested !
Once the Arduino is running the program, go to the Serial Monitor again.
The temperature should be printed on the screen
Tada ! Temperature is displayed on screen !
Next step is to try and combine the temperature sensing and to send it via TX 433 Mhz to the Raspberry Pi to sniff !
If anyone has any idea on how to do that ... i am interested !
No comments:
Post a Comment