Vaisakh1997shafeequeBoniface
Published © GPL3+

Ultrasonic Rangefinder with Processing

Obstacle distance is measured using ultrasonic sensor and Arduino. The data is processed using Processing and the distance is marked.

AdvancedShowcase (no instructions)24,631
Ultrasonic Rangefinder with Processing

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit diagram

connect the sensor to the arduino board as shown in the picture

Code

Arduino code

Arduino
upload the code into the arduino
#include <Mouse.h>
const int trigpin= 8;
const int echopin= 7;
long duration;
int distance;
void setup()
{
  pinMode(trigpin,OUTPUT);
  pinMode(echopin,INPUT);
  Serial.begin(9600);
 
}
void loop()
{
  digitalWrite(trigpin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigpin,LOW);
  duration=pulseIn(echopin,HIGH);
  distance = duration*0.034/2;
  Serial.println(distance);
}

processing code

Processing
run this code on processing to plot the disatance
import processing.serial.*;  
Serial myPort;  
String data="" ;
PFont  myFont;  
void setup()
{
size(1366,900); // size of processing window
background(0);// setting background color to black
myPort = new Serial(this, "COM3", 9600);
myPort.bufferUntil('\n');
}
void draw()
{
  background(0);
  textAlign(CENTER);
  fill(255);
  text(data,820,400);
  textSize(100);
  fill(#4B5DCE);
  text("              Distance :        cm",450,400);
   noFill();
   stroke(#4B5DCE);
}
void serialEvent(Serial myPort)
{
 
  data=myPort.readStringUntil('\n');
}

Credits

Vaisakh1997

Vaisakh1997

2 projects • 14 followers
shafeeque

shafeeque

0 projects • 5 followers
Boniface

Boniface

0 projects • 4 followers
Thanks to Vaisakh .

Comments