/* |
|
This sketch allows an Arduino to act as a speedometer. Data input can come from |
magnets glued to the rim or spoke of a wheel along with a hall-effect sensor or |
reed switch. You can also use an optical sensor using the spokes to break the |
beam of light. |
|
(If you use a reed switch instead of a hall-effect sensor, you will probably |
need to modify the sketch to include some debouncing. If you use an optical |
sensor, you might need Schmitt trigger circuitry.) |
|
The sketch times how long it takes in milliseconds between pulses from the |
sensor, and converts it into feet per minute. It is written for a bandsaw with |
16-inch wheels, and six magnets evenly spaced on one of the wheels. |
|
The data is written to an LCD with Hitachi HD44780 compatible chipsets using the |
LiquidCrystal library. |
|
For more information about LiquidCrystal, visit |
https://www.arduino.cc/en/Reference/LiquidCrystal |
|
|
The circuit: |
* LCD RS pin to digital pin 12 |
* LCD Enable pin to digital pin 11 |
* LCD D4 pin to digital pin 5 |
* LCD D5 pin to digital pin 4 |
* LCD D6 pin to digital pin 3 |
* LCD D7 pin to digital pin 2 |
* LCD R/W pin to ground |
* LCD VSS pin to ground |
* LCD VCC pin to 5V |
* 10K resistor: |
* ends to +5V and ground |
* wiper to LCD VO pin (pin 3) |
|
Library originally added 18 Apr 2008 |
by David A. Mellis |
library modified 5 Jul 2009 |
by Limor Fried (http://ladyada.net) |
example added 9 Jul 2009 |
by Tom Igoe |
modified 22 Nov 2010 |
by Tom Igoe |
modified 7 Nov 2016 |
by Arturo Guadalupi |
|
modified 21 Aug 2018 from LiquidCrystal Hello World sketch by Emily Velasco |
|
This example code is in the public domain. |
|
*/ |
|
// Include the library code: |
#include |
|
// Initialize the library by associating any needed LCD interface pin with the |
// arduino pin number it is connected to |
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; |
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); |
|
// Unsigned long is necessary for these variables because they hold millisecond |
// values, which add up quickly as the program runs, and would overflow as int |
// variables |
unsigned long TimerCount; |
unsigned long previousTimerCount; |
unsigned long LCDUpdateTime; |
|
int sensorPin = 8; |
int pinState = LOW; |
int oldpinState = LOW; |
int LCDprintValue = 0; |
int sawPulse = 1; |
|
|
void setup() { |
|
pinMode(sensorPin, INPUT); |
|
// Gives TimerCount a millisecond value to start with. millis() is the current |
// time in milliseconds since the Arduino booted up |
TimerCount = millis(); |
|
// Gives previousTimerCount a millisecond value to start with |
previousTimerCount = millis(); |
|
// Set up the LCD's number of columns and rows. Change this to match your LCD |
// dimensions |
lcd.begin(20, 4);// |
lcd.print("Feet per minute:"); |
|
} |
|
void loop() { |
|
pinState = digitalRead(sensorPin); |
|
// Checks to see if the sensor is reading high and if that's |
// different than the last time it checked. if both are true, it |
//means a pulse from the sensor is being received |
if (pinState == HIGH && pinState != oldpinState){ |
|
// Records the time in milliseconds so we know when the pulse was |
// received |
TimerCount = millis(); |
|
// Subtracts the time the last pulse was received from the time the newest |
// pulse was receieved to determine the milliseconds between each pulse. |
// Fewer milliseconds between pulses mean the wheel is turning faster. The |
// constant, 41887.8, is derived from a series of calculations that turn |
// milliseconds between pulses into revolutions per minute, and then |
// revolutions per minute into feet per minute. This constant depends on how |
// many pulses per rotation the wheel sensor generates, and the diameter of |
// the wheel. In this case, I have six pulses per rotation, and 16-inch |
// wheels. |
|
// mpp = milliseconds per pulse = TimerCount - previousTimerCount |
// circumference of band saw wheel = 16 inch diameter * Pi |
// cif = circumference in feet = (16 * Pi)/12 |
// |
// 1 pulse 60000 ms 1 rev cif 41887.8 |
// ------- X -------- X ------- X ----- = ------- = feet per minute |
// mpp ms 1 min 6 pulse 1 rev mpb |
LCDprintValue = (((unsigned long)41887.8)/(TimerCount - previousTimerCount)); |
|
// Sets a flag that we can use to tell if the speed has dropped |
// to zero |
sawPulse = 1; |
|
// Sets previousTimerCount to whatever value was recorded for |
// TimerCount before math was calculated |
previousTimerCount = TimerCount; |
|
} |
|
// Checks to see if LCDUpdateTime is less than current time in |
// milliseconds. this is so the LCD only updates once a second |
if (LCDUpdateTime <= millis()){ |
|
// Places the cursor in the first column on the second row of the |
// LCD |
lcd.setCursor(0, 1); |
|
// Checks to see if sawPulse was set to 1 by the first if |
// statement. if it has been, it means a pulse was detected |
// within the last second and the wheel is still turning |
if (sawPulse == 1){ |
|
// Prints the speed value calculated above to the LCD |
lcd.print(LCDprintValue); |
|
// Prints spaces to clear the line now in preparation for the |
// next speed value to be displayed |
lcd.print(" "); |
|
// Resets sawPulse to zero in preparation for the else statement |
// below |
sawPulse = 0; |
} |
|
// If sawPulse is anything besides 1, it means the program has |
// not detected a new pulse within the last second, and it can |
// be assumed speed has dropped to zero |
else { |
|
lcd.print("0"); //Prints zero for the speed |
|
// Prints spaces to clear the line now in preparation for the |
// next speed value to be displayed |
lcd.print(" "); |
} |
|
// Checks the time, adds 1000 milliseconds (1 second) to it, and |
// records it. this value is compared against the time in |
// milliseconds above to see if a second has elapsed. |
LCDUpdateTime = (millis()+1000); |
|
} |
|
|
// Sets oldpinState to the last measured state from the sensor so it can be |
// used to see if that state has changed next time the loop runs |
oldpinState = pinState; |
|
} |
22 Comments
3 years ago
Useful and thorough. Well done.
Question 3 years ago on Step 2
Nice job! You should do an Instructable on the conversion of your bandsaw to a DC Treadmill motor. :)
Answer 3 years ago
Actually a 3 phase motor with VFD is probably cheaper and much more robust. You can get VFDs from less than $100 US to several thousands of dollars US depending upon current capacity.
Reply 3 years ago
Nice idea but I only have 2 phase.
Reply 3 years ago
You can get VFDs that run off of 110V or 220V single phase for the smaller motors, 2 hp or so. We only have single phase in our area. We have a rotary 3 phase convert that runs the mills, and a 3 phase 220 volt VFD for the 2 hp lathe speed control that runs off of the rotary phase converter and a 110V 3 phase converter for the 1 hp lathe. The 220V input VFD will run off of 220V single phase and will run up to a 4 hp motor.
Reply 3 years ago
More robust, perhaps. Cheaper, not at all. I got three treadmills for free. Free motor. Free motor control board. All I needed to make it work on my saw was an enclosure for the controller, a toggle switch, a pushbutton, and a potentiometer. It was probably $20 worth of parts.
Answer 3 years ago
That's not a bad idea. I have spare treadmill motors, and one spare treadmill motor controller sitting in my garage. Maybe I could do a conversion of another one of my tools and document it
Reply 3 years ago
I've got an old Craftsman band saw from probably the 1950's with a massive 3/4 HP motor on it. It would be great to make it variable speed. :)
Reply 3 years ago
Start looking on craigslist in your area for free treadmills. They're not too hard to find because people buy them on a whim or for a resolution, and then stop using them, and they take up lots of room. Even when they're broken, the motor is usually still good.
I got three treadmills for free, and between the three of them, I got a really good motor, and a really good control board. Once you have those, the wiring is not too hard.
3 years ago
Nice Job! You might want to try using PWM for dimming the backlight of the LCD, but it might not worth it.
Reply 3 years ago
That's not a bad idea. I have spare IO pins on the arduino, so I could probably use one of them for PWM with a mosfet or something like that
3 years ago
Knowing what your blade speed is is vital. I sometimes work with Nickel and Iron based alloys that need around 45 - 50 FPM with lubricant/coolant with a bi-metal blade. Occasionally I end up on a Sunday evening with nought but a Carbon steel blade and need to drop to around 15 - 20 FPM. Most Woodworkers have no idea just how slow blade speed needs to be for SOME materials, hole saws are the classic example. Good article.
Reply 3 years ago
15-20 is slooooow. I doubt my saw can go that slow without stalling, but I suppose I could get there with the right pulleys
3 years ago
Pretty tricky. Lot of work though . I use the rev counters on ebay at about $10 a piece . Arduinos are great but you have to make a board and solder it or the contacts degrade and muck up the readings. That gets costly so using an ATTiny85 sometimes helps.
I use this . It picks up the magnet passing -just one though. about $10 AUD
https://www.ebay.com.au/itm/Digital-Engine-Tach-Tachometer-Hour-Meter-Inductive-for-Motorcycle-Motor-ATAU/392008527540?_trkparms=aid%3D555018%26algo%3DPL.SIM%26ao%3D1%26asc%3D60048%26meid%3Dc1eb12f64f3f4c948f70885f8f931b83%26pid%3D100005%26rk%3D3%26rkt%3D12%26sd%3D382596542583%26itm%3D392008527540%26pmt%3D1%26noa%3D0%26pg%3D2047675&_trksid=p2047675.c100005.m1851
Reply 3 years ago
The cost was not much. The arduino nano every is less than $10. Perfboard is very cheap. The hall-effect sensors were about a buck apiece. The LCD was salvaged.
Everything is soldered (no headers), so there are no contacts to degrade.
And yeah, it was a bit of work, but that's the fun part.
3 years ago
Neat solution! Well done, and thank you for sharing your work :-)
Reply 3 years ago
You're welcome!
Reply 3 years ago
You're welcome! Thanks for the nice comment.
3 years ago
Thanks so much for documenting the Arduino code the way you have, makes it easy to understand.
Nice job on the treadmill motor band saw too.
Reply 3 years ago
A friend of mine was a software engineer in his past career, so I asked him to do code review. I didn't realize what I was asking for. He went through my code with a fine toothed comb, and made sure I commented everything clearly. Credit goes to him as well!