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!

2.2.6 Speed Sensor Module

Introduction

In this project, we will learn the use of the speed sensor module. A Speed sensor module is a type of tachometer that is used to measure the speed of a rotating object like a motor.

Required Components

In this project, we need the following components.

../_images/2.2.6component.png

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

Raphael Kit

337

Raphael Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

GPIO Extension Board

BUY

Breadboard

BUY

Jumper Wires

BUY

Resistor

BUY

LED

BUY

Speed Sensor Module

-

Schematic Diagram

../_images/2.2.6circuit.png

Experimental Procedures

Step 1: Build the circuit.

../_images/2.2.6fritzing.png

Step 2: Go to the folder of the code.

cd ~/raphael-kit/nodejs/

Step 3: Run the code.

sudo node speed_sensor_module.js

After the code runs, the green LED will light up. If you place an obstacle in the gap of the speed sensor module, the “light blocked” will be printed on the screen and the red LED will be lit. Remove the obstacle and the green LED will light up again.

Code

const Gpio = require('pigpio').Gpio;

const Rpin = new Gpio(22, { mode: Gpio.OUTPUT });
const Gpin = new Gpio(27, { mode: Gpio.OUTPUT });

const speedPin = new Gpio(17, {
    mode: Gpio.INPUT,
    pullUpDown: Gpio.PUD_DOWN,
    edge: Gpio.EITHER_EDGE
});

speedPin.on('interrupt', (level) => {
    if (level) {
        console.log("Light was blocked");
    }
    Rpin.digitalWrite(level);
    Gpin.digitalWrite(!level);
});

process.on('SIGINT', function () {
    Rpin.digitalWrite(0);
    Gpin.digitalWrite(0);
    process.exit();
});

Code Explanation

The code of this example is almost the same as 2.1.5 Tilt Switch, so no need to repeat it.

Phenomenon Picture

../_images/2.2.6photo_interrrupter.JPG