张小哥

[Training Camp_Advanced Class] Smart IoT power meter based on ESP-07 - with night light

 
Overview
Directory order: (it may be a bit long, so you can skip it)

Picture (I can’t say anything, the picture above!

hardware

  1. Introduction(Features)
  2. Original parts selection
  3. Design Notes
software
  1. Introduction
  2. Program code description

problems at hand

Demo/Tutorial Video

-------------------------------------------------segmentation Wire-----------------------------------------------

picture

image.pngimage.pngimage.png

hardware

Introduction

This project’s ESP-07-based smart IoT power meter with night light has the following features:

feature illustrate
oled display Current voltage, power, power consumption, temperature and humidity can be printed on the OLED screen
Isolated current and voltage collection It is safer than non-isolated sampling
touch control It's tiring to press the buttons with your hands, so I added touch (fog
voice control Can be connected to smart speakers such as Xiaoai (can be used on mobile phones), Xiaodu, Tmall, etc.
PCB size Controlled within approximately 61x64mm, it can be easily inserted into the 86 cassette
Integrated socket No need to connect additional output lines, output directly through the onboard socket
ESP07 side welding It solves the area occupation problem of the ESP module very well, and also solves the problem of the signal being blocked by copper coating.
WS2812 night light You can set a variety of light effects, such as cold white, warm white, and the most important thing is RGB to increase performance by 100% (fog
TypeC interface Commonly used with most mobile phone data cables today, no need to look for additional wires
WS2812 indicator light Different colors for different power displays can be set in the firmware, and the indicator light automatically turns off when the night light is turned on.
Screen turns off automatically Wake up the screen by touching the switch (the OLED survival time can be set in the firmware)
Temperature and humidity sensor Can collect temperature and humidity data at home and send it to the server, and view charts in the app

Original parts selection

type name illustrate
WIFI module ESP-07 It occupies a small area, has sufficient io, and comes with a ceramic antenna, and the signal is stronger than a PCB antenna.
Voltage and current sampling chip HLW8032 Only one pin is needed to communicate with the microcontroller, and the circuit is simple
relay HK4100F-DC5V-SHG Although the current is only 3a, 600w is enough for use. The important thing is that it is small!
Temperature and humidity sensor SHTC3 Using i2c communication method, it can be connected in parallel with OLED, reducing IO usage
and the chip is super small! The circuit is super simple!
Indicator light/night light WS2812B-3535 Multiple colors can be set, and only a single IO is needed to set the light effects of multiple LEDs.
touch chip SD8223LC Has self-calibration function and can set different working modes through resistors
Serial chip ch340c There is no need for an external crystal oscillator and it is small in size. Why is it not suitable for other smaller e or n?
Because the ESP’s automatic placement needs to use the dtr and rts pins at the same time.

Design Notes



image.png

↑ Current flow and circuit overview

The circuit is divided into 2 parts: strong current and weak current

The strong current part mainly includes: power input, acdc module, current and voltage acquisition circuit, relay and power output socket

The weak current part mainly includes: ESP minimum system circuit, automatic drop circuit, reset circuit, and 5 peripheral circuits



From the picture above, you can see that the entire PCB is clearly divided into two parts, strong and weak (except LED, because it needs to be present in all four corners)

The smallest circuit in the picture is the SHTC3 temperature and humidity sensor circuit. It is really smaller than the LED circuit!

This is the welding diagram of ESP07

image.png

This solves the problem of the ESP module occupying a large area, and also solves the problem of signals being blocked by copper coating/tracing.

image.pngimage.png

There are no components near the temperature sensor to reduce measurement errors caused by heat generated by other components.

image.png

There is a 0.1uf electric dragon next to each WS2812 to filter and protect the lamp beads.

image.png

The power module used is only 2x3x3cm, which is very small and has a 3,3v output. There is no need to install a 5v to 3,3v step-down circuit on the PCB.

image.png

The touch circuit uses SD8223LC, which has a self-calibration function and can set different working modes through resistors, and can be connected to a copper-clad small board through pad wiring to extend the operating distance.

Copper-clad small board↓ (5 holes are for convenience of soldering

image.png


software

Introduction

The program uses Arduino for programming, and the main libraries used are:

Library illustrate
Blinker The core library of the program, Blinker, is a set of cross-hardware and cross-platform IoT solutions that
are very easy to use and support a variety of devices.
Fastled Library for controlling WS2812
HLW8032 HLW8032 fuel gauge chip library
SparkFun_SHTC3 SparkFun SHTC3 Temperature and Humidity Sensor Library
OneButton A simple key library that implements multiple operations by binding callback functions: single click, double click, long press, etc. It is
very convenient and you don’t have to write your own judgment formulas.
Adafruit_SSD1306 Adafruit’s OLED library
Adafruit_GFX Adafruit's graphics library, similar to u8g/u8g2
font   The 10px and 14px font libraries created using  http://oleddisplay.squix.ch/#/home
are used for oled display, because the Adafruit GFX library comes with too few font libraries.

Program Overview

Rows illustrate
5-15 library definition
17-19 Define WIFI SSID password and Blinker key
20-68 Various parameter definitions
70-92 Bind oled screen, HLW8032, SHTC3, blinker component, OneButton component
94-107 Various constant definitions
109-150 Custom icon (oled display)
153-361 Various definitions of blinker, please see the program for details
363-386 onebutton's callback function
394-443 setup function
445-454 loop function
456-480 Update app icon and update sensor data
497-501 buzzer
503-512 indicator light
514-526 night light timer
528-530 Convert bool to string
532-542 Screen automatically sleeps
544-608 screen display

For more details, please see the program comments (my hands hurt typing the comments)

problems at hand

1. Two people are in Hong Kong and the other is in Qingdao, spanning half of China. It is extremely difficult to debug and complete the work.

2. When I printed the board for the first time, I don’t know why the printed board was not filled with copper. I finally prototyped the second board. Fortunately, the course was delayed.

3. The CAD software cannot be opened on the computer to draw the dxf file of the shell. LCEDA can only be used as CAD.

4. The wrong buzzer was selected, and the passive one was selected. Finally, the solution was solved by changing the digitalWrite() → tone() function, and the selected one was only 65db, which has a smaller sound. In addition, the buzzer was connected on the first generation board. For gpio2, I forgot that gpio2 has an onboard LED, so the buzzer will always sound. Although you can stop the buzzer from sounding by pulling the pin high, the function of the LED will be lost. The second generation board will use the buzzer Received gpio13 solution

5. During debugging, the relay always maintained a high level, and there was no response when clicking the switch. Finally, the solution was solved by adding pinMode to the setup function to define the relay pin as an output (I have almost never used pinMode).

6. The SHTC3 temperature and humidity sensor could not read the data, and then I found that I forgot to add the Wire.begin() function.

7. HLW8032 cannot read data. It is initially suspected that it conflicts with the onboard ch340 and cannot read data from the serial port. The tester has not gotten up yet, and the solution is pending (-1 hour left before handing in the homework)

8. WS2812 does not light up. There is no problem with the program. In the end, it was found that it was a welding problem. The first lamp bead was damaged. But at this time, I found that 4 lamp beads were needed, but I only bought 5. The lamp beads on the board It was broken after being dismantled, and only one lamp bead was left............. This story teaches us to buy more spare parts when buying parts.

Cjpg

image.png

Fang Fang doesn’t get up, no photos or videos, md

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2024-11-15 01:54:59

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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号