Tuesday, May 8, 2018

An Arduino Small Engine Tachometer


I've been casting about for an Arduino sketch for a tachometer that I could adapt to small engines. The most promising one I've found so far is this one from "https://playground.arduino.cc/Learning/Tachometer". Here's the complete code if you'd rather not follow the link.

- - -

//
// This example shows one way of creating an optoswitch
// using an IR LED as emiter and an IR LED receiver as
// light sensor.
// On this case it acts as a tachometer to count the
// revolutions per second of an aeromodelism plane's
// propeller.
//
//           + GROUND                    +GROUND         
//           |                                        | 
//           <                                        <
//           > 220 ohm resistor             > 220 omh resistor
//           <                                        <     
//           |                                        | 
//           |                                        |
//         -----                                    -----
//          / \    >>IR LED emiter >>  / \   IR LED receiver
//         -----                                    -----
//           |                                        |
//           |                                        |
//           + +5VCD                        +  ANALOG INPUT 0
//


int val;
long last=0;
int stat=LOW;
int stat2;
int contar=0;

int sens=75;  // this value indicates the limit reading between dark and light,
              // it has to be tested as it may change acording on the
              // distance the leds are placed.
int nPalas=2; // the number of blades of the propeller

int milisegundos=500; // the time it takes each reading
void setup()
{
  Serial.begin(9600);
  pinMode(13,OUTPUT);
}

void loop()
{
  val=analogRead(0);
  if(val<sens)
    stat=LOW;
   else
    stat=HIGH;
   digitalWrite(13,stat); //as iR light is invisible for us, the led on pin 13
                          //indicate the state of the circuit.

   if(stat2!=stat){  //counts when the state change, thats from (dark to light) or
                     //from (light to dark), remmember that IR light is invisible for us.
     contar++;
     stat2=stat;
   }
   if(millis()-last>=milisegundos){
     double rps=((double)contar/nPalas)/2.0*1000.0/milisegundos;
     double rpm=((double)contar/nPalas)/2.0*60000.0/(milisegundos);
     Serial.print((contar/2.0));Serial.print("  RPS ");Serial.print(rps);
     Serial.print(" RPM");Serial.print(rpm);Serial.print("  VAL ");Serial.println(val);
     contar=0;
     last=millis();
   }
}

- - -

The sketch was evidently developed by a Spanish speaker for timing a model airplane propeller. Several things needed changing for my purposes:
  • I wanted a digital, not an analogue, input.
  • The tachometer needed to 'see' one event per revolution.
  • I wanted an LCD output in addition to the serial output.
After some tinkering, I came up with this:

- - -

#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int val;
long last=0;
int stat=LOW;
int stat2;
int contar=0;

//int sens=75;
int sens=500;// this value indicates the limit reading between dark and light,
//int sens=200;              // it has to be tested as it may change acording on the
              // distance the leds are placed.
int nPalas=1; // the number of blades of the propeller

int milisegundos=1000; // the time it takes each reading
void setup()
{
  Serial.begin(9600);
  pinMode(6,INPUT);
  pinMode(13,OUTPUT);
}

void loop()
{
  //val=analogRead(0);
  val=digitalRead(6);
  //if(val<sens)
  if(val==0)
  stat=LOW;
  else
   stat=HIGH;
   digitalWrite(13,stat); //as iR light is invisible for us, the led on pin 13
                          //indicate the state of the circuit.

  if(stat2!=stat){  //counts when the state change, thats from (dark to light) or
                     //from (light to dark), remmember that IR light is invisible for us.
     contar++;
   stat2=stat;
   }
   if(millis()-last>=milisegundos){
     int rps=(contar/nPalas)/2.0*1000.0/milisegundos;
     int rpm=(contar/nPalas)/2.0*60000.0/(milisegundos);
     Serial.print((contar/2.0));Serial.print("  RPS ");Serial.print(rps);
     Serial.print(" RPM");Serial.print(rpm);Serial.print("  VAL ");Serial.println(val);
     //lcd.clear();
     lcd.begin(16,2);
     lcd.print("RPS or Hz=");
     lcd.print(rps);
     lcd.setCursor(0,1);
     lcd.print("RPM=");
     lcd.print(rpm);
     contar=0;
     last=millis();
   }

}

- - -

'Tinkering' is the operative word. I'm pretty clueless where Arduino code is concerned. An expert would no doubt find plenty wrong with what I've done, but it appears to work. It got me to where I could experiment with spark plug wire pickups, and come up with a working small engine tachometer.

- - -

