Vibration alarm (vehicle alarm) based on ESP8266 and 51 single chip microcomputer (simple)

Vibration alarm (vehicle alarm) based on ESP8266 and 51 single chip microcomputer


The author is a college student of Guigong communication engineering. When designing the course, he wants to make an alarm that can remind the message on the mobile phone. It has made a breakthrough in the traditional audible and visual alarm, and can push messages to remind users.


The traditional vehicle alarm (vibration alarm) is generally audible and visual alarm. When the vibration module receives the external signal, it will feed back the signal to the single chip microcomputer for audible and visual alarm. We can use ESP8266 to push and alarm messages within a certain range in the LAN. If there is WiFi, we can also use wechat to push messages by combining ESP8266 and IOT platform.

design requirement

1. The vibration sensor vibrates, receives information and sends out alarm sound.
2. The alarm duration can be displayed through the nixie tube and closed for one minute.
3. The alarm duration can be set by pressing the key.
4. When the alarm is triggered, send a message reminder.

hardware circuit

For the design requirements, the first three can be easily completed by using 51 single chip microcomputer, while the fourth requirement can be realized in many ways, and I choose to use ESP8266 for message function development.
Therefore, the circuit can be divided into two parts for design. One is 51 single chip microcomputer circuit, and the other is to add ESP8266 module later.

51 circuit

(Note: Header 3H in the figure is the access hole of vibration module; Header 4 is the hole reserved for ESP8266.)

The following is a simple analysis of each module;

Crystal oscillator module
For the crystal oscillator module, we use the 11.0592MHZ crystal oscillator. There is a high gain reverse amplifier in 89C51, which is used to form an on-chip oscillator and pin
XTAL1 and XTAL2 are the input and output of the amplifier respectively.
The two ports are connected with crystal or ceramic resonators, which constitutes a self-excited oscillator, and the pulses sent by it are directly sent to the internal clock generator.
When the external crystal oscillator is connected, the two capacitors usually choose 30PF, which can stabilize the frequency and fine tune the oscillation frequency
The range is 0~24MHZ.
In order to reduce parasitic capacitance and better ensure the stable and reliable operation of the oscillator, the resonator and capacitor should be installed close to the single chip microcomputer chip as far as possible.

Key module
For the key module, my assumption is that there are four keys, one is the reset key, and the other three are the function keys.
For the reset key, the reset pin is active at high level, so the other end of the switch should be connected to VCC.
For the remaining three function keys: one minute alarm mode key, two minute alarm mode key and disarm key, the other end of the key is connected to GND, which has a certain relationship with the default high level of our STC89C51 chip pin.

Nixie tube display module
The triode is mainly responsible for voltage stabilization and amplification. According to the wiring, we use port P0 to control the chip selection of the nixie tube and port P2 to control the bit selection of the nixie tube. For the bit selection port, we use the triode to amplify the bit selection current, and there is enough current to control the bit selection enable end of the driving nixie tube. The position and number displayed can be controlled through port P0 and P2.

PCB design

With the prototype of the circuit, the design of PCB is easy, and the single-layer board can directly meet the requirements.

The wiring shall be as simple as possible to avoid electromagnetic interference. The signal is not a high-speed signal. There is no need to pay too much attention to the line. Just reserve the row needle at the reserved hole.

Access to ESP8266

The TXD and RXD ports of ESP8266 and the TXD and RXD ports of MCU shall be connected correctly. The power port and GND port of ESP8266 shall be reserved on the PCB of MCU.

Code design

The coding of 51 single chip microcomputer can be said to be very simple.
(the alarm duration of the buzzer can be set with a variety of alarm durations, or a countdown display can be designed to enrich the functionality and sense of design.)

The following are some codes:

void delay(uint z)//Delay Functions 
uint i,j;
void time0init()//timer initiated 
TH0=0xFC ;
void beep(uint m, uint k) //Modify the parameters to change the buzzer tone
uchar i = 0;
uint j = 0;
for(j = m;j > 0;j --)
for(i = 0;i <= 50; i++)
Beep=~Beep ;//Pay attention to the driving mode of the buzzer

For the code writing of ESP8266, I have two ideas.

As mentioned above, one is based on LAN, which is relatively simple, and the other is based on IOT platform.
When the vibration module gives an alarm, the TXD and RXD ports of the single chip microcomputer will play a role and transmit data to ESP8266. After receiving the data, the program of ESP8266 will start to work, which has a certain relationship with the writing method of the program.
I choose to lead out a pin directly to the vibration module and directly receive the high-level signal from the vibration module. In this way, even if the part of the single chip microcomputer cannot work due to some problem, the message push alarm can be realized.
The following are some codes:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>

const char* ssid = "D"; //WiFi name
const char* password = "12345678"; //WiFi password

// Start a TCP Server on port 5045
WiFiServer server(5045); //Port 5045, custom (avoid public port)
WiFiClient client;

char data[1500];
int ind = 5;

void setup() {
  //Wait for connection
  while(WiFi.status() != WL_CONNECTED) { //Check WiFi connection status
  Serial.print("Connected to "); Serial.println(ssid);
  Serial.print("IP Address: "); Serial.println(WiFi.localIP()); //The serial port monitor displays the IP address

  // Start the TCP server

void loop() {
    // put your main code here, to run repeatedly:
    //try to connect to a new client
    client = server.available();
    if(digitalRead(D0)){for(int j=0;j < ind; j++){client.print("call the police!");}}


Note: in the above code, ESP8266 plays the role of TCPsever, while the mobile phone can play the role of client to receive the information transmitted through the serial port.

Networked push
We have all realized LAN alarm. Why not directly study the first-hand online message push reminder( Anyway, there are not a few Internet of things platforms that can whore for nothing.)
The following is part of the code, which can realize the function.

//              WIFI reconnection function
void startSTA(){

//              WIFI status detection function, which automatically reconnects if WIFI is disconnected
void doWiFiTick(){
    if ( WiFi.status() != WL_CONNECTED ) {
        //Not connected 1s reconnection
        if (millis() - lastWiFiCheckTick > 1000) {
          lastWiFiCheckTick = millis();
 void doHttpStick(){  //Wechat message push function
      if (WiFi.status() == WL_CONNECTED) { //Check whether WIFI is connected
          HTTPClient http;  //Initialize http
          http.begin(ApiUrl+"?uid="+uid+"&title="+title+"&msg="+msg);  //Initialization request
          int httpCode = http.GET();                                  //Send request
          if (httpCode > 0) { // Check status code
            String payload = http.getString();   //Get response information
            Serial.println(payload);             //Print response information
          http.end();   //Turn off http

Physical welding

Tags: C IoT

Posted on Sun, 05 Sep 2021 02:30:37 -0400 by 2paulm