8493| 1
|
[入门] dth11,1602扩展版,arduino uno温度计简单教程, |
1602扩展版温度计 今天又用1602显示屏扩展板+dth11温度计,ArduinoUNO做了一个温度计,这个温度计最大的特点是简单,接三根线就行,剩下的就是烧录程序了。 Arduino IDE版本:1.0.6 程序如下。 缺点是,要按,才测量温度,不按不理你。 DTH11,用的是12号中断口。 1602显示屏扩展板是一体的,买回来就是这样,但是缺几根针,我去焊了几根针。这个扩展板不好用,没传感器什么的,不推荐各位买。 [mw_shl_code=applescript,true]#include <LiquidCrystal.h> #include <dht11.h> #include <Wire.h> dht11 DHT; #define DHT11_PIN 12 LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7); char msgs[5][3] = {"Ri", "Up", "Do", "Le", "Se" }; int adc_key_val[5] ={50, 200, 400, 600, 800}; int NUM_KEYS = 5; int adc_key_in; int key=-1; int oldkey=-1; void setup() { //put your setup code here, to run once: lcd.clear(); lcd.begin(16, 2); lcd.setCursor(0,0); lcd.print("% CRQ shcool %"); } void loop() { delay (1000); //put your main code here, to run repeatedly: adc_key_in = analogRead(0); //read the value from the sensor key= get_key(adc_key_in); // convert intokey press if(key != oldkey) // if keypress isdetected { delay(50); // wait for debouncetime adc_key_in = analogRead(0); //read the value from the sensor key = get_key(adc_key_in); //convert into key press if (key != oldkey) { lcd.setCursor(0, 1); int chk;//chk用于存储DHT11传感器的数据 Serial.print("DHT11 \t"); //读取DHT11传感器的数据 chk = DHT.read(DHT11_PIN); switch(chk) { caseDHTLIB_OK: Serial.print("OK,\t"); break; caseDHTLIB_ERROR_CHECKSUM: Serial.print("Checksumerror,\t"); break; caseDHTLIB_ERROR_TIMEOUT: Serial.print("Time outerror,\t"); break; Serial.print("Unknown error,\t"); break; } //串口显示温湿度值 Serial.print(DHT.humidity,1); Serial.print("\t"); Serial.println(DHT.temperature,1); oldkey = key; if (key >=0){ lcd.print("H"); lcd.print(DHT.humidity,1); lcd.print("% "); lcd.print(msgs[key]); lcd.print(" "); lcd.print(DHT.temperature,1); lcd.print("C"); } } } delay(100); } // Convert ADC value to key number int get_key(unsigned int input) { int k; for (k = 0; k < NUM_KEYS; k++) { if (input < adc_key_val[k]) { return k; } } if (k >= NUM_KEYS)k = -1; //No valid key pressed return k; }[/mw_shl_code] |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed