Mobile phone remote control switch device based on esp8266

Hardware preparation: esp8266; c2d3c66d879941eab50a095c910c7a37.png

SG90 servo; e3e63d4d3d6a4a958540abbd5c962aab.png

A microusb data cable (can transmit data);

The above can be purchased on Taobao.

Software preparation: Arduino IDE

Dian Deng Technology (mobile version) https://apps.apple.com/cn/app/Dian Deng-blinker/id1498805902

Servo wiring: brown is the ground wire GND

Red is the power cord

Yellow is the signal line

74ef91c8ecb64bec908d5352c63e5e09.png

GED is connected to the G of the microcontroller

The power cord is connected to the 3V of the microcontroller

The signal line is connected to D4 of the microcontroller

b8d2656dde5540e499b21d10f76ca87b.png

Open Arduino and click on File Preferences

7b6088d45a164a2e8065e9449fec55af.png

Will http://arduino.esp8266.com/stable/package_esp8266com_index.json

Copy to the add-on development manager URL ee5f84579cd54c4baa3069231bfa9d69.png

Click OK

Click Project-Load Library-Manage Library

Search for the microcontroller esp8266 we need to use and install the latest version

Click Tools-Development version and select ESP8266 Board (3.0.1)-Generic ESP8266 Module

30ca7078b10248ca8fd02ead1c590322.png

The code is written by combining some open source projects and adding modifications by yourself. The code link and specific content are as follows. You can download and use it yourself.

Codeicon-default.png?t=N7T8https://share.weiyun.com/ySWJgAi0

#define BLINKER_WIFI
#define BLINKER_MIOT_LIGHT

#include <Blinker.h>
#include <Servo.h>

Servo myservo; //Define servo

char auth[] = "bc6196889229"; //Light up Key
char ssid[] = "GG"; //wifi name
char pswd[] = "7777777105"; //wifi password

//Create a new component object
BlinkerButton Button1("test");


int counter = 0;

void miotPowerState(const String & amp; state)//Power operation
{
    BLINKER_LOG("need set power state: ", state);

    if (state == BLINKER_CMD_ON) {
      
        myservo.write(135);//After receiving the "on" command, the servo rotates 110 degrees
        BlinkerMIOT.powerState("on");
        BlinkerMIOT.print();//Feedback status
        delay(500);//delay 0.5 seconds
        myservo.write(90);//Reset the servo to zero and return to the vertical state
         
        
    }
    else if (state == BLINKER_CMD_OFF) {
      
         myservo.write(45); //The steering gear deflects 70°
         BlinkerMIOT.powerState("off");
         BlinkerMIOT.print();
         delay(500);
         myservo.write(90);
         
      
    }
}

// This function will be executed when the button is pressed
void button1_callback(const String & amp; state)
{
    BLINKER_LOG("get button state: ", state);
    if (state=="on")
    {
        myservo.write(150);//After receiving the "on" command, the servo rotates 150
        delay(500);//delay
        myservo.write(90);//Reset the servo to zero vertically
         
        
    } else if(state=="press"||state=="tap")
    {
       myservo.write(30);//Long press the switch button and the servo rotates 30
       delay(500);//delay
       myservo.write(90);//Reset the servo to zero vertically
    }
        
}

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

void setup()
{
    //Initialize serial port
    Serial.begin(115200);
    BLINKER_DEBUG.stream(Serial);
    //Initialize the servo
    myservo.attach(2); //The IO port of the servo, the D4 port of nodemcu
    myservo.write(90);//The servo returns to zero and vertical when powered on
  BlinkerMIOT.attachPowerState(miotPowerState);
  
    //Initialize blinker
    Blinker.begin(auth, ssid, pswd);
    Blinker.attachData(dataRead);

    Button1.attach(button1_callback);
}

void loop() {
    Blinker.run();
}

Autumn:
http://arduino.esp8266.com/stable/package_esp8266com_index.json

Download Dian Deng Technology APP

1. Select the independent device 0d07cce29a6e484787a77477781f7059.png

2. Copy the generated key. Use fd076e1449204ce28723a7388ac80ff6.png in the code.

3. Return to the device and click the three dots in the upper right corner d84bd296d6b842b09b26e33754493a31.png

4. Select the interface configuration 1799c4719e62418fa4a4ad587ad68a85.png

5. Copy the following content into the box and click Update Configuration

{¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨dark¨¨background¨{¨img¨¨assets/img/headerbg.jpg¨¨isFull¨?}}¨dashboard¨|{¨type¨¨btn¨ ¨ico¨¨fad fa-lightbulb-on¨¨mode¨ê¨t0¨¨turn on the light¨¨t1¨¨text2¨¨bg¨é¨cols¨í¨rows¨í¨key¨¨test¨′x′ ?′y′ì¨speech¨|÷¨cus¨¨on¨¨lstyle¨?¨clr¨¨#595959¨}{?A?B?C¨fad fa-lightbulb¨?Eé?F¨Turn off the lights¨? H?I?Jé?Kí?Lí?M?N′x′?′y′D?O|÷?RS?T}{?A¨deb¨?Eé?Jé?KLì?M ¨debug¨′x′é′y′¤D}÷¨actions¨||¨cmd¨|¨switch¨?¨text¨Q¨open?name¨¨off¨¨off?name¨-÷¨triggers ¨ | .png” src=”//i2.wp.com/img-blog.csdnimg.cn/97b9aaa9b3a9414f82b30a2c1a56e10e.png”>

Open Arduino and import the shared code

af128b148fbd49589dca509a3af050e5.png

Replace the copied key into the first line of quotes

Replace the second and third lines with the name and password of your mobile hotspot

Then click compile6cf67f4f16be4c3ea8e71d58fe845b4c.png

The following situation indicates that the compilation is successful and the code has no errors bba53cf6131b4da5b5042eb29f3fa038.png

Finally, burn the program into the microcontroller ad671bcc72094ebeab958d2846eb698f.png

Note: When burning the program to the microcontroller, the servo cannot be connected to the microcontroller, otherwise the programming will not be successful.

Note: Select the 2.4GHz frequency band instead of the 5GHz frequency band for the mobile hotspot AP band, otherwise the ESP8266 will not be able to connect to the mobile hotspot network.

The method demonstrated in this article is more suitable for students who just want to learn about the Internet of Things. If you want to learn more about it, it is recommended to start with the use of C language and Arduino, as well as the mechanism and pin usage of IoT microcontrollers such as ESP8266 and ESP32. Nowadays, there are many mature electronic modules on the market for us to use, which greatly reduces our learning costs. We can also use MiSiQi or Arduino graphical programming to complete our projects, further reducing the tedious time of entering codes.

Finally

I only regard the Internet of Things microcontroller as an interest and will not study it in depth. I only use this blog to record my learning, and also provide my own experience for students who want to understand the Internet of Things. I hope every electronics enthusiast can walk on the road of love.