# Converting 12v alternator signal to HIGH/LOW into a uController with an opto-isolator

#### ba58smith

Joined Nov 18, 2018
60
I'm trying to create a tachometer with an ESP8266, by reading the output from the stator wire on my 12V alternator. I'm using a 4n37 opto-isolator to provide the HIGH/LOW signal to the ESP8266. See schematic.

When I use an Arduino to create a simple ON/OFF signal and feed that into the 4n37 (through R2 first), I get exactly what I expect - the same frequency coming out of the ESP8266 as the frequency coming out of the Arduino. That tells me the 4n37 is doing what I expect. The first image shows the ouput on a DSO138 oscilloscope set to DC mode, but as you can see, the low voltage is negative, not 0, which is why I think it's AC voltage, not DC. (If that sounds stupid - I'm very new to this, and this is the first time I've ever used an oscilloscope.)

When the input to my 4n37 is the output from the alternator, however, I get very erratic results on the input pin of the ESP8266 - the frequency jumps all over the place. I am wondering if it's because the stator wire outputs AC voltage and maybe the 4n37 can't handle that?

If that's the problem, it seems like I should be able to use a diode between the stator wire and the opto-isolator (in series with R2 in the schematic) (a half-wave rectifier - I looked it up!), which should basically "chop off" the negative part of the signal and have it just bottom out at 0V. That would be fine, as the ESP8266 is simply counting RISING edges. However, when I tried a 1N4007 diode, it didn't seem to have any effect on the output - see the next image:

Questions:
1. Is the alternator ouput in fact AC, and if so, is that causing my problem?
2. Could it have anything to do with the fact that all the grounds are tied together?
3. Why didn't the diode have the desired effect of setting a lower limit of 0V on the wave?
4. Most important - what can I do? Do I need an opto-isolator that's specifically designed for AC on the input side?
Thanks for all relevant input!

Joined Jan 15, 2015
5,337
The alternator output is DC. The actual alternator stator outputs 3 phase AC which is on board rectified to DC. See the below image which is less the field winding and regulator guts.

Even if you pickoff the alternator using a phase to phase about all you will get is an alternator rotational speed which is not engine RPM. Depending on the automotive make and model there should be an engine tachometer sensor somewhere which would likely give you a signal more inline with what you actually want.

Here is another example of a typical automotive alternator:

Anyway the alternator output is DC after the rectification.

Ron

#### ba58smith

Joined Nov 18, 2018
60
The alternator output is DC. The actual alternator stator outputs 3 phase AC which is on board rectified to DC. See the below image which is less the field winding and regulator guts.

View attachment 176667

Even if you pickoff the alternator using a phase to phase about all you will get is an alternator rotational speed which is not engine RPM. Depending on the automotive make and model there should be an engine tachometer sensor somewhere which would likely give you a signal more inline with what you actually want.

Here is another example of a typical automotive alternator:
View attachment 176668

Anyway the alternator output is DC after the rectification.

Ron
Ron,

It's not a car, it's a boat, and the tachometer output IS the stator wire, according to the alternator mfr (Balmar). The stator wire is what's driving the existing analog tachometer - it's just not at all accurate, which is why I want to create a new one. And I know it's not engine RPM, but all it takes is a simple equation to convert alternator RPM to engine RPM, which is what an analog tach does.

But to my original question(s): can you explain to me why the oscilloscope would show the voltage alternating between positive and negative, if it's DC? When I look at bursts of DC current from an Arduino digital pin that I have progammed to pulse on and off, it doesn't look like that at all - it's 0V for a short time, then it shoots straight up to 5V for a short time, then back to 0V - over and over again. My apologies if this is an incredibly basic question, but from the reading I've done, only AC current goes back and forth between positive and negative.

#### crutschow

Joined Mar 14, 2008
24,709
Show us the output of the optocoupler with the stator input.
You should leave the diode in series to protect the opto input from excess reverse voltage.

#### ba58smith

Joined Nov 18, 2018
60
Show us the output of the optocoupler with the stator input.
You should leave the diode in series to protect the opto input from excess reverse voltage.
This is what the output from the optocoupler looks like. The more I've thought about this, the less sense it makes: if the detector side of the opto is connected to 3.3V (thru the 10K PU) and to GND (0V), how could it ever go negative? One thought: notice that the GND on the input side of the opto is connected to GND on the detector side? That seems to violate the whole "isolation" concept - I'll separate those the next time I can work on this project.

