Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
Hand tools and fabrication machines | ||||||
|
At work we use a lot of environmental monitors. I wanted something similar for home. I saw these DHT-11 Sensors on ebay pretty cheap. there are wider range and higher resolution version available but I wanted a few of them cheap.
I decided to do a simple serial interface so it would work easily with Linux, Pic's, Windows etc.. I have a few linux boxes around the house anyway so why not add to their usefulness.
I had a bunch of PIC16F73's left over from a project so I used them.
I opened the serial to USB adapter's case and ran a wire from the USB power pin to pin 9 on the serial port. This is actually the ring indicator input but this way I didn't need an external power connector.
I used Pic Basic Pro from MeLabs.
It would have been easier with an Arduino but I had all these things sitting here going to waste and rather than see them end up in the trash I used all the scraps so these cost me less than $5 each!
The hex file attached uses a simple menu interface good for testing and a raw data feed command for using in scripts.
Step 2: Final DesignI saw these nice time bulkhead boxes on Electronics Goldmine. I used them in my Tutorials on Balun's too.
I used a mill to cut the holes for the serial port and sensor but a Dremel or drill and file will do just as well.
Step 3: Miscelaneous PartsI used a 10Mhz ceramic resonator instead of the 10MHz crystal and two 12pf caps. I just happened to have a bunch of those around and its quicker to wire on a protoboard.
Step 4: Communicating with itIts pretty simple to talk to. I use 2400 Baud to help with slow devices or long cable runs.
The screen shot above was from Zterm on a mac.
The commands are simple and can be upper or lower case:
V - Version (4 line info header)
A - Ascii Reading Output (2 lines in plain English)
T - Temperature Reading (always 3 digits)
H - Humidity Reading (always 3 digits)
B - Both Reading separated by a comma
all readings are zero padded for fixed length. This makes it easy to read with some languages. All lines are terminated by a CR and LF. If the sensor fails the English commands will say "Sensor not Responding" and the data reads (T-H-B) will return 3 dashes in place of the reading.
:020000040000FA
:100000004E29B400841780048413A201201CA2008E
:1000100010200319492910200319492910204929C2
:100020003408A2063930A000FF30A10000083405D2
:100030002206031D2028A00A0319A10F1628080074
:10004000C830A00700300318013EA10703110800C3
:100050003708A0003508A1000130A200A301640008
:100060005020031C4328A20B2F28FF30A30703189E
:100070002F28A007031CA107031C08007D30A20045
:100080000030A3002F285B200830A3005C20502004
:10009000A20C4A28A30B46285C200314220808005F
:1000A000360884003408841780048413000533194B
:1000B0003406FF3E0800331700308A00330D06393E
:1000C000A0006E20A10000308A00200A6E20331F9D
:1000D000F6283313A00002300D21F628723E0318D3
:1000E0008A0A820001348E3403342E3400345534AD
:1000F0000C34F2340408A600360884008030B305BE
:100100000830A70003100318B30A9620A60CA70B0B
:1001100083280000AB1A330C96204C210314962040
:100120002F08A3002E08E920031449298413AB1FCC
:10013000A528000834042B1F34068000841700080B
:100140003404031C34068000B02800083404031C67
:1001500034062B1B34068000841734098005B02830
:100160002B081F39003EA1002A08083E0318A10AE7
:100170000000F628B31329080319B3170530A800A7
:100180002730A3001030D0200330A300E830D02067
:10019000A3016430D020A3010A30D0202408D7283E
:1001A000A2002508A1002408A00012212008A00018
:1001B000A8030319B31329080319E1282802031817
:1001C00008002008031DB313B31B0800303E442968
:1001D000A301A200FF30A207031CA307031C4929A7
:1001E0000330A100E430F620EA28A101F63EA00089
:1001F000A109031C0129FE300000A0070318FC28F8
:10020000A0076400A10FFB28000020180729201870
:10021000092908000310A10CA00CFF3E03180A29AD
:1002200020084929A501A4011030A600210DA40D24
:10023000A50D2208A4022308031C230FA5020318FE
:1002400028292208A40723080318230FA507031051
:10025000A00DA10DA60B1629200849291030A800D1
:10026000A101A001A70CA60C031C3C292208A00791
:1002700023080318230FA107A10CA00CA50CA40CA4
:10028000A80B322924084929840031088A00300843
:100290008200831303138312640008008316811302
:1002A000831205108316051083128510831685109E
:1002B000831205118316051183128511831685118A
:1002C0008312051283160512831285128316851276
:1002D000831206108316061083128610831686106A
:1002E0008312061183160611831286118316861156
:1002F0008312061283160612831286128316861242
:10030000831206138316061383128613831686132D
:100310008312071083160710831287108316871025
:100320008312071183160711831287118316871111
:1003300083120712831607128312871283168712FD
:1003400083120713831607138312871383168713E9
:1003500083128A118F230730B6000230B4000430B4
:10036000B3000130B700B5018A0128208A11031CAF
:10037000AB29F90064007908543C8A110319C62995
:1003800064007908743C8A11031DCC298A118F23DB
:100390008A153B208A118D2B64007908483C8A110C
:1003A0000319D82964007908683C8A11031DDE29E5
:1003B0008A118F238A157B208A118D2B640079087E
:1003C000423C8A110319EA2964007908623C8A11C7
:1003D000031DF0298A118F238A11E2278A118D2BA0
:1003E00064007908413C8A110319FC2964007908EA
:1003F000613C8A11031D022A8A118F238A11FA2671
:100400008A118D2B64007908563C8A1103190E2A33
:1004100064007908763C8A11031D8D2B0730B600E5
:100420000430B4008C30AA004130AB00AE01AF0103
:1004300054308A017B2065308A017B206D308A012F
:100440007B2070308A017B2065308A017B207230EE
:100450008A017B2061308A017B2074308A017B20F5
:1004600075308A017B2072308A017B2065308A01D9
:100470007B202F308A017B2048308A017B20753019
:100480008A017B206D308A017B2069308A017B20C4
:1004900064308A017B2069308A017B2074308A01B4
:1004A0007B2079308A017B2020308A017B204D30EF
:1004B0008A017B206F308A017B206E308A017B208D
:1004C00069308A017B2074308A017B206F308A0179
:1004D0007B2072308A017B200A308A017B200D301C
:1004E0008A017B200730B6000430B4008C30AA00AB
:1004F0004130AB00AE01AF0120308A017B202030BB
:100500008A017B2020308A017B2046308A017B20B3
:1005100069308A017B2072308A017B206D308A012C
:100520007B2077308A017B2061308A017B2072300A
:100530008A017B2065308A017B2020308A017B2064
:1005400056308A017B2065308A017B2072308A0117
:100550007B2073308A017B2069308A017B206F30D9
:100560008A017B206E308A017B2020308A017B202B
:1005700031308A017B202E308A017B2036308A017F
:100580007B200A308A017B200D308A017B200730D6
:10059000B6000430B4008C30AA004130AB00AE018C
:1005A000AF0120308A017B2020308A017B2020305F
:1005B0008A017B2020308A017B2043308A017B2006
:1005C0006F308A017B2070308A017B2079308A016C
:1005D0007B2072308A017B2069308A017B20673062
:1005E0008A017B2068308A017B2074308A017B205D
:1005F00020308A017B2028308A017B2063308A01E9
:100600007B2029308A017B2020308A017B203230F8
:100610008A017B2030308A017B2031308A017B20A7
:1006200034308A017B200A308A017B200D308A0118
:100630007B200730B6000430B4008C30AA00413073
:10064000AB00AE01AF014F308A017B2070308A01D0
:100650007B2065308A017B206E308A017B20203030
:100660008A017B2056308A017B2061308A017B2001
:100670006C308A017B206C308A017B2065308A01D6
:100680007B2079308A017B2020308A017B20433017
:100690008A017B206F308A017B206E308A017B20AB
:1006A00073308A017B2075308A017B206C308A018F
:1006B0007B2074308A017B2069308A017B206E3078
:1006C0008A017B2067308A017B2020308A017B20D1
:1006D00043308A017B206F308A017B2072308A018F
:1006E0007B2070308A017B202E308A017B200A30EB
:1006F0008A017B200D308A017B200730B600043050
:10070000B4008C30AA004130AB00AE01AF010A301A
:100710008A017B200D308A017B208A01AB290610DB
:1007200083160610123083128A01E82006148316FD
:100730000610193083128A01F5202030FD000130A7
:10074000A0000630840001308A0101202008E30067
:100750002108E4007D08A03E840063088000013089
:10076000FD028A1103189F2B2830FD006400213000
:100770007D028A11031CD12B0130A00006308400B9
:1007800001308A0101202008E3002108E4007D08EF
:10079000A03E8400630880000130FD028A11031826
:1007A000B62B2830FD007D08A03E84000008E30041
:1007B00064000B3063028A11031CE52B7D08383E70
:1007C0008400013080008A11E92B7D08383E8400C6
:1007D00080010130FD028A110318D32BFA01283061
:1007E000FD007D08A03E84000008E300640063086B
:1007F000003C8A11031DFE2B0130FA000130FD027E
:100800008A110318F12B6008A600A7018030A2000E
:10081000A3018A012E21E3002508E4005F08A60059
:10082000A7014030A200A3018A012E21E50025087E
:10083000E6006308E50764080318013EE6075E0862
:10084000A600A7012030A200A3018A012E21E70003
:100850002508E8006508E70766080318013EE80771
:100860005D08A600A7011030A200A3018A012E2175
:10087000E9002508EA006708E90768080318013E4F
:10088000EA075C08A600A7010830A200A3018A01BC
:100890002E21EB002508EC006908EB076A08031815
:1008A000013EEC075B08A600A7010430A200A301EB
:1008B0008A012E21ED002508EE006B08ED076C087B
:1008C0000318013EEE075A08A600A7010230A20055
:1008D000A3018A012E21EF002508F0006D08EF0723
:1008E0006E080318013EF0075808A600A701013062
:1008F000A200A3018A012E21F1002508F2006F0851
:100900007107F6005708A600A7018030A200A301D6
:100910008A012E21E3002508E4005608A600A7015D
:100920004030A200A3018A012E21E5002508E6003F
:100930006308E50764080318013EE6075508A600AA
:10094000A7012030A200A3018A012E21E70025087B
:10095000E8006508E70766080318013EE807540841
:10096000A600A7011030A200A3018A012E21E900F0
:100970002508EA006708E90768080318013EEA0746
:100980005308A600A7010830A200A3018A012E2166
:10099000EB002508EC006908EB076A080318013E24
:1009A000EC075208A600A7010430A200A3018A01A7
:1009B0002E21ED002508EE006B08ED076C080318EA
:1009C000013EEE075108A600A7010230A200A301D4
:1009D0008A012E21EF002508F0006D08EF076E0850
:1009E0000318013EF0075008A600A7010130A2003D
:1009F000A3018A012E21F1002508F2006F0871077A
:100A0000F7004F08A600A7018030A200A3018A01C9
:100A10002E21E3002508E4004E08A600A70140307F
:100A2000A200A3018A012E21E5002508E600630843
:100A3000E50764080318013EE6074D08A600A70174
:100A40002030A200A3018A012E21E7002508E8003A
:100A50006508E70766080318013EE8074C08A6008A
:100A6000A7011030A200A3018A012E21E900250868
:100A7000EA006708E90768080318013EEA074B081F
:100A8000A600A7010830A200A3018A012E21EB00D5
:100A90002508EC006908EB076A080318013EEC071B
:100AA0004A08A600A7010430A200A3018A012E2152
:100AB000ED002508EE006B08ED076C080318013EF9
:100AC000EE074908A600A7010230A200A3018A018F
:100AD0002E21EF002508F0006D08EF076E080318BF
:100AE000013EF0074808A600A7010130A200A301BB
:100AF0008A012E21F1002508F2006F087107F80025
:100B00004708A600A7018030A200A3018A012E2178
:100B1000E3002508E4004608A600A7014030A20033
:100B2000A3018A012E21E5002508E6006308E507F8
:100B300064080318013EE6074508A600A701203017
:100B4000A200A3018A012E21E7002508E80065081C
:100B5000E70766080318013EE8074408A600A70156
:100B60001030A200A3018A012E21E9002508EA0025
:100B70006708E90768080318013EEA074308A6006A
:100B8000A7010830A200A3018A012E21EB0025084D
:100B9000EC006908EB076A080318013EEC074208FD
:100BA000A600A7010430A200A3018A012E21ED00B6
:100BB0002508EE006B08ED076C080318013EEE07F0
:100BC0004108A600A7010230A200A3018A012E213C
:100BD000EF002508F0006D08EF076E080318013ECE
:100BE000F0074008A600A7010130A200A3018A0176
:100BF0002E21F1002508F2006F087107FB003F0865
:100C0000A600A7018030A200A3018A012E21E300E3
:100C10002508E4003E08A600A7014030A200A30179
:100C20008A012E21E5002508E6006308E50764082F
:100C30000318013EE6073D08A600A7012030A200E8
:100C4000A3018A012E21E7002508E8006508E707CF
:100C500066080318013EE8073C08A600A70110300B
:100C6000A200A3018A012E21E9002508EA006708F5
:100C7000E90768080318013EEA073B08A600A70138
:100C80000830A200A3018A012E21EB002508EC0008
:100C90006908EB076A080318013EEC073A08A6004A
:100CA000A7010430A200A3018A012E21ED0025082E
:100CB000EE006B08ED076C080318013EEE073908DB
:100CC000A600A7010230A200A3018A012E21EF0095
:100CD0002508F0006D08EF076E080318013EF007C5
:100CE0003808A600A7010130A200A3018A012E2125
:100CF000F1002508F2006F087107FC007B08A600D0
:100D0000A7010930A200A3018A012E21E3002508D2
:100D1000E4006308A0006408A1000530A200A3015C
:100D20008A011221E3002108E40020306307F30068
:100D300064080318013EF40077087807E300E40133
:100D4000E40D7B08E3070318E40A7C086307E1006D
:100D500064080318013EE20008002830FD00073057
:100D6000B6000430B4008C30AA004130AB00AE01B4
:100D7000AF0156308A017B2061308A017B206C30C4
:100D80008A017B2075308A017B2065308A017B20B7
:100D900020308A017B20A9017D08A400A5017A30BA
:100DA000B000B1018A01BA2020308A017B203D3099
:100DB0008A017B2020308A017B2020308A017B2021
:100DC000A9017D08A03E84000008E3006308A40098
:100DD000A5017A30B000B1018A01BA200A308A0137
:100DE0007B200D308A017B200130FD028A1103181F
:100DF000AF2E080064007A08003C8A11031D8C2F76
:100E00000730B6000430B4008C30AA004130AB008B
:100E1000AE01AF0154308A017B2065308A017B200E
:100E20006D308A017B2070308A017B2065308A0119
:100E30007B2072308A017B2061308A017B207430F4
:100E40008A017B2075308A017B2072308A017B20E9
:100E500065308A017B2020308A017B203D308A0169
:100E60007B2020308A017B20A9017308A40074082C
:100E7000A5007A30B000B1018A01BA2046308A015B
:100E80007B2020308A017B200A308A017B200D30B4
:100E90008A017B200730B6000430B4008C30AA00F1
:100EA0004130AB00AE01AF0148308A017B20753084
:100EB0008A017B206D308A017B2069308A017B208A
:100EC00064308A017B2069308A017B2074308A017A
:100ED0007B2079308A017B2020308A017B203D30C5
:100EE0008A017B2020308A017B20A9017708A40099
:100EF000A5017A30B000B1018A01BA2025308A01FB
:100F00007B2020308A017B200A308A017B200D3033
:100F10008A017B208A11DE2F0730B6000430B4002E
:100F20008C30AA004130AB00AE01AF0153308A01D2
:100F30007B2065308A017B206E308A017B207330F4
:100F40008A017B206F308A017B2072308A017B20EE
:100F500020308A017B206E308A017B206F308A012D
:100F60007B2074308A017B2020308A017B20723004
:100F70008A017B2065308A017B2073308A017B20C7
:100F800070308A017B206F308A017B206E308A01AD
:100F90007B2064308A017B2069308A017B206E309F
:100FA0008A017B2067308A017B2021308A017B20E7
:100FB0000A308A017B200D308A017B20AF308A0104
:100FC000E820080064007A08003C8A15031D1228F6
:100FD0000730B6000430B4008C30AA004130AB00BA
:100FE000AE01AF010330A9007308A4007408A50086
:100FF0007A30B000B1018A01BA202C308A017B20FE
:101000000330A9007708A400A5017A30B000B1012F
:101010008A01BA200A308A017B200D308A017B20A8
:101020008A1537280730B6000430B4008C30AA0087
:101030004130AB00AE01AF012D308A017B202D3055
:101040008A017B202D308A017B202C308A017B2075
:101050002D308A017B202D308A017B202D308A01A2
:101060007B200A308A017B200D308A017B20AF3043
:101070008A01E820080064007A08003C8A15031DF4
:101080005E280730B6000430B4008C30AA0041302E
:10109000AB00AE01AF010330A9007308A4007408CF
:1010A000A5007A30B000B1018A01BA200A308A0165
:1010B0007B200D308A017B208A1577280730B60007
:1010C0000430B4008C30AA004130AB00AE01AF0157
:1010D0002D308A017B202D308A017B202D308A0122
:1010E0007B200A308A017B200D308A017B20AF30C3
:1010F0008A01E820080064007A08003C8A15031D74
:101100009D280730B6000430B4008C30AA0041306E
:10111000AB00AE01AF010330A9007708A400A50120
:101120007A30B000B1018A01BA200A308A017B20EE
:101130000D308A017B208A15B6280730B6000430AE
:10114000B4008C30AA004130AB00AE01AF012D30AD
:101150008A017B202D308A017B202D308A017B2063
:101160000A308A017B200D308A017B20AF308A0152
:0A117000E820080063008A15BA2881
:02400E00F63F7B
:00000001FF
'****************************************************************
'* Name : DHT11.BAS *
'* Author : Robert Joseph Korn *
'* Notice : Copyright (c) 2013 Open Valley Consulting Corp *
'* : All Rights Reserved *
'* Date : 12/8/2013 *
'* Version : 1.6 *
'* Notes : *
'* : *
'****************************************************************
DEFINE PULSIN_MAX 200
DEFINE OSC 10
include "modedefs.bas"
OPTION_REG.7 = 0
low PORTA.0
low PORTA.1
low PORTA.2
low PORTA.3
low PORTA.4
low PORTA.5
low PORTB.0
low PORTB.1
low PORTB.2
low PORTB.3
low PORTB.4
low PORTB.5
low PORTB.6
low PORTB.7
low PORTC.0
low PORTC.1
low PORTC.2
low PORTC.3
low PORTC.4
low PORTC.5
low PORTC.6
low PORTC.7
dht var byte[41]
xht var byte[41]
cksum var word
cksum2 var byte
humdh var byte
humdl var byte
bas var byte
tempch var byte
tempcl var byte
tempf var word
x var byte
stat var byte
inbyte var byte
dht11 var PORTB.0
rxdp var PORTC.1
txdp var PORTC.2
gosub samp
main:
serin rxdp, N2400, 1, main, inbyte
Select Case inbyte
' case "d", "D"
' gosub dump
case "t", "T"
gosub samp
gosub printtemp
case "h", "H"
gosub samp
gosub printhumd
case "b", "B"
gosub samp
gosub printraw
case "a", "A"
gosub samp
gosub print
case "v", "V"
serout2 txdp,16780,["Temperature/Humidity Monitor",10,13]
serout2 txdp,16780,[" Firmware Version 1.6",10,13]
serout2 txdp,16780,[" Copyright (c) 2014",10,13]
serout2 txdp,16780,["Open Valley Consulting Corp.",10,13]
serout2 txdp,16780,[10,13]
end select
goto main
samp:
low dht11
pause 18
high dht11
pauseus 25
for x = 32 to 0 step-1
PulsIn dht11, 1, xht[x]
next x
for x = 40 to 33 step-1
PulsIn dht11, 1, xht[x]
next x
For x = 40 to 0 step-1
if xht[x] > 10 then
dht[x]=1
else
dht[x]=0
endif
next x
stat = 0
for x = 40 to 0 step-1
if xht[x] = 0 then
stat = 1
endif
next x
cksum2 = dht[40]*128+dht[39]*64+dht[38]*32+dht[37]*16+dht[36]*8+dht[35]*4+dht[34]*2+dht[32]*1
humdh = dht[31]*128+dht[30]*64+dht[29]*32+dht[28]*16+dht[27]*8+dht[26]*4+dht[25]*2+dht[24]*1
humdl = dht[23]*128+dht[22]*64+dht[21]*32+dht[20]*16+dht[19]*8+dht[18]*4+dht[17]*2+dht[16]*1
tempch = dht[15]*128+ dht[14]*64+dht[13]*32+dht[12]*16+dht[11]*8+dht[10]*4+dht[9]*2+dht[8]*1
tempcl = dht[7]*128+ dht[6]*64+dht[5]*32+dht[4]*16+dht[3]*8+dht[2]*4+dht[1]*2+dht[0]*1
TempF = (TempCh*9/5)+32
cksum = humdh + humdl + tempch + tempcl
' if cksum.lowbyte <> cksum2 then
' STAT = 1
' endif
return
dump:
for x = 40 to 0 step-1
serout2 txdp,16780,["Value ",DEC x," = ",DEC xht[x],10,13]
next x
return
print:
if stat = 0 then
' serout2 txdp,16780,["Temperature = ",dec tempch, ".", dec1 tempcl,"C ",10,13]
serout2 txdp,16780,["Temperature = ",dec tempf,"F ",10,13]
serOUT2 txdp,16780,["Humidity = ",DEC humdh, "% ",10,13]
else
serout2 txdp,16780,["Sensor not responding!",10,13]
' serout2 txdp,16780,["Checksum = ",dec cksum, "/", dec cksum.lowbyte, "/", dec cksum2, 10,13]
endif
pause 175
return
printraw:
if stat = 0 then
serOUT2 txdp,16780,[dec3 tempf,",",dec3 humdh, 10,13]
else
serout2 txdp,16780,["---,---",10,13]
endif
pause 175
return
printtemp:
if stat = 0 then
serOUT2 txdp,16780,[dec3 tempf,10,13]
else
serout2 txdp,16780,["---",10,13]
endif
pause 175
return
printhumd:
if stat = 0 then
serOUT2 txdp,16780,[dec3 humdh, 10,13]
else
serout2 txdp,16780,["---",10,13]
endif
pause 175
return
end
Comments