RPM à base d’Arduino

RPM à base d’Arduino

Petit montage pour le fun

Matériel:

  • 1 Arduino
  • 1 LCD
  • 1 Un récepteur Hall
  • 1 Aimant

Voici le code en rouge:

/*
* Compte tours
* Coded by: Dontown Swiss
*/
int ledPin = 13;
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void rpm_fun()
{
rpmcount++;
}
void setup()
{
Serial.begin(19200);
lcd.begin(16, 2); // intialise the LCD
attachInterrupt(0, rpm_fun, FALLING);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
rpmcount = 0;
rpm = 0;
timeold = 0;
}
void loop()
{
delay(750);
detachInterrupt(0);
rpm = 21*1000/(millis() – timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
lcd.clear();
lcd.print(“RPM=”);
lcd.print(rpm);
Serial.println(rpm);
//Restart the interrupt processing
attachInterrupt(0, rpm_fun, FALLING);
}

Voici le résultat.

Poster le commentaire