SAE BAJA Electrical - Digital Tachometer & DAQ Using ARDUINO!

by techbatman29 in Circuits > Arduino

1618 Views, 3 Favorites, 0 Comments

SAE BAJA Electrical - Digital Tachometer & DAQ Using ARDUINO!

Vechicle.png

Greeting Fella Makers,

I am going to share my experience on developing "Digital Tachometer & DAQ System" using Arduino for my college All Terrain Vehicle (ATV) Team.

Before I move on to the technical aspects, I would like to share you all some basic info about SAE BAJA Competition briefly.

SAE BAJA [ SAE - Society of Automotive Engineers ] is a inter college competition for engineering students all across the world. Students from Mechanical and Electrical Subsystem come together to build a rugged, sturdy, agile and light ATV.

You can check more about the SAE BAJA event and Electrical subsystem scope at the below mentioned YouTube video.

Our team - 25 members [ + Two Faculty members] part of various subsystems[ Design, Powertrain, Brakes, Steering & Electrical].

I am part of Electrical Subsystem [ Team of 5 ]. We had to complete Basic Electrical Requirements such as Brake Light and Kill Switch Installation.

Apart from this basic electrical work, We wanted to help our team members to optimize our car for better performance hence we came up with "Digital Tachometer and CVT Primary and Secondary RPM counter" for BAJA 2020.

​Digital Tachometer - Part 1

InductiveSensor_CloseLook.jpg
LCD_ScreenSetup.jpeg

Tachometer is a device which captures the Rotation per minute (RPM) of a vehicle.

In our project, we captured the RPM of the vehicle by using "NPN Inductive Sensor" to detect the iron nail welded to the driveshaft. Whenever iron nail is in close proximity inductive Sensor responds and Arduino acts as the brain to count the no of rotations and display it in a LCD for our driver.

In order to protect the system we enclosed the Arduino setup in a IP rated box at nose region of our car.

Circuit Diagram & Components Required - Part 1 [ Digital Tachometer]

Capture.PNG

Components:

A: LCD Interface (I2C module [4pin])

B: Switch for Arduino Mega 2560 Power Source

C: NPN Inductive Pickup

D & E: 9V Alkaline Power Source


Code - Part 1

Capture.PNG
/* Include the necessary header files : I2c Header for LCD,LCD Header files" */ 
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

/* Declare the 
 * variable for counting revolutions,storing rpm,interrupt pin attached for NPN Inductive Pickup, variable for time, LCD Header files
*/ 

float rev=0;
int rpm;
int oldtime=0;
int t;
int pin = 2; 

void isr() //interrupt service routine
{
rev++;
}

void setup()
{
lcd.begin();                //initialize LCD
lcd.print("Hello Captain");
delay(1000);
pinMode(pin,INPUT);
digitalWrite(pin,HIGH);
attachInterrupt(0,isr,RISING);  //attaching the interrupt
lcd.clear();
Serial.begin(9600);
}

void loop()
{
delay(1000);
detachInterrupt(0);           //detaches the interrupt
t=millis()-oldtime;         //finds the time 
rpm=((rev/t)*60000);         //calculates rpm
oldtime=millis();             //saves the current time
rev=0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("___TACHOMETER___");
lcd.setCursor(0,1);
lcd.print(rpm);
lcd.print(" RPM");
Serial.println(rpm);
attachInterrupt(0,isr,RISING);

}

/* Note: I take no credit in developing the code completely. I have referred multiple codes and understood the logic. I have tweaked it for our requirement. Thank you */

Code Walkthrough - Part 1

InductiveSensor_CloseLook.jpg

I will briefly explain the logic behind this code.

The NPN Inductive Pickup is used to detect the iron nail and count the revolutions for 2 sec [Convert it for 60 second - RPM] using an Arduino Mega and display it to driver.[ LCD Screen bottleneck refresh rate solved!!!!!]

NPN Inductive Pickup uses Hall Effect Principle to detect the iron nail whenever it is in close contact with it. You can find little more details on NPN Inductive Pickup at online resources and learn about the working of the circuit.

If the iron nail comes in contact, we use a Arduino hardware interrupt (ISR) ( 2 interrupt pin) to count the revolutions and convert it to speed as well.

Thank you.

CVT RPM Using IR Sensor - Part 2

IR_SensorSetup.jpeg

Second part of the project involved capturing the CVT primary and secondary RPM. This data will help our team members to understand more about our vehicle performance and plan the CVT Tuning accordingly.

I will include the code below and also explain about the working of IR for RPM calculation here.

How to use IR sensor for RPM calculation?

