1. Description MCU: Zero-knowledge open source development board - standard board Module: DHT11 module Development tools: Zero-knowledge open source development tools
The DHT11 module is a single bus interface, which is very simple to use. It is powered by 3.3-5V and can be used directly on the Zero Knowledge Laboratory platform. The wiring is shown below. Connect the OUT pin of the module to the A0 pin of the Zero Knowledge standard board. 2. Test After the corresponding connections are connected, just open the Zero Knowledge open source development tool to find the corresponding code, upload the program and open the debug window to see the debugging results. 3. Core code
- // DHT11 temperature and humidity sensor demo#include "dht11.h" //Use DHT11 DHT sensor; void setup() { Serial.begin(9600); //Use A0 pin to connect to the output pin of DHT11 modulesensor.attach(A0); delay(1000); } void loop() { //Start to get temperature and humidity datasensor.update(); switch (sensor.getLastError()) { case DHT_ERROR_OK: char msg[128]; //Format output sprintf(msg, "Temperature = %dC, Humidity = %d%%", sensor.getTemperatureInt(), sensor.getHumidityInt()); Serial.println(msg); break; case DHT_ERROR_START_FAILED_1: Serial.println("Error: start failed (stage 1) "); break; case DHT_ERROR_START_FAILED_2: Serial.println("Error: start failed (stage 2)"); break; case DHT_ERROR_READ_TIMEOUT: Serial.println("Error: read timeout"); break; case DHT_ERROR_CHECKSUM_FAILURE: Serial.println("Error: checksum error"); break; } delay(2000);
复制代码The complete project and more detailed information can be obtained for free on the official website of Zero Knowledge Lab.
This content is originally created by EEWORLD forum user roc2. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source