12v And Ground As An Input On The Same Pin

Hey guys. First time poster and new to Arduino. Not really new to electronics in general though. I'm Building a Nano based controller to operate a PWM controlled cooling fan in an automotive application. I'm trying to make it kinda "universal" in a way to where I can build multiples of them and then use them in different vehicles. Because every vehicle is different, it may need either a pull up or pull down signal to the inputs from sources like the A/C. I'd like for it to be able to see either a ground signal or a 12v signal on the same input pin and just change which means ON via a variable in the code. Reason being is I'm having some custom PCBs made through JLC and I don't want to have to reconfigure it and have a new board made every time I want make a new unit for another vehicle.

I currently have it configured as a simple voltage divider that pulls the input pin to 2.5v. Then the 12v/ground source is also connected to the input pin via a resistor. Essentially if 12v or ground is applied to the input, it will pull it either above 2.5v or below 2.5v. I also have a 5v Zener diode to help protect it from stray voltage spikes. In the code I have it configured to be on or off using a threshold of either 3v or 2v and then control it with a variable.

It works well in testing but I was just curious if there's perhaps a better way of doing this? I know there's lots of you far smarter than I and if there is either a simpler or more robust way of doing things, that's what I would prefer. If not, I'll just roll with what I got. Just want it to be as robust and reliable as possible.

Here is a simple circuit diagram of how I currently have it configured.

Capture

An opto-isolator will completely isolate the input from the Arduino.

1 Like

Use different input pins

How can i combine a pull up and pull down input on the same pin using an optocoupler?

I dont want to use more pins. Ive already occupied all of the analog pins and four of the digital pins. Also, as of right now there are a total of 12 wires for power and IO. I dont want to add any more. Partially because of simplicity, partially because im working with very little space to build the circuit board.

How many of these are you thinking you may sell or install? Two simple solutions:

  1. Use an additional pin that is connected to a DIP switch, re-write your code to look at this pin, if this pin is high then set up you input to expect a HIGH, if this pin is low set up your input to expect a LOW.

  2. Wait until you know whether you need a High or Low and flash you Arduino with the appropriate code.

https://www.jameco.com/Jameco/workshop/Howitworks/what-is-an-optocoupler-and-how-it-works.html

It just come down to how you wire the input of the opto into the circuit, depending on pullup or pulldown.
Use the same device just wire it differently.

No matter which config, turning on the switch will activate the opto output and so the controller input.

Tom.. :grinning: :+1: :coffee: :australia:

I'm not looking to sell any, however I do intend on sharing all of its design files and code. Essentially if somebody wants one, they can just simply save the gerber and code files and just make one for them selves with all the R&D done. Plus, I currently own three vehicles myself that I may or may not install it on. Each has different controls that need to be able to work with the unit. I have a few friends that may be interested in owning one too.

I like you method one and have considered that. Problem lies mostly with packaging. The dip switches just take up too much space in the enclosure. That, and there needs to be a bunch of different variables that need to be changed in the code anyway such as fan speed, number of fans, temperature thresholds, and even a/c pressure thresholds. If I have to change all of those anyways, its not much to change the input type in the code either. So method 2 is the route I chose. The question still stands though, other than how I currently have it configured, how else can I make the input pin see either pull up or pull down without any hardware changes?

Got ya. I see what your getting at. I suppose that's a pretty robust option as the arduino will be completely isolated. Unfortunately, that will need two input wires, a control and a constant. Depending on vehicle, it may require two wires per input, which will eat up lots of space. I like it though. Ill keep it in mind for future projects. Thanks

You will need two wires/connections to complete a circuit for each input.

Or you have a set of gnd common inputs, all sharing the same gnd, and a set of supply (say 12V) common inputs, all sharing the same 12V supply.

Here is a classic module designed to cater for common gnd or common reference circuits.

Tom.. :grinning: :+1: :coffee: :australia:

I unnderstood how you meant. When I said 2 wires per input i meant as two wires per input into the control module as a whole. With four inputs, depending on vehicle that can be up to 8 wires for the inputs alone with up to 16 wires in total. Im just trying to keep it simplified from a wiring stand point. That and 16 wires are a lot to squeeze into an enclosure only slightly larger than a nano. Trying to keep it as small as possible.

Forget about size and get a prototype/proof of concept going first.

Get some experimenting done in the real world, then solve any problems, over thinking is not a good thing.

Opto will work for ON/OFF signals but analog signals like fuel level, manifold pressure may need separate modules for each type of analog input to connect to your main controller.
That's is how Arduino solve the problem of so many different analog signal conditions that need to be standardised to 0 - 5V or 0 - 3.3V inputs.

Tom... :grinning: :+1: :coffee: :australia:

Ive been working on this for a couple months already. I have done lots of prototyping and testing and have even had a functioning proto type installed in a vehicle for a few weeks and its worked well, albiet with only 2 inputs and a single fan control at the time. Even did over volt, reverse polarity, over current and over temperature stress testing as it will be installed in an engine compartment.

Ive got a main board already designed. It will have four on/off inputs that can be either a groud or 12v switched signal. 2 fan outputs that can either control 5v/12v bias pwm modules and/or 12v relays for regular brushed fans. Will also have two more pwm capable outputs for either 12v indicator lights or 12v relays for even more fan control. The last 2 inputs will be a variable voltage input with a 5v bias that can be used for temperature and/or A/C head pressure. Will also have a small oled display for quick diagnosing of faults.

All the design, testing and prototyping has been done. I was just hoping for a few ideas to help further refine the circuitry before ordering the main boards. As I said, i like the optocoupler idea. I see its benefits but I just dont think it will be suitable for this application. I think im going to ultimately stick with the 2.5v bias method for now. If I come up with a better method later, i can always order a new set of main boards.

This sounds to me like something that should reside within the EEPROM of your Nano. Since you have other things to configure, that's where I'd put all that stuff. In my case, I even wrote an Arduino sketch to prompt me through setting all the parameters in the EEPROM. Process is simple, Download the setup sketch, respond to all the setup questions, then Download the real sketch. Done, no jumpers, switches or other things I can later futz up.
Just a free two-cent donation.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.