//Exampletesting sketchforvarious DHT humidity/temperature sensors//Writtenby ladyada,public domain#include "DHT.h"#define DHTPIN 2 // what pin we're connected to//Uncommentwhatever type you're using!#define DHTTYPE DHT11 // DHT 11//#define DHTTYPE DHT22 // DHT 22 (AM2302)//#define DHTTYPE DHT21 // DHT 21 (AM2301)// Connect pin 1 (on the left) of the sensor to +5V// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1// to 3.3V instead of 5V!// Connect pin 2 of the sensor to whatever your DHTPIN is// Connect pin 4 (on the right) of the sensor to GROUND// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor// Initialize DHT sensor for normal 16mhz ArduinoDHT dht(DHTPIN, DHTTYPE);// NOTE: For working with a faster chip, like an Arduino Due or Teensy, you// might need to increase the threshold for cycle counts considered a 1 or 0.// You can do this by passing a 3rd parameter for this threshold. It's a bit//of fiddling to find the right value,butingeneral the faster the CPU the//higher the value.Thedefaultfora16mhzAVRisa value of6.Foran//ArduinoDuethat runs at84mhza value of30works.//Exampleto initialize DHT sensorforArduinoDue://DHT dht(DHTPIN,DHTTYPE,30);void setup(){Serial.begin(115200);Serial.println("DHTxx test!");dht.begin();}void loop(){//Waita few seconds between measurements.delay(2000);//Readingtemperatureorhumidity takes about250milliseconds!//Sensorreadings may also be up to2seconds'old'(its a very slow sensor)float h=dht.readHumidity();//ReadtemperatureasCelsiusfloat t=dht.readTemperature();//ReadtemperatureasFahrenheit//Checkifany reads failedandexit early(totryagain).if(isnan(h)||isnan(t)){Serial.println("Failed to read from DHT sensor!");return;}Serial.print("Humidity: ");Serial.print(h);Serial.print(" ");Serial.print("Temperature: ");Serial.print(t);Serial.println(" ");}
python读取arduino串口数据_从Arduino项目读取串行数据(pySerial)
最新推荐文章于 2024-03-18 08:00:00 发布