Posts

Showing posts with the label how to drive DHT11 sensor

How to Drive DHT sensor without Library

Image
 Let's code! Expalantions are in the code area. Happy Coding! /* * DHT 11 driving without library * * http://en.devrelerim.com * Author : Hakan OZMEN (hakkanr@gmail.com) * Date : 30.03.2021 * * You can change or share all / or same part of * this code. Free of charge! :) */ uint8_t data [ 5 ] ; // to save our 8bit * 5 data void setup ( ) { Serial . begin ( 115200 ) ; } /* *  This function count an 8bit integer value *  while given signal is not changed *  no need to measure time counting is also *  need time ;) */ uint8_t expectedSignal ( bool level ) {   uint8_t count = 0 ;   while ( digitalRead ( 2 ) == level ) count ++ ;   return count ; } void loop ( ) { delay ( 2000 ) ; // wait 2 secs for sensor to initialize Serial . println ( "----------------------" ) ; pinMode ( 2 , INPUT_PULLUP ) ; // Standard is HIGH delay ( 1000 ) ; pinMode ( 2 , OUTPUT ) ; // make pin 2 output digitalWrite ( 2 , LO

Working Principle of DHT Sensors and Analysis with Logic Analyzer

Image
 What's inside DHT11 sensor , I've removed the plastic case and what I saw is :     There is a resistive type humidity measurement component, a NTC to measure temperature and a 8 bit microcontroller and it uses single-wire serial interface to communicate  with other systems. Measurement range 0-50 °C in temp and 20-90%RH in humidity. Accuracy for temp is ±2°C, ±5%RH for humidity, and last information about it is resolution is 1.          What about the power? it can work between 3v and 5.5V, this means you can use it 3.3v boards and also 5v boards. Communication Process      This is the part I like the most !     - One communication process is about 4ms.     - Data format : 8bit Humidity (integer part) 8bit Humidity (decimal Part) 8bit Temp (integer part) 8bit Temp (decimal Part) 8bit checksum totally we have 40 bits of data to deal with. Let's look at the signal on data pin with logic analyzer     There are two timing maker pairs A1 to A2 (at the same point B1),