In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Raspberry pie how to control the temperature and humidity sensor DHT11, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
Xiao π always fails to start up because he didn't turn off the system before several power outages. Had no choice but to rewrite the SD card. After being installed, a temperature and humidity sensor (DHT11) was connected to Xiao π the night before last, and the data was read out smoothly. Let's cut the crap and get to the point:
First of all, a brief introduction to DHT11:
DHT11 is a temperature and humidity sensor, which is divided into three interfaces: VCC, DATA and GND.
Pin number name type indicates 1VCC power supply + level, input 3V-5.5V2DATA data output pin 3GND ground pin
With a picture of DHT11:
DHT11 specification 200808 revised edition .pdf
It was said on the Internet before that it was necessary to add a resistance between DHT11VCC and DATA, which was not needed at all after the test.
Pin connection:
For the pins of the second generation of raspberry pie, you can see the following Blog: raspberry pie controlled active buzzer
If VCC is connected to 3V3, you can choose 1 port or 17 ports.
DATA connected to the GPIO port, I chose GPIO4, the seventh port
GND is connected to the grounding port. I chose the 14th port.
Python to obtain temperature and humidity:
123456789101112131415161718192021222325262728293031333435363738394041434446474849505154555758596061626566676869The binthonimport RPi.GPIO as GPIOimport timechannel = 4 / / GPIO4data = [] j = 0GPIO.setmode (GPIO.BCM) time.sleep (1) GPIO.setup (channel, GPIO.LOW) GPIO.output (channel, GPIO.LOW) time.sleep (0.02) GPIO.output (channel, GPIO.HIGH) GPIO.setup (channel, GPIO.IN) while GPIO.input (channel) = GPIO.LOW: continuewhile GPIO.input (channel) = GPIO.HIGH continuewhile j
< 40: k = 0 while GPIO.input(channel) == GPIO.LOW: continue while GPIO.input(channel) == GPIO.HIGH: k += 1 if k >Break if k < 8: data.append (0) else: data.append (1) j + = 1print "sensor is working." print datahumidity_bit = data [0:8] humidity_point_bit = data [8:16] temperature_bit = data [16:24] temperature_point_bit = data [24:32] check_bit = data [32:40] humidity = 0humidity_point = 0temperature = 0temperature_point = 0check = 0for i in range (8): humidity + = Humidity_ bit [I] * 2 * * (7meri) humidity_point + = humidity_point_ bit [I] * 2 * * (7Meii) temperature + = temperature_ bit [I] * 2 * * (7Maii) temperature_point + = temperature_point_ bit [I] * 2 * check + = check_ bit [I] * 2 * * (7Muti) tmp = humidity + humidity_point + temperature + temperature_pointif check = tmp: print "temperature:" Temperature, "* C, humidity:", humidity, "%" else: print "wrong" print "temperature:", temperature, "* C, humidity:", humidity, "% check:", check, ", tmp:", tmpGPIO.cleanup ()
Show the results:
1234root@raspberrypi:/data/basedata# python/dht11.pysensor is working. [0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0] temperature: 20 * C, humidity: 38%
In order to test whether the results are accurate, I put my finger on the sensor and the test data are:
12345root@raspberrypi:/data/basedata/python# python dht11.pysensor is working. [0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1] wrongtemperature: 36 * C, humidity: 38%
Confirm that it is correct ~
Note: if you are using DS18B20, you need to do the following:
1234567root@raspberrypi:/# apt-get updateroot@raspberrypi:/# apt-get upgrade # update kernel root@raspberrypi:/# rebootroot@raspberrypi:/# vi / boot/config.txt # manually added on the last line: dtoverlay=w1-gpio-pullup Gpiopin=4 to support the new system to read the w1 bus device root@raspberrypi:/# modprobe w1-gpio # confirm whether the device works root@raspberrypi:/# modprobe w1-thermroot@raspberrypi:/# cd / sys/bus/w1/devices/ the answer to the question about how the raspberry pie controls the temperature and humidity sensor DHT11 is shared here I hope the above content can help you to a certain extent, if you still have a lot of doubts to be solved, you can follow the industry information channel to learn more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.