Мне нужно собрать установку для измерения скорости вращения колеса, я нашел статью посвященную данной теме: http://academicfox.com/arduino-datchyk-holla-yzmerenye-skorosty-vraschenyya/ Собрал все по инструкции :Подключение датчика Холла в Arduino приведено на рисунке 1 (S (данные) -> pin 2, GND -> Arduino GND, VCC -> Arduino + 5V, резистор 1 кОм). Но когда запускаешь программу и подносишь магнит к Датчику Холла, не идет сигнал с данных и таблицу рисует лишь одни нули. В чем может быть проблема? В теме написано что Пин 2 это данные, но в самом коде я не увидел чтобы задавался сам Пин2. Вот сама программа: // read RPM volatile int rpmcount = 0;//see http://arduino.cc/en/Reference/Volatile int rpm = 0; unsigned long lastmillis = 0; void setup(){ Serial.begin(9600); attachInterrupt(0, rpm_fan, FALLING);//interrupt cero (0) is on pin two(2). } void loop(){ if (millis() - lastmillis == 1000){ /*Uptade every one second, this will be equal to reading frecuency (Hz).*/ detachInterrupt(0); //Disable interrupt when calculating rpm = rpmcount * 60; /* Convert frecuency to RPM, note: this works for one interruption per full rotation. For two interrups per full rotation use rpmcount * 30.*/ Serial.print("RPM =\t"); //print the word "RPM" and tab. Serial.print(rpm); // print the rpm value. Serial.print("\t Hz=\t"); //print the word "Hz". Serial.println(rpmcount); /*print revolutions per second or Hz. And print new line or enter.*/ rpmcount = 0; // Restart the RPM counter lastmillis = millis(); // Uptade lasmillis attachInterrupt(0, rpm_fan, FALLING); //enable interrupt } } void rpm_fan(){ /* this code will be executed every time the interrupt 0 (pin2) gets low.*/ rpmcount++; }
Код паршивый и более-менее точно считает только на высоких оборотах, не меньше 500 в минуту. Вручную нужно изо всех сил махать магнитом, чтобы хоть что-то появилось.