EasyManuals Logo

Freenove ESP32 User Manual

Default Icon
159 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #111 background imageLoading...
Page #111 background image
Need support? support@freenove.com
109
Chapter 10 Ultrasonic Ranging
www.freenove.com
The following is the code:
1
2
3
4
5
6
7
8
9
10
11
12
#include "UltrasonicRanging.h"
void setup() {
Serial.begin(115200);
setupSonar();
}
void loop() {
float dist = getSonar();
Serial.printf("dist: %.2fcm\r\n", dist);
delay(500);
}
Initialize the pins of the ultrasonic module.
6
setupSonar();
Get the data value of the ultrasonic module, the unit is cm.
13
float dist = getSonar();
UltrasonicRanging.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef _ULTRASONICRANGING_h
#define _ULTRASONICRANGING_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define PIN_TRIG 32 //Ultrasonic trig pin
#define PIN_ECHO 12 //Ultrasonic echo pin
void setupSonar();
float getSonar();
#endif

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove ESP32 and is the answer not in the manual?

Freenove ESP32 Specifications

General IconGeneral
BrandFreenove
ModelESP32
CategoryComputer Hardware
LanguageEnglish

Related product manuals