念慈菴

[Training Camp_Advanced Class] Internet Socket

 
Overview

Use a microcontroller and EMW3080 or esp8266 to implement a socket that can be controlled by an app.

2020 Lichuang EDA Summer Advanced Class. For the project, refer to the Zero Demon Project ; for the online documentation, refer to Yuque: Socket-Requirements Analysis based on Alibaba Cloud Intelligence .

1: Project requirements

Design a board that can control home lights through a mobile phone APP

  • Hardware: USB power supply, WIFI control, relay (with load within 100W)
  • Embedded: Respond to the instructions of the WIFI module to perform corresponding actions and control the WIFI module to enter the corresponding state.
  • Mobile APP: Different users can configure the network, control the relay status, read the relay status, and manage multiple devices.
  • Server: Can link to WIFI module and mobile phone, can maintain user information, and is not easy to crash

Two: Scheme design

  • Cloud: Using the Alibaba Cloud IoT platform , you can control devices through the Cloud Smart APP and Tmall Genie.
  • Wifi module: Choose EMW3080 as the WIFI module. The communication module has been officially certified by Alibaba Cloud and is safe and reliable. Directly connect to the Alibaba Cloud platform through AT commands. When using, refresh the firmware to Alibaba Cloud Feiyan firmware.
  • Main control chip: Select 51 microcontroller, model STC15W4K56S4-LQFP48. Universal chips are easy to use. (In fact, it is to be consistent with the tutorial and reduce unnecessary trouble)
  • Download circuit: CH340E is used to convert USB to TTL level. You can download the program to the microcontroller and communicate with the 3080 through AT commands during the debugging process.
  • Microcontroller reset: STC's microcontroller needs to be powered off to complete the reset. Use an LDO with an enable pin and a button to achieve the purpose. The LDO model is ME6215C33M5G, which can stabilize the 5V voltage to 3.3V and power the STC15W.
  • Relay: Choose a 5V driven relay. Because the board uses a 5V power supply via USB.
  • Relay drive circuit: Select the dedicated chip NUD3105LT1G. At the same time, because the microcontroller defaults to high level when powered on, an inverter SN74LVC1G04DBVR is added before the control signal to ensure that the default signal of the relay is low level and closed when powered on.

Three: Business logic

  1. Power on. Read triplet information in Flash.
  2. Send the triplet information to the WIF module through the AT command sending interface.
  3. Open the ILOP service of the WIFI module through the AT command sending interface.
  4. Enter the cyclic task and start executing all related subroutines regularly.
    1. If the AT command receives the "open relay" string, it controls the IO port.
    2. If the AT command receives the "close relay" string, it controls the IO port
    3. If the button is scanned and long pressed, the WIFI module will enter the network configuration mode through the AT command sending interface, and the LED will start to flash simultaneously.
    4. If the AT command receives the string "Connect to server successfully", the LED will be controlled to flash individually.
    5. If the AT command reaches the string "disconnect server", the control LED will turn off.
    6. Watchdog feeds the dog regularly

Four: Notes on PCB drawing

  1. Do not lay copper on the strong current parts, and pay attention to the safe distance between strong current and strong current, and between strong current and weak current (try to 3mm, consider trenching if it is lower than 2mm, but the PCB strength issue must be considered);
  2. It is recommended to use terminals for external 220V relays. It is not recommended to use pin holes. The diameter of the wire from the relay to the terminal should be thick;
  3. Place the terminal blocks and microUSB on the edge of the board, otherwise it will be difficult to wire them. You can use 3D preview;
  4. Some students’ buttons are too close to the high voltage, and the button is in the middle of the board, making it difficult to press;
  5. The power supply must first filter the capacitor and then go to the microcontroller/WiFi module;
  6. WIFI will generate heat when working properly, so please pay attention to the heat dissipation design;
  7. A clear area is required below the WIFI antenna, and slotting is best;
  8. If there is a plastic mold, you should pay attention to the size of the mold space when selecting components.

Five: Project results

  1. 3D model of PCB
3D.png
  1. Physical PCB
Actual picture.jpg
  1. APP interface
app.jpg
  1. Implemented functions
    1. When the device is powered on, the buzzer will sound twice to prompt. After connecting to the network, the blue light turns on.
    2. The device reports current device information to the cloud every 5 minutes: the status of the relay and the current remaining working time.
    3. The relay can be controlled on and off through the APP.
    4. Press the button on the device to reverse the relay status and report the device information once
    5. Click and hold the button, and the buzzer will sound the corresponding button sound.
    6. Set the remaining working time on the APP. After the device receives it, it will start counting down on the device. When the time is up, the relay will reverse. The countdown can be set up to 24 hours. When the time is set to 0 or greater than 24 hours, no countdown is performed, and the countdown is turned off by default.
    7. You can set a cloud timer, similar to an alarm clock. Set the relay to turn on or off at a certain time of the day. After setting up, make sure the APP is running in the background.

Six: Project summary

  1. After the EMW3080 refreshed the firmware, the serial port used AT commands to communicate, and the baud rate was set to 115200. The communication failed and was garbled   . When the firmware was refreshed, the BOOT was grounded through the jumper cap, and I forgot to unplug it after the firmware was refreshed, causing the communication with the serial port assistant to fail. When EMW3080 is working normally, BOOT is not connected to GND.
  2. The Alibaba Cloud platform is set up, and the EMW3080 is controlled directly using AT commands through the serial port assistant. However, the EMW3080 cannot be scanned through the cloud smart APP. The EMW3080   initially used the network distribution method 2. When scanning on the mobile APP, peripheral devices cannot be scanned, and the reason has not been found. Modify to network distribution mode 1,. Scan the distribution network QR code directly through the APP to connect successfully.
  3. There is no problem with the program. After downloading it, the communication between the serial port 1 of the microcontroller STC15W and the serial port assistant has been garbled, and the baud rate is wrong   . When downloading the program, STC-SPI requires the IRC frequency when the program is running to be 22.1184Mhz. As shown below:
image.png
  1. The buzzer does not sound.   The driving capability of port P52 is too weak, so a pull-up resistor is added.
  2. The data of DS18B20 has always been wrong. It is a random number (not solved, please help me).    The variable FloatTemperature is not initialized, resulting in a random value. Due to unknown reasons, the judgment if (DS18B20_RAM[8] == DS18B20_RAM[9]) has never been made, and the Read_T1() function directly returns a random value. Initialize the FloatTemperature to 0 and directly turn off the if(DS18B20_RAM[8] == DS18B20_RAM[9]) judgment. The finally returned temperatures are always about 66 and 133, and the problem is not found. If you have any solution ideas, please leave them in the comment area. Thank you very much. 
1.jpg
  1. The public version of the APP edited on the Life Internet of Things platform has a secondary interface, but it cannot be drawn out on the mobile phone (unsolved)
image.png
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-23 08:50:15
  • F2812 programming problem
  • Smile, ten years younger
  • DC/DC 24V to 5V
  • [GD32E503 Review] Part 3: Screen Code Analysis
  • PIC microcontroller key recognition program
  • How capacitive isolation solves key challenges in AC motor drives

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号