IR (Infra Red) is an LED that emits infrared radiations. We calculate the RPM by with the understanding of black body principle. IR sensor emits infrared radiations and black surfaces absorbs completely. So we taped the CVT primary and secondary wheel with black tape and left a small part with sticker(silver) for RPM detection.IR emits and receives and we use it to calculate the RPM.

I have used the code from the below source. It works fine until 600- 800 RPM accurately. Thank you all.

Credit/Source: https://www.hackster.io/TonyScarp/arduino-ir-lathe...

 

// Tachometer_For_Lathe_IR
// Display RPM rate of lathe spindle

// Uses:
// Arduino Nano V 3.0
// OSOYOO IR Infrared Sensor (available on Amazon)
// IM162 LCD Display (similar ones available on Amazon)

// Include the LCD and Timer library code:
#include <TimerOne.h>


// RPM values to track
const int IRSensorPin = 2;  // the number of the IR sensor input pin
const int ledPin = 13;          // the number of the LED pin on Nano
int ledState = HIGH;           // the current state of the output pin

// Note: This program was used at one time with a reed relay, for a bicycle cadence counter,
//       but it works all right with the input from the IR sensor. 
//       If I need to reuse it, all variables are still in place.
int inputState;                          // the current state from the input pin
int lastInputState = LOW;        // the previous InputState from the input pin
long lastDebounceTime = 0;   // the last time the output pin was toggled
long debounceDelay = 0;        // the debounce time; increase if the output flickers
long time;
long endTime;
long startTime;
int RPM = 0;
//int lnCount = 0;        // counter for averaging RPM
//int avgRPM = 0;      // averaging total

//long voltage = 0;           // Value read from the pot
//long outputValue = 0;   // Value output to the PWM (analog out)
//int speedVal = 0;
//long rpm50 = 833333;
//volatile unsigned long cadTime = 0;  // use volatile for shared variables
//long timeC, endTimeC, startTimeC;
//int RPMC = 0;
float lnTime = 0;
//int speakerPin = 10;
//int lowRate;
//int hiRate;
//int potPin = A0;               //Analog in pin 0
//int switchValPin = A1;     //Analog in pin 1

// ---------------------------------------------------------------
void setup(void) 
{
  pinMode(IRSensorPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, ledState);
  
  Serial.begin(9600);
  endTime = 0;
  Timer1.initialize(1000000);  // Set the timer to 60 rpm, 1,000,000 microseconds (1 second)
  Timer1.attachInterrupt(timerIsr);  // Attach the service routine here
}

// ---------------------------------------------------------------
void loop(void) 
{
  time = millis();
  int currentSwitchState = digitalRead(IRSensorPin);

  if (currentSwitchState != lastInputState) {
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (currentSwitchState != inputState) {
      inputState = currentSwitchState;
      if (inputState == LOW) {
        digitalWrite(ledPin, LOW);
        calculateRPM(); // Real RPM from sensor
        ledState = !ledState;
      }
      else {
        digitalWrite(ledPin, HIGH);
      }
    }
  }
  lastInputState = currentSwitchState;
}

// ---------------------------------------------------------------
void calculateRPM() {
  startTime = lastDebounceTime;
  lnTime = startTime - endTime;
  RPM = 60000 / (startTime - endTime);
  endTime = startTime;
}

// --------------------------
// Custom ISR Timer Routine
// Timer set to rpm, see above
// --------------------------
void timerIsr()
{
  // Print RPM every second
  // RPM based on timer
  Serial.println("---------------");
  time = millis() / 1000;
  Serial.print(time);
  Serial.print(" RPM: ");
  Serial.println(RPM);
  RPM = 0;
}

// ---------------------------------------------------------------

Learning & Special Mention - END

SAE BAJA Electrical Subsystem - Part 1(Project 1)

Learning:

I would like to thank my mentor/faculties for giving me this wonderful opportunity to work in this amazing project. I learnt many things and understood the true essence of Engineering and How it feels to build a product as a team.

E-Baja Future!:

Yes, Our Humankind has always strived for better ways of living and definitely we will soon develop a lot more sustainable products for a Greener Planet. As a start, SAE Baja has also started conducting events for Electric ATV from 2019 with lot more opportunity and carbon-free development.

Special Mention:

Electrical Subsystem: Paruchuri Chaithanyasai, Gopikrishnan K, Swetha R and Meriga Varshini

Seniors: Harshavardan(Captain), Nagendran (Vice Captain), Ashwanth and Vamsi and all my fellow team mates

Author: TechBatman (Praveenraj M)


You can find the video about the working for the project at the below YouTube video: [ I have discussed about the future enhancements for the system]