Project in progress
Arduino Frequency Counter with 16×2 LCD Display

Arduino Frequency Counter with 16×2 LCD Display © Apache-2.0

Recently, a friend of mine had an issue with his car’s ECU and needed a frequency counting device.

  • 24,465 views
  • 7 comments
  • 23 respects

Components and supplies

About this project

Recently, a friend of mine had an issue with his car’s ECU and needed a frequency counting device. The solution was a device to determine the pulse frequency emitted by the ECU against the rev counter. So, the device had to have the ability to read digital pulses, between 1V – 5V, which are then interpreted by a digital pin on the Arduino as HIGH and LOW pulses. Then outputs the frequency in Hz/kHz on the LCD display.

Hardware

  • 1x Arduino Uno
  • 1x 16×2 LCD SPI (not the I2C)
  • 3x jumper wires

The Setup

I had bought a 16×2 LCD and never actually done anything with it, so it was about time.

The LCD was in the form of a shield compatible with Arduino Uno. I snapped the LCD onto the Arduino and attached a jumper wire to analog pin A5. I am still using digital input in my code but since almost all digital pins were taken by the LCD I’ve decided to utilize an analog pin. Now, the device can be powered via the USB port, the jack pin or the VIN. I am using the VIN here as I had no jack available and I was using the car’s supply (roughly 12V-14V).

Circuit

If using the LCD shield you can skip this part, but if you don’t have a shield here are the connections that are needed.

  • LCD ———-Arduino
  • RS ———– 12
  • Enable ——11
  • D4 ———– 5
  • D5 ———– 4
  • D6 ———– 3
  • D7 ———– 2
  • R/W ——— GND
  • VSS ———- GND
  • VCC ———- +5V

Add 10Kohm resistor between +v5 and GND. Plug in the +12V of the battery in Arduino VIN pin and GND of the battery to Arduino GND. Finally the A1 pin jumper wire to the source of the frequency to be measured.

NOTE: In my case both the ECU and the Arduino had their GND connected (at the GND Terminal of the battery).

The Sketch

The sketch is fairly simple. We will display 3 values on screen. The current frequency, the max frequency and the min frequency, updating every second. The min and max are reset every 5 minutes. We are using the LiquidCrystal.h which is included in the Arduino IDE installation, so you don’t need to add anything.

Limitations

We tested the device using another Arduino (which probably it’s not the best thing to do) and found that up to 50kHz the device had an error of around +/- 3% so it’s actually pretty good. Beyond 50kHz, the error started to rise and became very inaccurate. So our suggestion is to use it only for frequencies under 50kHz.

Code

codeArduino
/*
 * The MIT License (MIT)
 * 
 * Copyright (c) 2016 RuntimeProjects
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

long microSecs;
long freq;
int lastBit;
int nowVal;
long secs;
long maxHz;
long minHz;
long minmax;
void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Loading...");
  pinMode(A1,INPUT);
  pinMode(A5,OUTPUT);
  microSecs = micros();
  freq = 0;
  lastBit = 0;
  nowVal =0;
  maxHz=0;
  minHz=0;
  minmax=0;
  secs = millis();
  //Serial.begin(9600);
}
int x=0;
void loop() {


  if ((microSecs+20)<micros()){
      nowVal=digitalRead(A1);
 
      if (lastBit!=nowVal) {
        lastBit=nowVal;
        freq=freq+1;
      }
      if (freq>maxHz){
        maxHz=freq;
      }
      if (freq<minHz){
        minHz=freq;
      }
      //lcd.clear();
      //lcd.print();
      microSecs = micros();
  }
  if (secs+1000<millis()){

    if (minmax+300000<millis())
    {
      minmax=millis();
      minHz=freq;
      maxHz=freq;
      
    }
      
      lcd.clear();
      lcd.print((freq/2));
      lcd.print("hz");
      lcd.setCursor(0,1);
      lcd.print("+: ");
      lcd.print(maxHz);
      lcd.print(" -: ");
      lcd.print(minHz);
      
      freq=0;
      secs=millis();
      
  }

}

Comments

Similar projects you might like

DHT11 Humidity + Temperature Sensor with 16x2 LCD display

Project showcase by onatto22

  • 22,120 views
  • 6 comments
  • 40 respects

Simple Ultrasonic Distance Measurer With LCD Display

Project showcase by onatto22

  • 10,829 views
  • 4 comments
  • 31 respects

Displaying Sensor Values on LCD

by Wimpie van den Berg

  • 64,860 views
  • 6 comments
  • 46 respects

Fidget Spinner RPM Counter

by Andriy Baranov

  • 51,785 views
  • 30 comments
  • 114 respects

Ultrasonic Sensor with LCD Display Using 433MHz

Project tutorial by mcharrison500

  • 9,223 views
  • 1 comment
  • 24 respects
Add projectSign up / Login