Build a Tachometer with an IR Sensor and an Arduino
Build Your Own Tachometer with an IR Sensor and an Arduino
Have you ever wanted to build a digital tachometer using an IR sensor and an Arduino microcontroller? If so, it’s not as hard as you might think. With the right components and a little know-how, anyone can create a basic and dependable tachometer with an infrared sensor, an Arduino, and a few other electronic components.
What is a Digital Tachometer?
A digital tachometer is an electronic device used to measure the speed of an object, usually in revolutions per minute (rpm). Tachometers are used in a variety of applications, from automotive engines and electrical motors to industrial machine tools and turbines. Digital tachometers are also used to monitor speed in science experiments, aeronautical engineering, and more.
Components Needed for Building a Tachometer
The components required for building a basic tachometer with an IR sensor and an Arduino include:
- Arduino board such as the Uno
- IR sensor
- LED diode
- Resistor
- Breadboard and connecting wires
Step-By-Step Guide For Building a Tachometer
Once you’ve gathered all the necessary components, the first step to building a tachometer with an IR sensor and an Arduino is to connect the IR sensor to the Arduino board. The connections should be made as follows:
- Connect the 5V pin on the Arduino board to the +5V pin on the breadboard.
- Connect the GND pin on the Arduino board to the - row of the breadboard.
- Attach the LED diode to the breadboard, connecting one side to the + row and the other to the - row.
- Connect the resistor to the + row of the breadboard and the other end to the anode of the LED diode.
- Connect one side of the IR sensor to the + row and the other to the - row of the breadboard.
- Connect one side of the IR sensor to the digital pin of the Arduino board and the other to the + row of the breadboard.
- Load the code onto the Arduino board using an IDE like the Arduino IDE.
Now that the components are connected and the code is loaded onto the board, you’re ready to build the tachometer. You can find detailed instructions on how to build the tachometer online. Once you’ve built your tachometer, you can use it to measure the speed of objects like spinning motors, vehicles, and more!
Here is the source code for the tachometer:
// IR Sensor Tachometer
// Written by ChatGPT
// Pin definitions
const int irSensorPin = 2; // IR sensor connected to digital pin 2
const int ledPin = 13; // LED connected to digital pin 13
const int lcdRS = 7; // LCD display RS pin
const int lcdEN = 8; // LCD display EN pin
const int lcdD4 = 9; // LCD display D4 pin
const int lcdD5 = 10; // LCD display D5 pin
const int lcdD6 = 11; // LCD display D6 pin
const int lcdD7 = 12; // LCD display D7 pin
// Variables
int rpm = 0; // revolutions per minute
unsigned long timeOld = 0; // old time
unsigned long timeNew = 0; // new time
unsigned long pulseWidth = 0; // pulse width
// LCD display
LiquidCrystal lcd(lcdRS, lcdEN, lcdD4, lcdD5, lcdD6, lcdD7);
void setup() {
pinMode(irSensorPin, INPUT);
pinMode(ledPin, OUTPUT);
lcd.begin(16, 2); // initialize the LCD display
lcd.print("IR Tachometer"); // print a message on the LCD display
}
void loop() {
// Calculate RPM
timeNew = millis();
pulseWidth = pulseIn(irSensorPin, HIGH);
rpm = 60000 / (pulseWidth * 10); // calculate RPM
// Update LCD display
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("RPM: ");
lcd.print(rpm);
// Blink LED
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
// Delay to allow sensor to stabilize
delay(10);
}
In this code, the IR sensor is connected to digital pin 2 and the LED is connected to digital pin 13. The LCD display is connected to pins 7-12.
The setup() function initializes the pins and the LCD display. The loop() function calculates the RPM using the pulseIn() function to measure the pulse width of the IR sensor signal. The RPM is then displayed on the LCD display and the LED blinks to indicate that the code is running.
Note: The calibration factor of the tachometer may need to be adjusted depending on the number of pulses per revolution of the motor being measured.