基于Blinker+18B20+继电器三档温控
可以用于热敷,暖炕,壁挂炉等,自己发挥吧
一定看到结束俩字,如果还不会,那你就别玩了
单单控制系统需要用到的材料:
1,继电器
2,18b20建议带上拉小板
3,关键,ESP01s
4,选件:烧写器不会做的就买
模块插入烧写器,打开软件,选择开发板,和“端口”
有的同学不显示端口,可能你烧写器驱动有问题,找卖家要驱动,我就不提供链接了,再说我发的文件有毒,解释不清
代码
- #include <OneWire.h>
- #include <DallasTemperature.h>
- volatile int item;
- OneWire oneWire_0(0);
- DallasTemperature sensors_0(&oneWire_0);
- DeviceAddress insideThermometer;
- volatile int gear;
- #define BLINKER_WIFI
- #include <Blinker.h>
- char auth[] = "26c18c5e4183";
- char ssid[] = "TP-LINK_123";
- char pswd[] = "12356789";
- float ds18b20_0_getTemp(int w) {
- sensors_0.requestTemperatures();
- if(w==0) {
- return sensors_0.getTempC(insideThermometer);
- }
- else {
- return sensors_0.getTempF(insideThermometer);
- }
- }
- BlinkerButton Button1("k1");
- void Button1_callback(const String & state) {
- if (state == "on") {
- gear = 20;
- }
- }
- BlinkerButton Button2("k2");
- void Button2_callback(const String & state) {
- if (state == "on") {
- gear = 30;
- }
- }
- BlinkerButton Button3("k3");
- void Button3_callback(const String & state) {
- if (state == "on") {
- gear = 40;
- }
- }
- BlinkerButton Button4("k4");
- void Button4_callback(const String & state) {
- if (state == "off") {
- digitalWrite(2,HIGH);
- gear = -200;
- }
- }
- void setup(){
- Blinker.begin(auth,ssid,pswd);
- pinMode(2, OUTPUT);
- item = 0;
- sensors_0.getAddress(insideThermometer, 0);
- sensors_0.setResolution(insideThermometer, 9);
- Serial.begin(115200);
- gear = 0;
- Button1.attach(Button1_callback);
- Button2.attach(Button2_callback);
- Button3.attach(Button3_callback);
- Button4.attach(Button4_callback);
- }
- void loop(){
- Blinker.run();
- if (item < gear) {
- digitalWrite(2,LOW);
- } else if (item > gear) {
- digitalWrite(2,HIGH);
- }
- item = ds18b20_0_getTemp(0);
- Serial.println(item);
- delay(1000);
- }
复制代码 这里需要修改一些东西就是
char auth[] = "26c18c5e4183";这个哪里来等下说
char ssid[] = "TP-LINK_123";这是我家的WiFi,你改你家的
char pswd[] = "12356789";密码也改,不改连空气啊
"26c18c5e4183";这个哪里来等下说
这个哪儿来?
点击返回设备并打开
点击右上角建立四个按键
传完程序下滑app里的设备刷新,会显示在线!ok
四个按键三个档位K1-20度,K2-30度,K3-40度,k4关闭
打开电脑串口可查看温度变化,不要修改程序,把温度显示到手机上会变慢,
喜欢的就试试吧,有问题留言,我也不一定看,
我的上班啊
!!!
注意!!!程序18B20接的是0,但是你买的继电器模块也是0,能修改的自己修改一下,如果你说你不能修改程序但是你能做继电器,好,给你张图
继电器接2,18b20接0,这样你还能看见esp01s板载LED变化
如果你啥也不会,只能按照我提供你的链接买模块,那你传这个代码,
- #include <OneWire.h>
- #include <DallasTemperature.h>
- volatile int item;
- OneWire oneWire_2(2);
- DallasTemperature sensors_2(&oneWire_2);
- DeviceAddress insideThermometer;
- volatile int gear;
- #define BLINKER_WIFI
- #include <Blinker.h>
- char auth[] = "26c18c5e4183";
- char ssid[] = "TP-LINK_C000";
- char pswd[] = "12356789";
- float ds18b20_2_getTemp(int w) {
- sensors_2.requestTemperatures();
- if(w==0) {
- return sensors_2.getTempC(insideThermometer);
- }
- else {
- return sensors_2.getTempF(insideThermometer);
- }
- }
- BlinkerButton Button1("k1");
- void Button1_callback(const String & state) {
- if (state == "on") {
- gear = 20;
- }
- }
- BlinkerButton Button2("k2");
- void Button2_callback(const String & state) {
- if (state == "on") {
- gear = 30;
- }
- }
- BlinkerButton Button3("k3");
- void Button3_callback(const String & state) {
- if (state == "on") {
- gear = 40;
- }
- }
- BlinkerButton Button4("k4");
- void Button4_callback(const String & state) {
- if (state == "off") {
- digitalWrite(0,HIGH);
- gear = -200;
- }
- }
- void setup(){
- Blinker.begin(auth,ssid,pswd);
- pinMode(0, OUTPUT);
- item = 0;
- sensors_2.getAddress(insideThermometer, 0);
- sensors_2.setResolution(insideThermometer, 9);
- Serial.begin(115200);
- gear = 0;
- Button1.attach(Button1_callback);
- Button2.attach(Button2_callback);
- Button3.attach(Button3_callback);
- Button4.attach(Button4_callback);
- }
- void loop(){
- Blinker.run();
- if (item < gear) {
- digitalWrite(0,LOW);
- } else if (item > gear) {
- digitalWrite(0,HIGH);
- }
- item = ds18b20_2_getTemp(0);
- Serial.println(item);
- delay(1000);
- }
复制代码 我也不知道该咋详细了,
补充:库下载
https://share.weiyun.com/5CGEKJO如果你的开发板里看不见8266,下这个!
结束!!
|