Wemos-based wifi controlled obstacle avoidance car

This is a demo from a long time ago. I will make a record today. After all, it is a learning process.

Preparation materials and brief description

WeMos D1

characteristic

  1. Based on ESP-8266EX

  2. Arduino compatible, use rduino IDE for programming

  3. 11 x I/O pins

  4. 1 x ADC pin (input range 0-3.3V)

  5. Onboard 5V 1A switching power supply (high input voltage 24V)

At work:

Similar to stm32 module development, high integration

The STM32 solution is also more economical and cheaper

The red box is the onboard wireless network card

Support AP (routing), sta (Internet device) mode

Ultrasonic Module

There are usually two ultrasonic components on the ultrasonic sensor module, one for transmitting and one for receiving. There are 4 pins on the circuit board: VCC (positive), Trig (trigger), Echo (response), and GND (ground). Main parameters:
1. Working voltage and current: 5V, 15mA.
2. Sensing distance: 2~400cm.
3. Sensing angle: no more than 15°.
4. The area of ​​the object to be measured should not be less than 50cm2 and should be as flat as possible, with a temperature compensation circuit.
5. Input a high potential of more than 10 microseconds to the trigger pin of the ultrasonic module to emit ultrasonic waves. After the ultrasonic waves are emitted, and before the returned ultrasonic waves are received, the "response" pin presents a high potential. Therefore, the program can convert the distance of the measured object from the duration of the high-potential pulse of the "response" pin.

L9110S DC Motor Driver

L9110S parameters: input voltage 2.5V-12V, output current 800mA, forward and reverse
describe:
L9110 is a two-channel push-pull power amplifier special integrated circuit device designed for controlling and driving motors. It integrates discrete circuits into a single-chip IC, which reduces the cost of peripheral devices and improves the reliability of the whole machine. The chip has two TTL/CMOS compatible level inputs, which have good anti-interference; the two outputs can directly drive the forward and reverse motion of the motor, and it has a large current drive capability, and each channel can pass 800mA of Continuous current, the peak current capability can reach 1.5A; at the same time, it has a low output saturation voltage drop; the built-in clamping diode can release the reverse impulse current of the inductive load, making it suitable for driving relays, DC motors, stepper motors or The use of switching power tubes is safe and reliable. L9110 is widely used in toy car motor drive, pulse solenoid valve drive, stepper motor drive and switching power tubes and other circuits.
Features:
Low quiescent operating current;
Wide power supply voltage range: 2.5V-12V;
Each channel has 800mA continuous current output capability;
Lower saturation pressure drop;
TTL/CMOS output level compatible, can be directly connected to CPU;
Output built-in clamping diode, suitable for inductive load;
Control and drive are integrated in a monolithic IC;
With pin high voltage protection function;
Working temperature: -20°C-80°C.

In addition, the development environment is Arduino. Compared with keil, Arduino can integrate many development libraries such as serial port, network, sg90, etc.; it includes various hardware development interfaces for rapid development; it comes with serial port debugging tools, but the disadvantage is that the program compilation speed is slow.

Operation process

First, let's look at the hardware connections.

Ultrasonic sensor:
VCC-wemos 5V
GND-wemos GND
Trig-wemos D8
Echo-wemos D2

L9110S DC Motor:
VCC-wemos 5V,VIN
GND-wemos GND
//rear wheel
A-1B-wemos D7
A-1A-wemos D6
// turn
B-2A-wemos D4
B-1A-wemos D5

Take a look at the code.

#include <ESP8266WiFi.h>
#define Dong1 D7
#define Dong2 D6
#define Zhuan1 D5
#define Zhuan2 D4
#define Echo D2
#define Trig D8

char* ssid = "WiFi account";
char* passwd = "WiFi password";

int port = 8899;//port number, set by yourself
WiFiServer server(port);//Set the server port number

long getTime() {
  digitalWrite(Trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trig, LOW);
  return pulseIn(Echo, HIGH);
}
void initChaoShengBo() {
  pinMode(Echo, INPUT);
  pinMode(Trig, OUTPUT);
}
void initWifiSta() {
  WiFi.mode(WIFI_STA);//Set STA mode
  WiFi.begin(ssid, passwd); //Connect Network
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(200);
  }
  Serial.println(WiFi.localIP());//Print the ip address of wemos through the serial port
  delay(500);
}
void initL9110s() {
  pinMode(Dong1, OUTPUT);
  pinMode(Dong2, OUTPUT);
  pinMode(Zhuan1, OUTPUT);
  pinMode(Zhuan2, OUTPUT);
}

void zuo() {
  digitalWrite(Zhuan1, HIGH);
  digitalWrite(Zhuan2, LOW);
}
void you() {

    digitalWrite(Zhuan1, LOW);
  digitalWrite(Zhuan2, HIGH);
}
void zheng() {
  digitalWrite(Zhuan1, HIGH);
  digitalWrite(Zhuan2, HIGH);
}


void hou() {
  digitalWrite(Dong1, LOW);
  digitalWrite(Dong2, HIGH);
}
void qian() {
  digitalWrite(Dong1, HIGH);
  digitalWrite(Dong2, LOW);
}
void ting() {
  digitalWrite(Dong1, HIGH);
  digitalWrite(Dong2, HIGH);
}

void setup() {
  initL9110s();
  initChaoShengBo();
  Serial.begin(115200);
  initWifiSta();
  server.begin();//start the server
}
void loop() {
  char cmd;
  //get distance
  long dis;
  int mark = 0;
  WiFiClient client = server.available();//service initialization

  while (client.connected()) { //waiting for client to connect
    while (client.available() > 0) { //data is coming
      cmd = client.read();//read data
      Serial.println(cmd);
      dis = getTime() / 58;
      if (dis < 15) {
        hou();
        delay(200);
        ting();
        mark = 1;
      } else {
        mark = 0;
      }
      if (mark == 0) {
        switch (cmd) {
          case 'q':
            qian();
            break;
          case 'h':
            hou();
            break;
          case 'z':
            zuo();
            break;
          case 'y':
            you();
            break;
          case 's':
            ting();
            break;
          case 'd':
            zheng();
            break;
        }
      }
    }
  }
}

Save and upload, wait for compilation, and then open serial debugging and network debugging tools.

It is enough to send instructions according to the code. The implementation is relatively simple, and the overall realization of the functions of running according to the instructions, accessing WiFi and car obstacle avoidance.

Tags: stm32 IoT Single-Chip Microcomputer

Posted by satheshf12000 on Sun, 10 Jul 2022 00:57:29 +0530