Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
š Ready to explore and create with us? Click [here] and join today!
Lesson 07: Infrared Speed Sensor Moduleļ
In this lesson, youāll learn how to use an ESP32 Development Board with a Speed Sensor Module to detect obstructions. Weāll see how the sensor sends a high signal when thereās an obstruction and a low signal when the path is clear. This project is ideal for those looking to grasp sensor integration and basic input/output operations in a practical setting using the ESP32 platform.
Required Componentsļ
In this project, we need the following components.
Itās definitely convenient to buy a whole kit, hereās the link:
Name |
ITEMS IN THIS KIT |
LINK |
|---|---|---|
Universal Maker Sensor Kit |
94 |
You can also buy them separately from the links below.
Component Introduction |
Purchase Link |
|---|---|
ESP32 & Development Board (ESP32 Board) |
|
Wiringļ
Codeļ
Code Analysisļ
Define the sensor pin
The sensor pin is declared as a constant integer and is assigned pin number 25 of the ESP32.
const int sensorPin = 25;
Setup function
This function initializes the serial communication at 9600 baud rate and sets the sensorPin as an input.
void setup() { Serial.begin(9600); pinMode(sensorPin, INPUT); }
Loop function
The loop function continuously checks the sensor pinās status. If the sensor pin reads HIGH, it prints āObstruction detectedā to the Serial Monitor. If the sensor pin is LOW, it prints āUnobstructedā.
void loop() { if (digitalRead(sensorPin) == HIGH) { Serial.println("Obstruction detected"); } else { Serial.println("Unobstructed"); } }
More
If an encoder is mounted on the motor, the rotational speed of the motor can be calculated by counting the number of times an obstruction passes the sensor within a specific period.