Introduction: Wireless Temperature Sensor
Consisting of 2 circuits
One reads the temperature using a DS18B20 and then transmitts it over the radio waves.
The other receives the data and displays it.
I've not fully tested the range yet, but I've had it working over 12 feet going through 2 walls.
Transmitter Parts List:
One reads the temperature using a DS18B20 and then transmitts it over the radio waves.
The other receives the data and displays it.
I've not fully tested the range yet, but I've had it working over 12 feet going through 2 walls.
Transmitter Parts List:
- Picaxe 08m
- DS18B20 temp sensor
- AM RT4-433.9 transmitter module
- LED
- 4k7 resistor
- 1k resistor
- 3.5v Battery
- Picaxe 18X
- AM HRR3 433.9 Receiver module
- 7 segment I2c module
- 5mm 2 pin Bi-Colour LED -- red and green
Step 1: Build the Circuit
The diagram below shows the circuit to build. I apologies for the poor quality, I did attempt drawing it in Eagle at first, but didn't get too far and decided it would be quicker to just draw it in Ms Paint !
The transmitter circuit is shown at the top, I actually didn't use 5v, instead I ran it off a 3.5v button battery. The button battery was hooked up to a solar cell; a module I pulled from a cheap solar torch. I've had the transmitter circuit lying on my window sill, happily transmitting for a week with no power problems.
The AM transmitter/Receiver I had bought years ago from Maplin.
The receiver circuit is shown below, it is very simple. Pins 11 and 12 on the chip is actually a bi-colour LED, I wasn't sure how best to draw it.
The counter looking object in the top right makes displaying a number easy work. I needed a chip that could use the I2C, which is why I'm using a Picaxe18X. The 7 segment module was bought off ebay for about �15, but they do sell it on their website
I've not shown the programming header, partly to keep it simple and clean and partly because I was using a seperate circuit to program the chip.
The transmitter circuit is shown at the top, I actually didn't use 5v, instead I ran it off a 3.5v button battery. The button battery was hooked up to a solar cell; a module I pulled from a cheap solar torch. I've had the transmitter circuit lying on my window sill, happily transmitting for a week with no power problems.
The AM transmitter/Receiver I had bought years ago from Maplin.
The receiver circuit is shown below, it is very simple. Pins 11 and 12 on the chip is actually a bi-colour LED, I wasn't sure how best to draw it.
The counter looking object in the top right makes displaying a number easy work. I needed a chip that could use the I2C, which is why I'm using a Picaxe18X. The 7 segment module was bought off ebay for about �15, but they do sell it on their website
I've not shown the programming header, partly to keep it simple and clean and partly because I was using a seperate circuit to program the chip.
Step 2: Writing the Transmitter Code
The code for the 08M Transmitter circuit:
'------------------------------------------------------------
'08M Project Board - Transmitter
SYMBOL TX_PIN = 1
SYMBOL TXLED_PIN = 2
SYMBOL TempSend_PIN = 4
SYMBOL BAUDRATE = N1200
SYMBOL TmpReading = b1
pause 2000
main:
'read temp
readtemp TempSend_PIN,TmpReading ' read value into b1
pause 150
'blink LED
high TXLED_PIN
pause 50
low TXLED_PIN
send
pause 50
SerOut TX_PIN, BAUDRATE, ("UUUUUUUUUUUUUUUUUUUUU")
pause 20
if TmpReading > 127 then 'negative number
let TmpReading = TmpReading - 128 ' adjust neg value
b2 = "-"
Else 'positive
b2 = " "
End if
serout TX_PIN, BAUDRATE, ("TP",b2,TmpReading,"x")
SerTxD (#TmpReading)
'nap 6
GOSUB Wait1Minute
goto main
Wait1Minute:
'turn clock speed down
poke $8F,%01100000 'Set clock to 31kHz ~19bps
'Disable Brown Out Detection
DisableBod
sleep 4 'in multiples of 2.3
'change it all back
EnableBod
poke $8F,%01100000 'Set clock to 4MHz 2400bps
RETURN
End
'------------------------------------------------------------
The Wait1Minute sub procedure uses a few techniques to lower the power consumption.
'------------------------------------------------------------
'08M Project Board - Transmitter
SYMBOL TX_PIN = 1
SYMBOL TXLED_PIN = 2
SYMBOL TempSend_PIN = 4
SYMBOL BAUDRATE = N1200
SYMBOL TmpReading = b1
pause 2000
main:
'read temp
readtemp TempSend_PIN,TmpReading ' read value into b1
pause 150
'blink LED
high TXLED_PIN
pause 50
low TXLED_PIN
send
pause 50
SerOut TX_PIN, BAUDRATE, ("UUUUUUUUUUUUUUUUUUUUU")
pause 20
if TmpReading > 127 then 'negative number
let TmpReading = TmpReading - 128 ' adjust neg value
b2 = "-"
Else 'positive
b2 = " "
End if
serout TX_PIN, BAUDRATE, ("TP",b2,TmpReading,"x")
SerTxD (#TmpReading)
'nap 6
GOSUB Wait1Minute
goto main
Wait1Minute:
'turn clock speed down
poke $8F,%01100000 'Set clock to 31kHz ~19bps
'Disable Brown Out Detection
DisableBod
sleep 4 'in multiples of 2.3
'change it all back
EnableBod
poke $8F,%01100000 'Set clock to 4MHz 2400bps
RETURN
End
'------------------------------------------------------------
The Wait1Minute sub procedure uses a few techniques to lower the power consumption.
Step 3: Writing the Receiver Code
The Receiver code is a little more complicated because of the 7 segment I2c module, but the CONVERT sub does most of the hard work.
'------------------------------------------------------------
'18X - Receiver
SYMBOL RCV_PIN = 7
SYMBOL DATA_RCVD =w3
SYMBOL DATA_RCVD_SIGN = b3
SYMBOL CHECK_DATA= b1
SYMBOL BAUDRATE = N1200 'Must b T2400 if using USB-Serial
symbol temp = b12
symbol Cnt= w2 ' Counter
symbol Digit0 = b8 ' Hold digit0 data
symbol Digit1 = b9 ' Hold digit1 data
symbol Digit2 = b10 ' Hold digit2 data
symbol Digit3 = b11 ' Hold digit3 data
symbol slvAddrWR = $70 ' I2C write address
symbol slvAddrRD = $71 ' I2C read address
PAUSE 1000
i2cslave slvAddrWR, i2cslow, i2cbyte 'Initialize I2C-7SEG
writei2c 0,(%01000111)
NXT:
LOW 5
LOW 6
SERIN RCV_PIN, BAUDRATE,("TP"), DATA_RCVD_SIGN, DATA_RCVD, CHECK_DATA
if CHECK_DATA = "x" then
SERTXD ("Val ", DATA_RCVD_SIGN, #DATA_RCVD,13,10)
'turn green
LOW 5
HIGH 6
pause 100
Else 'Check bit failed to receive properly
sertxd ("bad. ","sign ",DATA_RCVD_SIGN," - " , #DATA_RCVD_SIGN ," ,rcvd1 ",DATA_RCVD, " - ", #DATA_RCVD , ", chk ", CHECK_DATA, " - ", #CHECK_DATA,13,10)
'Turn Red
LOW 6
HIGH 5
End if
pause 100
let cnt = DATA_RCVD
GOSUB CONVERT ' Convert decimal into each LED segment
'clear first 2 digits
Digit3 = $0
Digit2 = $0
writei2c 1,(Digit0,Digit1,Digit2,Digit3) ' Write each digit to 7-segment
GOTO NXT
CONVERT: ' Lookup table for 7-segment
temp = cnt % 10
LOOKUP temp, ($3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$77,$7C,$39,$5E,$79,$71), Digit0
temp = cnt / 10 % 10
LOOKUP temp, ($3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$77,$7C,$39,$5E,$79,$71), Digit1
temp = cnt / 100 % 10
LOOKUP temp, ($3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$77,$7C,$39,$5E,$79,$71), Digit2
temp = cnt / 1000 % 10
LOOKUP temp, ($3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$77,$7C,$39,$5E,$79,$71), Digit3
RETURN
'------------------------------------------------------------
When I first started using the module I was getting some interference and so sometimes it wouldn't show the correct value, so I added a check byte at the end, to check that the data was received properly. When the data is received properly the LED will flash green, if "bad" data is received it'll flash red.
The lines
Digit3 = $0
Digit2 = $0
are added to stop the first 2 digits on the display from showing, as they don't need to be on.
'------------------------------------------------------------
'18X - Receiver
SYMBOL RCV_PIN = 7
SYMBOL DATA_RCVD =w3
SYMBOL DATA_RCVD_SIGN = b3
SYMBOL CHECK_DATA= b1
SYMBOL BAUDRATE = N1200 'Must b T2400 if using USB-Serial
symbol temp = b12
symbol Cnt= w2 ' Counter
symbol Digit0 = b8 ' Hold digit0 data
symbol Digit1 = b9 ' Hold digit1 data
symbol Digit2 = b10 ' Hold digit2 data
symbol Digit3 = b11 ' Hold digit3 data
symbol slvAddrWR = $70 ' I2C write address
symbol slvAddrRD = $71 ' I2C read address
PAUSE 1000
i2cslave slvAddrWR, i2cslow, i2cbyte 'Initialize I2C-7SEG
writei2c 0,(%01000111)
NXT:
LOW 5
LOW 6
SERIN RCV_PIN, BAUDRATE,("TP"), DATA_RCVD_SIGN, DATA_RCVD, CHECK_DATA
if CHECK_DATA = "x" then
SERTXD ("Val ", DATA_RCVD_SIGN, #DATA_RCVD,13,10)
'turn green
LOW 5
HIGH 6
pause 100
Else 'Check bit failed to receive properly
sertxd ("bad. ","sign ",DATA_RCVD_SIGN," - " , #DATA_RCVD_SIGN ," ,rcvd1 ",DATA_RCVD, " - ", #DATA_RCVD , ", chk ", CHECK_DATA, " - ", #CHECK_DATA,13,10)
'Turn Red
LOW 6
HIGH 5
End if
pause 100
let cnt = DATA_RCVD
GOSUB CONVERT ' Convert decimal into each LED segment
'clear first 2 digits
Digit3 = $0
Digit2 = $0
writei2c 1,(Digit0,Digit1,Digit2,Digit3) ' Write each digit to 7-segment
GOTO NXT
CONVERT: ' Lookup table for 7-segment
temp = cnt % 10
LOOKUP temp, ($3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$77,$7C,$39,$5E,$79,$71), Digit0
temp = cnt / 10 % 10
LOOKUP temp, ($3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$77,$7C,$39,$5E,$79,$71), Digit1
temp = cnt / 100 % 10
LOOKUP temp, ($3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$77,$7C,$39,$5E,$79,$71), Digit2
temp = cnt / 1000 % 10
LOOKUP temp, ($3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$77,$7C,$39,$5E,$79,$71), Digit3
RETURN
'------------------------------------------------------------
When I first started using the module I was getting some interference and so sometimes it wouldn't show the correct value, so I added a check byte at the end, to check that the data was received properly. When the data is received properly the LED will flash green, if "bad" data is received it'll flash red.
The lines
Digit3 = $0
Digit2 = $0
are added to stop the first 2 digits on the display from showing, as they don't need to be on.
Step 4: The Future
Many things could be improved.
The first thing I did was take the components of the prototyping board and put them into a permanent breadboard home. Partly because I wanted something permanent I could place on my window sill and partly because I wanted to free the proto board to test out some 7 segment driver chips.
The transmitter
The first thing I did was take the components of the prototyping board and put them into a permanent breadboard home. Partly because I wanted something permanent I could place on my window sill and partly because I wanted to free the proto board to test out some 7 segment driver chips.
The transmitter
- Could detect light levels and send signal less often if it's dark outside, as this would conserve power
- It could check the voltage of the battery and not send if the battery is low - this would requite a reference voltage though.
- A better arial than my coiled up single core wire.
- When sending, transmit a Device ID, so more than one transmitter could be used
- Show battery level on a LED - red blink if very low, green led if power level is good.
- Manual button for sending temperature
- Add a single 7 segment display to show temp at the touch of a button - For simplicity I would probably use a different picaxe chip, one with more outputs.
- Instead of displaying on a 7 segment it could show on a LCD send to a PC via serial
- If sending via serial cable the device could be powered of USB and use a virtial USB port to send serial data. There are a few of these modles on ebay using FTDI's FT232BM chip.
- Display negative numbers - I don't know how to show negative numbers with the current 7 segment display