// Target and tach shouldn't be expected to be the same sprintf(buffer, "Target: %d, Tach: %d", fanSpeed, rpm); Serial.println(buffer); // Rest for a second and check again delay(1000); }
CONSTANTS
In the beginning of this sketch I have declared some constant values which I will use later on in my code. As I mentioned previously, it is better to declare these values as constant that way you get the benefit of meaningful names in your code which helps in the overall readability of your sketch along with the ability to change the value as needed later on without trying to find everywhere it is used in your code. The constants in this sketch define which pins are being used as analog and digital input, and which pin is being used for analog out i.e. PWM output. METHOD DECLARATIONS
There are not any additional methods declared for this sketch. SETUP
The setup method is where I will configure my Arduino速 to operate as I need. For this sketch we will ensure that our analog reference voltage is five (5) volts.
void setup() { analogReference(DEFAULT); pinMode(fanTachPin, INPUT); Serial.begin(9600); }
In addition to the analog reference we will also set the fanTachPin as a digital input which is much like we have done before however there will be a slight twist in how we use it. Finally the serial port is started and set for 9600 baud. This will allow us to observe the speed of the fan that is being read. LOOP