0% found this document useful (0 votes)
11 views2 pages

RPM 2

Uploaded by

omareldahry03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

RPM 2

Uploaded by

omareldahry03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

// Constants

const int sensorPin = 2; // IR sensor connected to digital pin 2

// Variables

volatile int rpmCount = 0;

unsigned long startTime;

volatile boolean rpmFlag = false;

// Interrupt service routine for counting RPM

void rpmIncrement() {

rpmCount++;

void setup() {

// Attach interrupt to the IR sensor pin

attachInterrupt(digitalPinToInterrupt(sensorPin), rpmIncrement, RISING);

// Start time

startTime = millis();

// Initialize the serial communication

Serial.begin(9600);

void loop() {

// Calculate RPM every second


if (millis() - startTime >= 1000) {

detachInterrupt(digitalPinToInterrupt(sensorPin));

// Calculate RPM value

float rpm = (rpmCount / 2.0) * 60.0;

// Print RPM value to the serial monitor

Serial.print("RPM: ");

Serial.println(rpm);

// Reset variables

rpmCount = 0;

startTime = millis();

attachInterrupt(digitalPinToInterrupt(sensorPin), rpmIncrement, RISING);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy