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.
After wiring, we can start programming.
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.
All Projects
- ARDUBLOCK Graphical Programming Starter Kit Tutorial
- ARDUBLOCK Project 1: LED Blinking
- ARDUBLOCK Project 2: PWM Regulating Light Brightness
- ARDUBLOCK Project 3: Flowing Light
- ARDUBLOCK Project 4: Button-controlled LED
- ARDUBLOCK Project 5: Passive Buzzer Sound Production
- ARDUBLOCK Project 6: Active Buzzer Sound Production
- ARDUBLOCK Project 7: Reading-out Analog Value
- ARDUBLOCK Project 8: Light-controlled Sound
- ARDUBLOCK Project 9: Sound-controlled Light
- ARDUBLOCK Project 10: Servo Motor Control
- ARDUBLOCK Project 11:Ultrasonic Distance Measurement
- ARDUBLOCK Project 12:PS2 Joystick Module
- ARDUBLOCK Project 13: LM35 Temperature Sensor
- ARDUBLOCK Project 14: 5V Relay Module
- ARDUBLOCK Project 15: Tilting Switch Module
- ARDUBLOCK Project 16: Capacitive Touch Module Control LED
- ARDUBLOCK Project 17: Flame Alarm Module
- ARDUBLOCK Project 18: Reed Switch Module
- ARDUBLOCK Project 19: Human Body IR Pyroelectricity
- ARDUBLOCK Project 20: Line Tracking Sensor
- ARDUBLOCK Project 21: MQ-2 Combustible Gas and Smoke Sensor
- ARDUBLOCK Project 22: Soil Module
Buy it >> ARDUBLOCK Graphical Programming Starter Kit for Arduino