Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

// Compute the RPM of a simple DC Motor using a photomicrosensor(PMS)

#include <LiquidCrystal.h>
#define PMS_PIN 2 // Pin for signal from Photomicrosensor
#define LED_PIN 13 //Using Arduino's Internal LED; just as an indicator
boolean counted=false;
int t1=0,t2=0;
int hits=0;
int rps=0;
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
void setup(){
pinMode(PMS_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
lcd.begin(16, 2);
}
void loop(){
t2 = millis();
if(t2 >= (t1 + 1000)){
rps = hits;
hits = 0;
t1=t2;
lcd.clear();
lcd.print("RPM: ");
lcd.print(rps*60);
}
if(digitalRead(PMS_PIN) == HIGH){
if(!counted){
counted = true;
hits++;
}
} else {
counted = false;
}
digitalWrite(LED_PIN, digitalRead(PMS_PIN));
}

You might also like