将NODEMCU与霍尔效应传感器连接以创建转速表

时间:2019-06-07 14:41:20

标签: arduino nodemcu

我想借助霍尔效应传感器从NODEMCU计算旋转对象的RPM。

int sensor = 14; // Hall sensor at D5
volatile byte counts;
unsigned int rpm; //unsigned gives only positive values
unsigned long previoustime;
boolean digitalValue=0;
void count_function()
{ /*The ISR function
Called on Interrupt
Update counts*/
counts++;
}
void setup() {
Serial.begin(9600);
//Intiates Serial communications
attachInterrupt(0, count_function, RISING); //Interrupts are called on      Rise of Input
pinMode(sensor, INPUT); //Sets sensor as input
counts= 0;
rpm = 0;
previoustime = 0; //Initialise the values
}
void loop()
{
delay(1000);//Update RPM every second
digitalValue=digitalRead(sensor);
detachInterrupt(0); //Interrupts are disabled
rpm = 60*1000/(millis() - previoustime)*counts;
previoustime = millis(); //Resets the clock
counts= 0; //Resets the counter
Serial.print("RPM=");
Serial.println(rpm); //Calculated values are displayed
attachInterrupt(0, count_function, RISING); //Counter restarted
}

转速= 0 它总是这样,但是当我在Arduino UNO中尝试时,它显示RPM。 因为我要上传数据,所以我正在使用NODEMCU。

0 个答案:

没有答案