Introduction: Arduino: DS18B20 Temperature Sensor Data Over Wireless

This project looks at using very inexpensive 315/433 MHz RF modules to send data from a DS18B20 temperature sensor over a wireless link. In my case I'd like to place the sensor outside the house in the back garden and be able to receive temperature data on the receiver inside the house.

The transmit RF module is very low power, only 10 mW, and so the range is quite limited. In initial experiments on breadboard I was able to obtain a range of about 25 feet line of sight with a 12 cm antenna on the receiver and a 95 cm antenna on the transmitter and using a 12V supply for the transmitter. Range can be increased by using up to a 12 Volt (maximum) supply for the transmitter and using longer antenna wires. With 95 cm antenna wires on both the Tx and Rx and 12V power on the transmitter the range extended to anywhere within my house with transmitter out in the back garden. That's impressive for RF modules that only cost $1 per pair!

These modules use ASK or Amplitude Shift Keying. See a brief tutorial on this here: ASK . In its simplest form, RF carrier on means we are sending a 1 and RF carrier off means we are sending a 0. We will use the radio head library with Arduino to format the data for transmission by ASK.

First we'll build the project on breadboard to get it working and then build a permanent version on vector board. It's really advisable that you build this on breadboard first to familiarize yourself with the project and make sure you can get it working before committing to a full build.

Supplies

In order to build this project on breadboard you will need the following:

2 - Arduino Uno boards
2 - Small breadboards
1 - pair of 315 MHz or 433 MHz Tx/Rx RF modules RF Modules
1 - DS18B20 Temperature sensor
2 - 5K potentiometer
1 - 4.7K resistor
2 - LEDs
3 - 330 ohm resistors
1 - 2 x 16 LCD 2x16 LCD
2 - Sources of 4.5 V to 5V power. Either 2 benchtop supplies (5V) or two sets of 3 x AA cells (4.5V) with battery holders.

Jumper wires and about 2m of single strand #24 wire for the antennas

Step 1: Transmitter Circuit

The transmitter schematic shows the final schematic as we would build it on vector board. For now the left half of the schematic including the ATMega328P will be provided by one of the Arduino Uno boards. We just need to connect the DS18B20, RF Tx module and associated parts to the Uno.

When we build the final project we will need the header at the top left of the schematic connected to the ATmega328P IC pins in order to program it, as well as a crystal and capacitors for the ATMega328P clocking.

Step 2: Receiver Circuit

The receiver schematic shows the final schematic as we would build it on vector board. For now the left half of the schematic including the ATMega328P will be provided by one of the Arduino Uno boards. We just need to connect the RF Rx module, LCD module and associated parts to the Uno.

When we build the final project we will need the header at the top left of the schematic connected to the ATmega328P IC pins in order to program it, as well as a crystal and capacitors for the ATMega328P clocking.

Step 3: Transmitter and Receiver Arduino Code for Breadboard Build

The transmitter and receiver Arduino code for the breadboard build are provided. The code is comprehensively commented and fairly self explanatory. Things to note are that you will need to include several libraries including the radio head library which facilitates modulation of the RF carrier using ASK.

The transmitter will send temperature in degrees C and F as well as the transmitter battery voltage. If I have this out in my garden running on a remote power supply or battery I want to know if the voltage level is ok, so I've set this up so that the transmitter battery voltage is sampled through a potentiometer and fed into analog pin A0.

We've included Serial.print statements in the transmitter code so that we can see if the temperature sensor is working by turning on the serial monitor. These will slow down the program somewhat and you can speed things up by commenting them out. If you find the program does not work when you do this, insert a slight delay, say, 100 msec in the program. This applies to the receiver code also.

The receiver code also requires the radio head and LCD libraries to operate. In this program we use the internal processor time counter millis() to keep track of the time and will use this every 60 seconds to display the received transmitter battery voltage level. We use the DisplayTime = millis() + 60000; statement to do this.

Step 4: About Using Higher Voltage for the Transmit Module and Measuring the Battery Voltage

We set the analog reference point to 1.1V by using the command analogReference(INTERNAL); So now the reference point is not the default which is usually the 5V power supply voltage which might vary but instead the internal 1.1V reference. So now with a power supply voltage of 5V, we will set the potentiometer connected to pin A0 such that the voltage on this pin is 1.1V when the supply is operating normally. If the supply drops below 5V then we will correctly measure and display the reduction.

A note of CAUTION: if you are using a power supply above 5V for the transmitter, such as 12V for example, be sure you only connect this to the RF module and not to the 5V logic rail!

Now let's suppose for a moment that you want to use a 12V battery not only to power the RF module at it's maximum level but also to power the circuit. If you are using this higher voltage to provide power for the 5V rail you will obviously need to use a 5V regulator to bring this down to 5V. Then if you just want to monitor the 5V rail voltage you can just use the circuit as is.

If you decide that you want to actually monitor the 12V battery, then we need to modify the circuit slightly so that we don't apply more than 5V to the A0 pin. And let's also suppose that you might be charging your battery with a solar charger that could go as high as say 14.7V. We might then want to anticipate a maximum voltage of 15V to use round numbers. So to do this we add a 10K resistor in series with the adjustment potentiometer to drop the 15V to 5V across the potentiometer.

