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!
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!