Need to convert 12v - 3v signal into digital 0-5v signal - Page 1
Forum section: electronics / beginners

author: bjt_fetter
author_rank: Newbie
timestamp: March 02, 2022, 01:30:48 am
content: Here's what I came up with to turn a 12v - 3v signal into a 5v - 0v digital signal for my Arduino. It seems to work but for some reason I keep blowing up the op amp after a few days. Is there something I should add, or better yet, is there a better design for this?My car's air conditioning system has a wire that goes to the engine computer that is 12 volts when A/C is off, around 3v when A/C is on (varies a little bit depending on the fan blower speed).Thanks

author: IanB
author_rank: Super Contributor
timestamp: March 02, 2022, 01:43:46 am
content: Quote from: bjt_fetter on March 02, 2022, 01:30:48 amThese two things are probably not unrelated.A car's electrical system is very noisy, with all sorts of high voltage spikes and other sorts of bad stuff floating on the wires. Any delicate electronics connected to that system will need careful input filtering to protect from damage.Is suspect you will want at a minimum a low pass RC filter with a high series resistance and a capacitor to ground, and maybe some kind of clamping diode like a zener to remove high voltage spikes. Others can advise better than I can.

author: IanB
author_rank: Super Contributor
timestamp: March 02, 2022, 01:51:21 am
content: Here I was thinking about the input signal to the op amp. But also, you need to consider a clean power supply for both the op amp and the Arduino.For instance, I have a 12 V USB charger and the instructions say, "Do not have this plugged in when starting the engine." This is a device that is designed for in car use, and still they are scared of it being damaged by voltage spikes.

author: bjt_fetter
author_rank: Newbie
timestamp: March 02, 2022, 02:13:55 am
content: After some more research, i think this should work.

author: bjt_fetter
author_rank: Newbie
timestamp: March 02, 2022, 06:12:18 am
content: Well it didn't work.https://youtu.be/Ybf4hjn5ZhY

author: darkspr1te
author_rank: Frequent Contributor
timestamp: March 02, 2022, 07:41:25 am
content: My 2 pennies worth here.I would have a darling pair power the opto isolator , that way you are stepping down the forward voltage and current, i've used ULN2803;s and ULN2003's for this purpose.The switch 12v would trigger the high side of darlington and the darlington will trigger the low side of the opto isolator. add in the correct bias resistor and you have you HV switching setup.On another note the voltages you have shown, ~12v at off and ~3-5V at on is a odd value and make me think there are other signals at play here, example is in modern cars the ac switch might be a canbus device and what you are seeing is the high frequency signal at 3-5v and 12v is canbus at rest ( i have tested this and found my canbus behaves like this in my rav4) , this is also the same in BMW, the lights switch is not a ON/OFF signal but in fact a CANBUS device and will not provide a usable on/off value without canbus hardware.As you didnt mention the car I am going to assume it's modern ,maybe 2005 onwards in which case I may well be right there.A good test for this is using a scope or multi meter with frequncy counter on it and test this AC switch value, also the wires if they are twisted may show they are canbus.darkspr1teedit: saw the video and now know it's 2000 mazda miata,as per this diagram,https://www.miataforumz.com/1990-200-Miata-Wiring/2000wire.pdf- page 49 Condenser Fan Systemat connect X-07, purple wire goes to ground via resistor pack(blower fan speed) when AC and FAN is on, this in turn controls the blower relay and AC compressor relay and also tells the PCM to idle up at pins 25/26 (section B) ,that would be a better signal to read as it's providing 2 signals, AC requested (the actual ac switch) and compressor on (has enough gas and is operational right now)hope this helps.darkspr1te

author: Terry Bites
author_rank: Super Contributor
timestamp: March 02, 2022, 11:45:19 am
content: Power the LM324 from the Arduino 5V rail.This will keep the horrible transients on the car's 12V bus from destroying your comparator.Protect the comparator inputs from similar garbage and attenuate input to suit threshold.So something like this for a few cents more-with optional status LED!

author: bjt_fetter
author_rank: Newbie
timestamp: March 02, 2022, 03:49:48 pm
content: I couldn't power the op amp from 5v rail, it wasn't comparing properly. It was powered with 5v, trying to compare 12v versus 6 volts, can it do that while running at 5v? I couldn't get it to work.

author: Zero999
author_rank: Super Contributor
timestamp: March 06, 2022, 07:42:25 pm
content: Why not alter the software and use a single transistor?

author: nali
author_rank: Frequent Contributor
timestamp: March 06, 2022, 08:12:03 pm
content: Or scale the signal down with a couple of resistors and use an analogue pin then arbitrate in software? Also use a clamping diode to be on the safe side.

author: tooki
author_rank: Super Contributor
timestamp: March 07, 2022, 05:01:03 pm
content: Quote from: bjt_fetter on March 02, 2022, 03:49:48 pmIn the original post you say the “low” level is around 3V, not 6…Regardless, scaling a voltage down is easy: use a voltage divider (resistive divider). For example, you could scale it to 1/3, giving you 4V as “high” and <2V as “low”. By similar fashion, you generate a reference voltage by dividing your 5V supply.Did you not look at Terry’s schematic, which does precisely this?? (It scales the input voltage to 0.4 times the input — 4.8V for high, 2.4V for low — and the reference is 1/2 the supply voltage, so 2.5V.)FYI:Fundamentally, a comparator just looks at which input’s voltage is higher and then swings the output to the positive or negative power supply rail (not to the input voltage!!!). In theory, you could tie one input of the comparator to the +12V supply (or a reference voltage derived from it), the other to your input signal, but power the comparator with +5V. The amount by which an input voltage can exceed a supply voltage varies by model. (They even make special comparators optimized for this scenario, I used one in a recent project.)

author: Zero999
author_rank: Super Contributor
timestamp: March 07, 2022, 09:57:16 pm
content: I suppose common base is another option. R5 represents the internal pull-up.