Musicmanager
Well-Known Member
Hi Guys
Do we have a resident Arduino genius ?
I'm busy installing a CNC milling machine in my workshop at the moment .. .. a cheap chinese version that has provision for spindle speed control but it is not connected and there is some development work to do before I can attempt to achieve that.
As an interim measure I found a Tachometer circuit on the net which uses an Arduino Uno, a IR reflective sensor and an LCD panel to measure and display spindle speed .. .. great ! I thought.
I built the circuit and used my function generator to test it and it seems to work OK, so I got the Arduino Uno out, copied the program file but I can't get it to upload .. ..It compiles OK, but upload hangs after a few seconds and then I get a message 'Problem uploading to the board'
Here's the code .. ..
I haven't done anything harduino before, and right now I'm concentrating on CNC stuff .. .. .. Why use harduino ? simply because I had one in the cupboard doing nothing ........mind you, it still is ! Doing nothing I mean
Simple question ... .. can anybody see a glaring error ??
Thanks
S
Do we have a resident Arduino genius ?
I'm busy installing a CNC milling machine in my workshop at the moment .. .. a cheap chinese version that has provision for spindle speed control but it is not connected and there is some development work to do before I can attempt to achieve that.
As an interim measure I found a Tachometer circuit on the net which uses an Arduino Uno, a IR reflective sensor and an LCD panel to measure and display spindle speed .. .. great ! I thought.
I built the circuit and used my function generator to test it and it seems to work OK, so I got the Arduino Uno out, copied the program file but I can't get it to upload .. ..It compiles OK, but upload hangs after a few seconds and then I get a message 'Problem uploading to the board'
Here's the code .. ..
C:
/*
* Optical Tachometer
*
* Uses an IR LED and IR phototransistor to implement an optical tachometer.
* The IR LED is connected to pin 13 and ran continually.
* Pin 2 (interrupt 0) is connected across the IR detector.
*
* Code based on: [URL='https://www.instructables.com/id/Arduino�Based�Optical�Tachometer/']www.instructables.com/id/Arduino�Based�Optical�Tachometer/[/URL]
* Coded by: arduinoprojects101.com
*/
int ledPin = 13; // IR LED connected to digital pin 13
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void rpm_fun()
{
//Each rotation, this interrupt function is run twice, so take that into consideration for
//calculating RPM
//Update count
rpmcount++;
}
void setup()
{
lcd.begin(16, 2); // intialise the LCD
//Interrupt 0 is digital pin 2, so that is where the IR detector is connected
//Triggers on FALLING (change from HIGH to LOW)
attachInterrupt(0, rpm_fun, FALLING);
//Turn on IR LED
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
rpmcount = 0;
rpm = 0;
timeold = 0;
}
void loop()
{
//Update RPM every second
delay(1000);
//Don't process interrupts during calculations
detachInterrupt(0);
//Note that this would be 60*1000/(millis() � timeold)*rpmcount if the interrupt
//happened once per revolution instead of twice. Other multiples could be used
//for multi�bladed propellers or fans
//rpm = 30*1000/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
//Print out result to lcd
lcd.clear();
lcd.print("RPM=");
lcd.print(rpm);
//Restart the interrupt processing
attachInterrupt(0, rpm_fun, FALLING);
}
I haven't done anything harduino before, and right now I'm concentrating on CNC stuff .. .. .. Why use harduino ? simply because I had one in the cupboard doing nothing ........mind you, it still is ! Doing nothing I mean
Simple question ... .. can anybody see a glaring error ??
Thanks
S
Last edited by a moderator: