Internet of things series ④ - humidifier design based on ESP8266 and lighting technology platform (access to Xiaoai classmate)


1, Design objectives

  1. Use the lighting technology platform to access the Internet of things, and you can control the switch of the humidifier through the mobile lighting APP
  2. Connect Xiaoai and control the switch of humidifier through voice
  3. Download the module through the external TTL serial port to burn the ESP8266 program, manually pull down the GPIO0 level through the jumper cap, and manually RST
  4. LM1117 5V to 3V design is used for power supply, and Mico USB and DC 5.5*2.5mm interface can be selected for 5V power supply
  5. The pins are of universal design, which is convenient for peripheral expansion
  6. The LED indicator indicates the operation status of the system

2, Circuit design

It is optimized on the basis of the circuit of the previous version. In order to save costs, the CH340 download circuit is removed, the board is sprayed with black paint to improve the sense of science and technology, and the output pin adopts the general pin design of the general peripheral module to improve the universality of the circuit board.


The three circuit boards are grounded and fixed through a copper column, and power is supplied between the boards through a black 5V power line to form a tower structure, with a sense of science and technology in the appearance. Different layers of circuit boards perform different functions. The first layer is lighting technology + Xiaoai to control the humidifier switch, which is connected to the distant humidifier module through the row of pins. The second layer is lighting technology + Xiaoai control WS2812B light belt, which will be introduced in the next article. The third layer is ESP8266 as a network server, which is described in Internet of things series ① - network server based on ESP8266 One article has an introduction. Interested partners can go and have a look!

3, Train of thought introduction

About the humidifier module, I bought it at a price of about 10 yuan from a certain treasure. The module itself is powered by USB and switched on and off through the button of the module itself. Therefore, if we want to control its switch through ESP8266, we need to transform the module. The simplest way is to replace the keys on the humidifier module through the GPIO port to remotely control the switch of the humidifier module, and connect the 5V power line and ground wire from the circuit board to the power supply end of the humidifier module to realize the power supply of the humidifier from the Internet of things circuit board. After testing, the control mechanism of the humidifier module is that after the key input pin detects the low level, it can be recognized as a switch only when the high level is detected. Which pin is the key input pin can be known by measuring the key pin of the humidifier with a multimeter. It's much easier to understand this mechanism. We connect the D1 of ESP8266 to the key input pin of the humidifier module. D1 defaults to the output high level. We first lower the D1 level, delay it for a period of time, and then raise the level. At this time, we will find that the humidifier is turned on. Similarly, this method can also turn off the humidifier module when it is turned on. Therefore, in order to prevent the humidifier in the original on state from being turned off by mistake or the humidifier in the original off state from being turned on by mistake, it is necessary to judge the current operation state of the humidifier, otherwise a bug will occur. Interested partners can buy the humidifier module and try to transform it with my solution.

4, ESP8266 code

#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#define BLINKER_MIOT_OUTLET

#include <Blinker.h>

char auth[] = "*********";//Equipment number
char ssid[] = "*********";//Wireless account
char pswd[] = "*********";//Wifi password

// New component object
BlinkerButton Button1("HUM_Button");


int count = 0;//Humidifier counter
int count1 = 0;//led flip counter
int HUM_OPEN=0;//Humidifier flag
int HUM_State=0;//Humidifier switch status flag bit, 0 off, 1 on
#define HUM_Button D1
#define LED1 16
#define LED2 14

// Pressing the key will execute the function
void button1_callback(const String & state) {
    BLINKER_LOG("get button state: ", state);
    digitalWrite(LED2, !digitalRead(LED2));
    HUM_OPEN=1;//Flag bit on
    if(digitalRead(LED2)==0)
    {
      Button1.print("off");
     }
     else
     {
       Button1.print("on");
      }
}

// If an unbound component is triggered, its contents will be executed
void dataRead(const String & data)
{
    BLINKER_LOG("Blinker readString: ", data);

}
//Xiaoai classmate processing function
void miotPowerState(const String & state)
{
    BLINKER_LOG("need set power state: ", state);

    if (state == BLINKER_CMD_ON) {
        BlinkerMIOT.powerState("on");
        BlinkerMIOT.print();

        if(HUM_State==0)//On in off state
        {
          digitalWrite(LED2, HIGH);
          HUM_OPEN=1;
          HUM_State=1;//open
        }
    }
    else if (state == BLINKER_CMD_OFF) {
        BlinkerMIOT.powerState("off");
        BlinkerMIOT.print();
        if(HUM_State==1)//On or off
        {
          digitalWrite(LED2, LOW);
          HUM_OPEN=1;
          HUM_State=0;//close
        }
    }
}

void setup() {
    // Initialize serial port
    Serial.begin(115200);

    #if defined(BLINKER_PRINT)
        BLINKER_DEBUG.stream(BLINKER_PRINT);
    #endif

    // Initialize IO with LED
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, HIGH);
    pinMode(LED1, OUTPUT);
    digitalWrite(LED1, HIGH);
    pinMode(LED2, OUTPUT);
    digitalWrite(LED2, LOW);
    //Initialize humidifier pin
    pinMode(HUM_Button, OUTPUT);
    digitalWrite(HUM_Button, HIGH);//Power on and off
    // Initialize blinker
    Blinker.begin(auth, ssid, pswd);
    Blinker.attachData(dataRead);
    Button1.attach(button1_callback);//Key
    //Xiaoai callback function
    BlinkerMIOT.attachPowerState(miotPowerState);
}

void loop() {
    Blinker.run();
    count1++;//led flip counter
      if(HUM_OPEN==1)
      {
         digitalWrite(HUM_Button, LOW);
         count++;
         if(count==30)
         {
            digitalWrite(HUM_Button, HIGH);
            count=0;
            HUM_OPEN=0;
         }
      }
    if(count1==100)
    {
       digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
       digitalWrite(LED1, !digitalRead(LED1));
       count1=0;
    }
}


I hope you guys will give me some advice on your shortcomings!

Tags: Embedded system IoT Single-Chip Microcomputer

Posted by CRichardson on Mon, 18 Apr 2022 06:06:31 +0930