#### Alec_t

Joined Sep 17, 2013
11,119
At which point in the circuit is the scope ground lead connected?

#### ba58smith

Joined Nov 18, 2018
60
At which point in the circuit is the scope ground lead connected?
Up to this point, I don't suppose it has mattered, as I had all the grounds on the entire project connected together. As noted above, the first thing I'm going to do is separate the ground on the input side from the detector side. At that point, the oscilloscope ground test lead will go to the ground of the side being tested. I will update here after I do that, as it seems like it could make a huge difference.

#### mvas

Joined Jun 19, 2017
537
Do you have a Ground Bus Bar on your boat?
Does the Alternator ground have a good bond to the Battery ground?
Is there any voltage difference between your Alternator ground and Battery ground?
Your project ( circuit Board ) should have a single point for all ground connections ( 7805 GND ) and then that point is connected to Battery Negative.
You project should not create a secondary / parallel ground path between the Alternator and the Battery !

3 Input wires to your project:
1) Stator Coil to Opto (+) Input, then Opto (-) Input to project ground
2) Battery Positive to 7805 (+)
3) Battery Negative to 7805 (Gnd) <<< Project Ground Point

4 Input wires ( isolated opto ) to your project:
1) Stator Coil to Opto (+) Input
2) Alternator Ground to Opto (-) Input but then no connection to battery (-)
2) Battery Positive to 7805 (+)
3) Battery Negative to 7805 (Gnd) <<< Project Ground Point
Note: I would twist the pair coming from the Alternator.

And you say "... the frequency jumps all over the place ..."
Can you be specific about the change in frequency?
+/- 5 Hz or +/- 10 Hz or ?
How stable is your actual engine RPM speed?

You need a clean Square Wave, you have "glitches" in your waveform.
What is your Trigger "ON" Voltage for the Rising Edge ?
Would a Schmidt Trigger help?

Last edited:

Joined Feb 20, 2016
3,425
Maybe you have the oscilloscope input switched to AC coupling, not DC as there can really not be AC at the opto output.

#### ba58smith

Joined Nov 18, 2018
60
Do you have a Ground Bus Bar on your boat?
Yes.

Does the Alternator ground have a good bond to the Battery ground?
Is there any voltage difference between your Alternator ground and Battery ground?
Yes, a good bond. No voltage difference between Alt Pos - Alt Gnd (12.79 just now) and Alt Pos - Bat Neg Bus (12.79).

Your project ( circuit Board ) should have a single point for all ground connections ( 7805 GND ) and then that point is connected to Battery Negative. You project should not create a secondary / parallel ground path between the Alternator and the Battery !

3 Input wires to you project:
1) Stator Coil to Opto (+) Input, then Opto (-) Input to project ground
2) Battery Positive to 7805 (+)
3) Battery Negative to 7805 (Gnd) <<< Project Ground Point

4 Input wires ( isolated opto ) to your project:
1) Stator Coil to Opto (+) Input
2) Alternator Ground to Opto (-) Input but then no connection to battery (-)
2) Battery Positive to 7805 (+)
3) Battery Negative to 7805 (Gnd) <<< Project Ground Point
Note: I would twist the pair coming from the Alternator.
Thanks for the very detailed reply, @mvas. Can you please clarify something? "1) Stator Coil to Opto (+) Input, then Opto (-) Input to project ground" and "2) Alternator Ground to Opto (-) Input but then no connection to battery (-)". Each of these describes a connection to Opto(-); the first says connect it to Project Ground, the second says to connect it to Alternator Ground. But the second one also says "..."but then no connection to Battery(-)". It seems that in my original schematic, that's what I have. But I've modified the schematic to try to represent exactly what you said, below. Is that somehow different from the original schematic? (The battery symbol in the upper left of the schematic is actually the alternator - I couldn't find a symbol to represent an alternator in Fritzing.)

#### ba58smith

