FREE SHIPPING OVER $89; 10% OFF FOR YOUR FIRST ORDER (CODE:NEW10);



ARDUBLOCK Project 11:Ultrasonic Distance Measurement

Posted by Fiona Su on

Introduction:
In this project, we use graphical programming to measure the distance between ultrasonic module and front obstacle and display it on serial monitor.
Materials Required:

  • 1. KEYESTUDIO UNO Control Board *1
  • 2. V5 Sensor Shield*1
  • 3. Ultrasonic Module*1
  • 4. Female to Female Dupont Line*4

Connection Diagram:
Let’s start experiment, and connect ultrasonic waves to ARDUINO referring to the following figure.

thumb

thumb

thumb

After wiring, we can start programming.

thumb

Click “download to Arduino” to see the following codes in ARDUINO programming interface:
Sample Code:

*****************************************************************************
int _ABVAR_1_t1 = 0 ;
int ardublockUltrasonicSensorCodeAutoGeneratedReturnCM(int trigPin, int echoPin)
{
  long duration;
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(20);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  duration = duration / 59;
  if ((duration < 2) || (duration > 300)) return false;
  return duration;
}

void setup()
{
  digitalWrite( 4 , LOW );

  Serial.begin(9600);
}

void loop()
{
  _ABVAR_1_t1 = 	ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 4 , 5 ) ;
  Serial.print("diatance:");
  Serial.print(_ABVAR_1_t1);
  Serial.println();
  delay( 200 );
}
*******************************************************************************

Result:
We can see the distance value measured by ultrasonic in the serial monitor of ARDUINO after downloading the program.

thumb 

All Projects

Buy it >> ARDUBLOCK Graphical Programming Starter Kit for Arduino

0 comments

Leave a comment

Please note, comments must be approved before they are published