Getting A Signal Off A Spark Plug Wire -- THURSDAY, MAY 10, 2018

Here's what I came up with for a spark sampling circuit.


And here's a view of C1 and L1.


The inductor is from a set that I got from Amazon. The capacitor is a crude thing that I made out of two pieces of beer can aluminum and double-sided tape; it's about one inch square. (I later replaced that homemade capacitor with a 33pF disc capacitor, and that works about as well.)

In use, a pickup is simply held next to an engine's spark plug wire. Either pickup works about equally well to coax a useable signal, ¬SPARK, out of Q1. That signal is messy, though. It turns out that a small engine spark is not a single event -- it's a little sequence of events. The ¬SPARK signal cannot be applied directly to an Arduino as an input; an erratic, chaotic rpm reading will result. To get around that, I applied the ¬SPARK signal to a 555 timer configured in its monostable mode.

- - -

Conditioning/Digitizing The ¬SPARK Signal -- FRIDAY, MAY 11, 2018

Here's the schematic for the 555 timer circuit that turns the messy ¬SPARK signal into a tidy pulse.


And here's the Arduino wiring for the display.


So there we have all the elements of my tachometer prototype, should you wish to recreate it. Here's a view of the prototype at work on the bench.


The business to the right of the display is a bit of known frequency input circuitry for test purposes. I'll post the schematic for that and an explanation shortly.

- - -

A Tachometer 'Speed' Signal Generator -- SATURDAY, MAY 12, 2018

For bench testing my tachometer prototype, I needed a signal source that would give me a known 'speed' input to the spark sampling transistor, Q1 in the first schematic above. A 60 Hz signal works out to 3600 rpm, and a 120 Hz signal works out to 7200 rpm, so I put together the half-wave and full-wave rectifiers shown below.


In use, VR1 and VR2 are adjusted so that Q1 is just triggered into putting out a ¬SPARK signal. The desired signal, 3600 'RPM' or 7200 'RPM' is applied via a breadboard jumper wire.

- - -

Spark Generation In The Workshop -- SUNDAY, MAY 13, 2018

This post describes an apparatus that lets me bench test the tachometer with a live spark.

- - -

Packaging And Refinement

I needed a steel enclosure for the tachometer, and given the cost of those things and the hassle to obtain one, I went to the dollar store to see what I might find. For $4.00, I came up with this.


It's an enameled steel storage tin. It's 5 1/2" x 5 1/2" x 4 1/8" tall, which is a bit large for what's needed, but at least it won't be cramped inside. The picture shows it with a 16 x 2 LCD installed in the tin's lid. Here's a rear view.


There's an on/off switch, a reset push-button and a 1/4" phone jack for a probe. I've added screws for securing the cover. Here's a look inside.


I still have wiring to finish up properly, and that 9V rectangular battery needs to be replaced by a cell holder that will give me a 6 x AA cell battery.

- - -

Accuracy -- TUESDAY, MAY 15, 2018

Accuracy is not great, but it's not bad either.

With a known 3600 rpm input, the readout ranges from 3600 to 3630; that's within 1%. I think the reason for the variation is that the one-second measurement 'window' and the read pulse train are not synchronized -- the device may drop or pick up a half or a full cycle now and then. Accuracy worsens considerably at low speeds. With a known input very near to 500 rpm, the readout ranges from 480 to 540; that's within 8%. I imagine that it should be possible to synchronize the measurement window with the read pulse train, but doing so may well be beyond my capability.

Susceptibility To Engines' EM Fields

With a steel-shrouded engine mounted on a steel mower deck, the probe needs to be very near the spark plug wire to pick up a signal. With my lathe-mounted spark generating apparatus, the tachometer gets an input signal even with the probe at some distance from the spark plug wire. The same is true of a scooter engine that I have. The scooter engine's shroud is a cast, non-ferrous alloy, and the ignition system seems to radiate a considerable EMF.

Anyway, there's my small engine tachometer, for whatever it's worth. I guess I can call it a qualified success.

- - -

Update -- THURSDAY, MAY 16, 2019

I've given the instrument a proper battery pack -- a six 'AA' cell holder.


I tried this for a pickup.


It's a 5 1/2 foot length of light gauge shielded wire with a battery terminal post alligator clip on the end. The clip connects directly to the instrument's input point via the shielded wire. The shield braid connects to signal/chassis ground at the 1/4" phone plug. In use, the alligator clip is simply clamped onto a spark plug wire's insulation.

It's not entirely free of flakiness, but it works well enough for things like setting governed speed on a lawn mower engine.

# # #


# # #

1 comment: