- arduino uno
- input digital - proximity sensor would this program work to find the rpm of a wheel with a proximity sensor

int sensorpin=1; //sensor at pin 1 long int previoutime=0; int value,count,rp,rpm; long int interval=500; //calculating number of rotates every 500ms

void setup() { Serial.begin(9600); pinMode(sensorpin,INPUT); }

void loop() { value=digitalRead(sensorpin); long int currenttime = millis(); if(value==1) count++; //count gives the number of highs ergo giving number of rotations if((currenttime-previoustime)>interval) //if time elapsed is more than 500ms { if(value==0) //if there are no rotations { count=0; rpm=0; Serial.print(rpm); } rp=count/interval; //rotates per 500ms rpm=rp*120; //rotates per minutes previoustime=currrenttime; Serial.println(rpm); rpm=0; count=0; } delay(10); }