IR light for speed sensor
hi trying use ir light , photo transistor calculate rpms of shaft , therefore speed. keep getting zeros when displaying serial monitor. i not sure if code or have faulty photo transistor. below code using.
#
int ledpin = 13;
int statuspin = 12;
volatile byte rpmcount;
volatile int status;
unsigned int rpm;
unsigned long timeold;
void rpm_fun()
{
rpmcount++;
if (status == low) {
status = high;
} else {
status = low;
}
digitalwrite(statuspin, status);
}
void setup()
{
serial.begin(9600);
attachinterrupt(0, rpm_fun, falling);
pinmode(ledpin, output);
digitalwrite(ledpin, high);
pinmode(statuspin, output);
rpmcount = 0;
rpm = 0;
timeold = 0;
status = low;
}
void loop()
{
delay(500);
detachinterrupt(0);
rpm = 30*1000/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
serial.println(rpm,dec);
attachinterrupt(0, rpm_fun, falling);
}
#
#
int ledpin = 13;
int statuspin = 12;
volatile byte rpmcount;
volatile int status;
unsigned int rpm;
unsigned long timeold;
void rpm_fun()
{
rpmcount++;
if (status == low) {
status = high;
} else {
status = low;
}
digitalwrite(statuspin, status);
}
void setup()
{
serial.begin(9600);
attachinterrupt(0, rpm_fun, falling);
pinmode(ledpin, output);
digitalwrite(ledpin, high);
pinmode(statuspin, output);
rpmcount = 0;
rpm = 0;
timeold = 0;
status = low;
}
void loop()
{
delay(500);
detachinterrupt(0);
rpm = 30*1000/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
serial.println(rpm,dec);
attachinterrupt(0, rpm_fun, falling);
}
#
code: [select]
int ledpin = 13;
int statuspin = 12
const int ledpin = 13;
const int statuspin = 12;
also please put code in hash tags '#'
Arduino Forum > Using Arduino > Programming Questions > IR light for speed sensor
arduino
Comments
Post a Comment