Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 08, 2016, 03:04:29 03:04


Login with username, password and session length


Pages: [1]
Print
Author Topic: Code for AM2301, AM2302, DHT22, DHT11 Temperature & Humidity Sensor  (Read 3409 times)
0 Members and 1 Guest are viewing this topic.
mcu
Newbie
*
Offline Offline

Posts: 12

Thank You
-Given: 0
-Receive: 13


« on: October 25, 2014, 09:22:50 21:22 »

Here is a picture of AM2301 low cost (US $5 / piece) Capacitive Digital Temperature & Humidity Sensor.


Front


Back


Front No cover


Board


Board (Magnified)


Signal


Format

As you can see in datasheet this sensor just needs single wire to communicate.

for communication:
1. send request (MCU pin is output [max 2 requests in second])
2. wait for response signal (MCU pin is input)
3. read 16-bit humidity data
4. read 16-bit temperature data
5. read 8-bit parity

I wrote code for the sensor (using Proton compiller) and worked well.
Most of sensors made by AOSONG company are very similar together so you can use this code for other Digital type.

*Please note that all measurements are time based so if your application needs change frequency (or changing crystal [by default it set to 20MHz]) you should read Proton manual for "PulseIn" instruction to get value around 75 an 60 microsecond. (change should be applied by changing "37" for 75uSec and "30" for 60uSec in the code.)

**Here is "PulseIn" Note:
The variable can be either a Word or a Byte . If the variable is a word, the value returned by
PulseIn can range from 1 to 65535 units.
The units are dependant on the frequency of the crystal used. If a 4MHz crystal is used, then
each unit is 10us, while a 20MHz crystal produces a unit length of 2us.

If the variable is a byte and the crystal is 4MHz, the value returned can range from 1 to 255
units of 10μs. Internally, PulseIn always uses a 16-bit timer. When your program specifies a
byte, PulseIn stores the lower 8 bits of the internal counter into it. Pulse widths longer than
2550μs will give false, low readings with a byte variable. For example, a 2560μs pulse returns a
reading of 256 with a word variable and 0 with a byte variable.



Datasheet:
AM2301: https://www.dropbox.com/s/l3j01vhvvqgaksl/AM2301.pdf?dl=0
AM2302: https://www.adafruit.com/datasheets/Digital%20humidity%20and%20temperature%20sensor%20AM2302.pdf
DHT11:   http://www.micro4you.com/files/sensor/DHT11.pdf
DHT22:   ftp://imall.iteadstudio.com/Sensor/IM120712007/DS_IM120712007.pdf
« Last Edit: October 25, 2014, 09:57:07 21:57 by mcu » Logged
waicon
Active Member
***
Offline Offline

Posts: 127

Thank You
-Given: 55
-Receive: 62


I'm learning to Dream...not Relaxing...zzZ


« Reply #1 on: October 01, 2016, 01:26:07 13:26 »

have been using this sensor AM2301 for 2 years, working good, but
only one issue i encountered, hum% will driff higher(99% Undecided) after about 8 months of continue of using it.

control condition:-
hum% =80%  +/_ 5%
sampling rate: 10sec intervel.

seen tobe humility sensor saturated, have anyone using it have this issue ?
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC