walid abdelazeem
Published © MIT

How to Make a Radar with WeMos D1 Mini ESP32 and Ultrasonic

This project shows how to make a simple radar system using HC-SR04 sensor and Wemos esp32 with processing and Arduino IDEs.

BeginnerFull instructions provided3 hours1,035
How to Make a Radar with WeMos D1 Mini ESP32 and Ultrasonic

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Processing
The Processing Foundation Processing

Story

Read more

Schematics

Radar with WeMos D1 Mini ESP32 and Ultrasonic

Code

Radar with WeMos D1 Mini ESP32 and Ultrasonic

Arduino
#include <ESP32Servo.h>
Servo myservo;  // create servo object to control a servo
const int trigPin = 5;
const int echoPin = 18;
// Variables for the duration and the distance
long duration;
int distance;
int pos = 0; // variable to store the servo position
int incomingByte = 0; for incoming serial data
void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);  // Sets the trigPin as an Output
 pinMode(echoPin, INPUT);   // Sets the echoPin as an Input
  //myservo.attach(13);  // attaches the servo on pin 13 to the servo object
  myservo.attach(13);
  myservo.write(90);
}
void loop() {
 for(int i=15;i<=165;i++){  
  myservo.write(i);
  delay(30);
  distance = calculateDistance();// Calls a function for calculating the distance measured by the Ultrasonic sensor for each degree
  Serial.print(i); // Sends the current degree into the Serial Port
 Serial.print(","); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
  Serial.print(distance); // Sends the distance value into the Serial Port
 Serial.print("."); // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
  }
  // Repeats the previous lines from 165 to 15 degrees
  for(int i=165;i>15;i--){  
  myservo.write(i);
  delay(30);
  distance = calculateDistance();
  Serial.print(i);
  Serial.print(",");
  Serial.print(distance);
  Serial.print(".");
  }
  int calculateDistance(){

 

  digitalWrite(trigPin, LOW);

  delayMicroseconds(2);

  // Sets the trigPin on HIGH state for 10 micro seconds

  digitalWrite(trigPin, HIGH);

  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds

  distance= duration*0.034/2;

  return distance;

}

Credits

walid abdelazeem

walid abdelazeem

6 projects • 6 followers

Comments