(后面制作pcb)
一:说明
1.该加湿器自定义湿度阈值为60%RH,可手动按键更改阈值
2.加湿器可USB供电或自带使用锂电源电池
3.加湿器为自动控制,无需人工干预
二:加湿器控制策略
湿度小于阈值时,开通继电器使物化片工作。
湿度小于阈值时,关闭继电器,物化片停止工作
三:加湿器控制芯片
加湿器的控制芯片为Arduino Nano(Atmega328P)
参考下图:
四:湿度传感器
加湿器采用的湿度传感器为DHT11,具体可度娘一下~
带有上拉电阻的DHT11模块
五:其他介绍
- 两个按键
- 一个继电器
- 备用电源电池开关
- 单独供电图:
- USB供电图:单独供电图
-
ACT:雾化片这里就不展示了,tb上有的是>_<
-
六:软件编程
软件IDE:Arduino IDE(没错,就是有手就行的ArduinoIDE!)
ACT:ArduinoIDE下载网址:
官网下载https://arduino.en.softonic.com/
百度网盘资源地址:https://pan.baidu.com/s/1pL9CnI7
网盘资源提取密码:无需提取码
全部代码如下:
#include <Arduino.h>#include <SimpleDHT.h>#include "U8glib.h"//#include <U2g2lib.h>#define DHTpin 5 //自己按需求修改#define Red_led 2#define key_1 7#define key_2 9#define relay 13U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);// 初始化i2c接口SimpleDHT11 dht11(DHTpin);//初始化DHT11对象String tmp; String hmp;String KHS = "60";//显示阈值int KH=60; //实际阈值void draw_hello(void) {u8g.setFont(u8g_font_unifont);u8g.drawStr( 0, 22, "Hello Baby!");}void draw_data(void) {//具体显示屏显示内容u8g.setFont(u8g_font_unifont);//设置字体u8g.drawStr( 0, 16, tmp.c_str());//写入字符串u8g.drawStr( 0, 32, hmp.c_str());u8g.drawStr( 15, 48, KHS.c_str());}void setup() {// put your setup code here, to run once:/*GPIO初始化*///pinMode(Red_led,OUTPUT);pinMode(8, OUTPUT);//不知道干啥的pinMode(key_1,INPUT);pinMode(key_2,INPUT);pinMode(relay,OUTPUT);/*串口初始化*/Serial.begin(9600);draw_hello();delay(1500);/*Here is nothing!!*//*这是一个空行*/// flip screen, if required// u8g.setRot180();// set SPI backup if required//u8g.setHardwareBackup(u8g_backup_avr_spi);// assign default color valueif ( u8g.getMode() == U8G_MODE_R3G3B2 ) {u8g.setColorIndex(255); // white}else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {u8g.setColorIndex(3); // max intensity}else if ( u8g.getMode() == U8G_MODE_BW ) {u8g.setColorIndex(1); // pixel on}else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {u8g.setHiColorByRGB(255,255,255);}}void loop() {/*led指示灯闪烁*/while(digitalRead(key_1)==LOW){delay(10);if(digitalRead(key_1)==LOW){KH++;KHS=String(KH);}}while(digitalRead(key_2)==LOW){delay(10);if(digitalRead(key_2)==LOW){KH++;KHS=String(KH);}}digitalWrite(Red_led,HIGH);delay(500);digitalWrite(Red_led,LOW);delay(500);//draw_hello();delay(1200);/*DHT11读取并串口打印显示*/byte temperature = 0;byte humidity = 0;byte humidity_last = 0;int err = SimpleDHTErrSuccess;if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);return;}humidity_last = humidity; //字符串拼接tmp += String("Temperature:");tmp += String(temperature);tmp += String("*C");hmp += String("Humidity: ");hmp += String(humidity);hmp += String("RH%");Serial.print((int)temperature); Serial.print(" *C, ");Serial.print((int)humidity); Serial.println(" H");if(humidity<KH){digitalWrite(relay,LOW);digitalWrite(A0,LOW);Serial.println("Warnning!");}if(humidity>=KH){digitalWrite(A0,HIGH);digitalWrite(relay,HIGH);}/*oled显示屏显示程序*/u8g.firstPage(); do {if(humidity != humidity_last){u8g.drawStr( 0, 16, tmp.c_str());u8g.drawStr( 0, 32, " ");delay(1000);}draw_data();} while( u8g.nextPage() );}