Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20578

Share your working BASCOM-AVR code here : HONEYWELL HIH-6130/21 Humidity Sensor : NEWTOPIC

$
0
0
If you need some sort of accuracy in a lower cost temperature and humidity sensor the the Honeywell HIH-6130, HIH6121 is a good choice they are I2C so easy to connect to the AVR . I have tried the DHT11 and its humidity readings are useless when compared to an accurate wet/dry hygrometer more than 20% out whereas the HIH-6130, HIH-6121 readings are well within the document accuracy 2 to 3%. So I obtained two of the HIH-6130 sensors and wrote the code to get readings from them. Regards Paul [code:1:a8bce215f8] 'variables '----HIH-6130-I2C----------------------- '--Honeywell HumidIcon Digital Humidity/Temperature Sensors '--write address 4E '--read address 4F Dim Hihtemp As Long 'four bytes sent from sensor Dim Hihrcd(2) As Word At Hihtemp Overlay 'break up long into two words Dim Hihbuf(4) As Byte At Hihtemp Overlay break up long into four bytes Dim Hihstatus As Byte Dim Humiditys As Single Sub Hih_6130_write '--this starts a measurement cycle to begin I2cstart I2cwbyte &H4E I2cstop End Sub 'Read Temperature and humidity Sub Hih_6130_read Local Temph As Word 'humidity Local Tempstat As Word 'status bits I2cstart I2cwbyte &H4F I2crbyte Hihbuf(4) , Ack I2crbyte Hihbuf(3) , Ack I2crbyte Hihbuf(2) , Ack I2crbyte Hihbuf(1) , Nack I2cstop Tempstat = Hihrcd(2) Shift Tempstat , Right , 14 'remove data and leave status bits Hihstatus = Tempstat 'get humidity value Shift Hihrcd(2) , Left , 2 'remove the first 2 bits Shift Hihrcd(2) , Right , 2 'so we are left with the humidity Humiditys = Hihrcd(2) Humiditys = Humiditys * 6.10e-3 'get temp value Shift Hihrcd(1) , Right , 2 'last 2 bits are of no use Tempras = Hihrcd(1) Tempras = Tempras * 1.007e-2 Tempras = Tempras - 40 End Sub [/code:1:a8bce215f8]

Viewing all articles
Browse latest Browse all 20578

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>