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

Universal Maker Sensor Kit

You can also buy them separately from the links below.

Component Introduction

Purchase Link

ESP32 & Development Board (ESP32 Board)

BUY

Breadboard

BUY

Infrared Speed Sensor Module

BUY

Wiring

../_images/Lesson_07_Speed_esp32_bb.png

Code

Code Analysis

  1. 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;
    
  2. 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);
    }
    
  3. 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");
      }
    }
    
  4. 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.

    ../_images/Lesson_07_Encoder_Disk.png