Joined Nov 18, 2018
60
Maybe you have the oscilloscope input switched to AC coupling, not DC as there can really not be AC at the opto output.
@dendad, I've switched the oscilloscope back and forth between AC and DC, and it doesn't seem to do anything other than shift the wave up and down. The bottom of the wave is always negative, regardless of the setting. However, you can see "DC" in the lower left corner of all of my oscilloscope screen shots.

#### KeithWalker

Joined Jul 10, 2017
794
This is what the output from the optocoupler looks like. The more I've thought about this, the less sense it makes: if the detector side of the opto is connected to 3.3V (thru the 10K PU) and to GND (0V), how could it ever go negative? One thought: notice that the GND on the input side of the opto is connected to GND on the detector side? That seems to violate the whole "isolation" concept - I'll separate those the next time I can work on this project.
View attachment 176675
The waveform from your opto-coupler is reasonable in amplitude and shape for inputting to the arduino. In your circuit, the output can not go negative with respect to ground. I suspect that you have a zero offset on the display of your scope. What scope are you using and what display do you get when you short the probe tip to ground. It should be a straight line through zero volts.
I think it's time to check the coding on your Arduino.

#### crutschow

Joined Mar 14, 2008
24,709
This is what the output from the optocoupler looks like.
That looks like a good signal.
Why do you think it's not?

Since that signal also shows a negative part, it would seen you have a scope setting/adjustment issue.

#### mvas

Joined Jun 19, 2017
537
Thanks for the very detailed reply, @mvas. Can you please clarify something?
View attachment 176683
You must select either a "3 Wire" connection OR a "4 wire" connection to your project.

Your latest schematic looks almost like a "4-Wire ( isolated Opto ) " connection, except you have a 5th wire...
1) Alternator Stator connects to Resistor, which connects to Opto (+) input = OK
2) Alternator Ground connects to Opto (-) Input = OK - except for that "extra" 5th wire ?
3) Battery (+) connects to 7805 (+) = OK
4) Battery (-) connects to 7805 (Gnd) << Project Ground Point = OK - except for that "extra" 5th wire

What is that "extra" 5th wire from the Opto (-) into to 7805 (Gnd) Terminal for?
Your boat already has a connection between Alternator Ground and the Battery (-) via your Ground Bar
So, why are you connecting another wire between Opto(-) to 7805(Gnd) ?

The Opto(-) connects to either...
(a) the Alternator(Gnd) using a 4 wire connection ( 2 wires to alternator & 2 wires to battery ) OR
(b) to the Project Ground = 7805(Gnd) using a 3-wire connection ( 1 wire to alternator and 2 wires to battery )

I think, remove that 5th wire.
Do you agree?

#### KeithWalker

Joined Jul 10, 2017
794
You must select either a "3 Wire" connection OR a "4 wire" connection to your project.

Your latest schematic looks almost like a "4-Wire ( isolated Opto ) " connection, except you have a 5th wire...
1) Alternator Stator connects to Resistor, which connects to Opto (+) input = OK
2) Alternator Ground connects to Opto (-) Input = OK - except for that "extra" 5th wire ?
3) Battery (+) connects to 7805 (+) = OK
4) Battery (-) connects to 7805 (Gnd) << Project Ground Point = OK - except for that "extra" 5th wire

What is that "extra" 5th wire from the Opto (-) into to 7805 (Gnd) Terminal for?
Your boat already has a connection between Alternator Ground and the Battery (-) via your Ground Bar
So, why are you connecting another wire between Opto(-) to 7805(Gnd) ?

The Opto(-) connects to either...
(a) the Alternator(Gnd) using a 4 wire connection ( 2 wires to alternator & 2 wires to battery ) OR
(b) to the Project Ground = 7805(Gnd) using a 3-wire connection ( 1 wire to alternator and 2 wires to battery )

I think, remove that 5th wire.
Do you agree?
If you are using the same 12V battery to power the alternator and the Arduino then the ground must be connected to both. The opto-isolator does not isolate the signal but it does condition the 17 Vp/p signal from the alternator so that it is suitable for connecting to the microprocessor.
The electrical system on any gasoline engine is not an ideal environment for a microprocessor. It would be advisable to connect a pair of capacitors in parallel (100uF // 0.01uf, 16VDC working min.) between the output and ground of the 7805. This will help to minimise electrical noise.