Then you need to change a single line of code: change myData.BattVolts = myData.BattVolts*5.00/1023; to
myData.BattVolts = myData.BattVolts*15.00/1023; Again adjust the pot for 1.1V on pin A0 with a 15V battery test voltage or if all you have is a 12V battery, adjust the potentiometer while looking at the serial monitor until it shows 12V. I've provided the schematic with the modifications required in this section. I'll provide any updated code for the final build in the sections below.

NOTE: I'd advise you to use 12V for the transmitter power, I found the range extremely limited with only 5V powering the transmitter. As such, I will plan to build the final project with a 12V supply. Providing 0.95m antenna wires on both the receiver and transmitter substantially improved the range also.

Another note of CAUTION: If you are using a wall wart type plug in power adapter and it says 12 volts on the label, check the voltage with a DVM before connecting it to the circuit. I used an old cell phone charger and it actually had a voltage of about 14V even when loaded. To get around this I just added a couple of diodes to step down the voltage to about 12V, not very efficient but it works.

Step 5: Final Build of the Transmitter

I've built the final project on vector board and put it into a plastic box to protect it from the weather. See the video to view it's construction. For now, I used a 12V wall wart supply which plugs into an outlet on the outside of the house. In future I may look into using a 12V battery and solar charger, but that's a project for another day!

The temperature readings seem to be a couple of degrees too high with the sensor right on the vector board and sealed in the box. I suspect that the electronics are keeping the inside of the box warmer than ambient. So in the future I plan to move the sensor outside the box by running a wire to the outside. Also a project for another day.

I also found that modifications to the software improved the accuracy of the temperature readings. I've added more delay between readings and set the resolution to 12 bit in the final code provided at the end of the instructable.

To check the accuracy of the temperature readings I drilled a hole in an ice cube and placed the DS18B20 inside. The reading dropped to +0.44 degrees C which is within the claimed +/- 0.5 deg accuracy over the -10 to +85 range. I place the sensor in boiling water and it read about 96.3 deg C so slightly off there. I found that with my current build when the outside temperature is in the range of 0 to 5 degrees C the sensor has trouble returning an accurate reading, it is often a couple of degrees high. This is probably due to self heating of the sensor along with heating from the other electronics in the box. I need to investigate further. Its interesting that when the sensor is measuring around typical room temperature say 68 deg F it is usually spot on. I can only assume that this is because any heating effects are masked or made irrelevant by the higher room temperature. I also found that the sensor is very sensitive to heating by direct sunlight and cooling by air currents.

Step 6: Final Build of the Receiver

I built the receiver in a transparent box, see the video to view it's construction. This is a good way to avoid having to cut a hole for the LCD in your project box, which is very hard to do cleanly. With a transparent box all you need to do is drill 4 small holes and bolt the LCD to the inside of the box which is much easier.

Even though we used a 5V supply for the breadboard build, for the final build I'm using 3 x AAA batteries in a battery holder, or 4.5V total. This works fine. I wanted to make the receiver portable so that I could move it around anywhere in the house. And of course I've added a switch so that you can turn it on only when required to preserve the batteries. I found that it will turn on and acquire temperature data in less than 5 seconds.

Note that if you build it in an appropriate size box, such as the one in the parts list, when you plug the LCD into the circuit board and place the 3 x AAA battery holder below the circuit board it just nicely fits snuggly into the box and you don't need attach the circuit board or the battery holder to the box. If you use a female header on the circuit board and plug the LCD into it the friction is substantial and the LCD holds the circuit board in place. Then there is just enough space for the batteries below the circuit board. It all holds together very well.

Step 7: Final Build Transmitter Parts List

1 - 315 or 433 MHz transmitter module
1- DS18B20 temp sensor
1 - Atmega328P microcontroller
1 - 28 pin IC socket
3 - 0.1 uF caps
1 - 4.7K resistor
1 - 10K resistor
1 - 330 ohm resistor
1 - 16 MHz crystal
2 - 22 pf caps
1 - LM7805 voltage regulator
1 - 0.33 uF cap
1 - 5K pot
1 - LED
1 - LED bezel
1 - 3 hole female header
4 - 1/4" standoffs with #4-40 threads
8 - 1/4" #4-40 bolts
7 - male header strip pins
1 - rubber grommet (sized to your power supply cable)
1 - 12 VDC wall adapter or 12V battery
1 - project box (Hammond 1591GSBK)
1 - vector board 2.75" x 3.75"
#22 stranded wire
#22 single strand wire (for antenna)
#30 wire wrap wire
heat shrink tubing
silicon caulking
solder

Step 8: Final Build Receiver Parts List

1 - 2 x 16 LCD
1 - Transparent plastic case (Hammond 1591CTCL)
1 - Pushbutton latching switch
1 - Vector board 2" x 2.75"
1 - 315 or 433 MHz receiver module
1 - 5K potentiometer
1 - 10K resistor
2 - 0.1 uF caps
2 - 22 pF caps
1 - 16 MHz crystal
1 - Atmega328P microcontroller
1 - 28 pin IC socket
1 - 16 hole female header
1 - 4 hole female header
4 - male header strip pins
16 - male strip pins (for LCD)
1 - 330 ohm resistor
1 - 3 x AAA battery holder
3 - AAA batteries
4 - #4-40 3/4" bolts
4 - #4-40 nuts
#24 stranded wire
#24 single strand wire (for the antenna)
#30 - wire wrap wire
Heat shrink tubing
solder

Step 9: Arduino Code for the Final Build Rx and Tx

See attached the final versions of the Tx and Rx code.