Sensing Ground on a 12 Volt circuit.

I’m normally pretty good at finding the information that I need but I couldn’t really come up with anything for this. I may have been searching wrong or something.

I have included a diagram of what I’m trying to do.
I need this to work just like drawn as I am trying to integrate the arduino into a preexisting circuit.
I need to be able to sense when this circuit is grounded so that I can have the arduino activate something else.

Results Right now:
It works exactly how I want it to, BUT and BIG one I feel this isn’t right and I also can hear a slight pop in my computer speakers when letting the push button go. I push it down nothing happens you let go and can hear computer speakers make a little faint pop sound.

Components:
Signal Diode I recall it being way over 12V and 3Amp but don’t know the exact specs.
(Had it on hand from another project)

My code is as follows also

void setup() {

Serial.begin(9600);

pinMode(2, INPUT_PULLUP);
pinMode(13, OUTPUT);

}

void loop() {

int sensorVal = digitalRead(2);

Serial.println(sensorVal);

if (sensorVal == HIGH) {
digitalWrite(13, LOW);
}
else {
digitalWrite(13, HIGH);
}
}

Diagram!

Diagram?

After posting and searching some more I started to think this way. Glad to see it may be the answer.

You are correct I just want to know if the button is pushed. The arduino registers anything above 0v as a push correct? Because the +12v source isn’t 100% clean so it could very from 12 to 15v.
So I was going to run the voltage divider so it puts out less than 5v in case I get voltage spikes from source.

Wawa:
I assume you just want to know if or when the button is pressed.

Safer to use a voltage divider with two resistors.

I assume you have measured the 12volt relay supply.
If it is 12volt:
10k from pin2 to Arduino ground.
15k from pin 2 to relay/switch.

This will only draw ~480uA from the 12volt supply.

Use the diode across the relay. Cathode to +12volt.
Back EMF from the relay could kill the Arduino pin.
Leo…

Does this look right? I just need to change my resistor values to higher ones?

Oops, accidently deleted my post while adding something.

The diode in the second diagram has to go across the relay coil.
A diode across the coil (cathode to +12) kills back EMF voltage spikes (the pops you hear).
15k connects directly to the switch.

Another more simple way is one diode as in your first diagram, and a second diode across the relay coil.
With _PULLUP enabled.
Leo…

Wawa:
Oops, accidently deleted my post while adding something.

The diode in the second diagram has to go across the relay.
15k connects directly to the switch.
Leo..

Well that's an issue, I have no access to the relay and the wire that hooks to the first resistor would be the only access I have to the whole circuit.. :frowning:
So I have to do it all with that one wire and the ground.

Any ideas how I can just use the one wire and sense when the circuit is grounded.

The relay coil will have a kickback voltage spike when you release the button.
That could kill the Arduino pin.
I would increase the the resistor values to 150k and 100k. No diode.
And use a ~18volt zener across the button.
Leo..

This is the best I could Physical do, as I can't gain access to the button as it is embedded in the control panel.
I appreciate the help, and I'm trying to not be difficult I'm just stuck in the parameters I have and am trying to figure out a way to do this :frowning:

Imagine you have a plug coming out of a console, and what is labeled in the diagram as WIRE 1 is all you have access to and the common ground. That is what I am faced with. I can't gain access to or alter any of the preexisting stuff.

Totally understand the EMF stuff and appreciate your feedback on it (pun) so I would like to try and safe guard against it. Your also right I don't want to kill the pin on the arduino. This is used in a non crucial system in terms of needing super clean signal or anything of the nature. This is just pure is it on or is it off kind of thing. So what ever we can come up with that will offer ruggedness and won't get fried is fine with me. LOL

Wawa:
The relay coil will have a kickback voltage spike when you release the button.
That could kill the Arduino pin.
I would increase the the resistor values to 150k and 100k. No diode.
And use a ~18volt zener across the button.
Leo..

That last circuit is what I had in mind, but the diode has to be an 18volt zener diode.
That limits the relay spike to the voltage of the zener diode.
Not a problem for the Arduino with the given resistor values.
Leo..

Wawa:
That last circuit is what I had in mind, but the diode has to be an 18volt zener diode.
That limits the relay spike to the voltage of the zener diode.
Not a problem for the Arduino with the given resistor values.
Leo..

Well, sounds awesome. I'll try that. It will work with out having to gain access to the control panel and I can keep it all with in my project box and not have to add external parts. Making it more plug and play.

I have some old electronics laying around is there anyway to figure out if one of these zeners would work ok?
It's mostly automotive stuff.

Probably hard to find a zener on old circuit boards.
For now you could use a cap across the switch.
That will also reduce the spike.
Try 10uF and listen to the pops.
Bit of russian roulette though.
A 150k:100k divider should protect the Arduino to ~200volt.
Leo..

Wawa:
That last circuit is what I had in mind, but the diode has to be an 18volt zener diode.
That limits the relay spike to the voltage of the zener diode.
Not a problem for the Arduino with the given resistor values.
Leo..

Also, this might make sense to you but not to me. I setup the circuit like the one in the last diagram. When I have the button not pressed and the power supply on. I see 6v on the voltage divider (which makes sense as it's a voltage divider) and the relay is open, shouldn't I see no voltage? Then when I push the button the 6v goes to 0 volts and the relay clicks (Like it should as I have now grounded it) isn't this opposite of what should happen.

I found some on this old board I have they say 1n4004
They look just like this but it says on datasheet they are 400v lol

1N400x are general purpose 1Amp diodes.
The last number represents the peak working voltage.
This is not a zener diode.

A 1N4746 would be perfect.
Leo..

Thanks for the recommendation I'll order some. So you think this is the best setup I could use with the limitations I have.
Also 6v wont hurt the arduino input pin?
Thanks again

Wawa:
1N400x are general purpose 1Amp diodes.
The last number represents the peak working voltage.
This is not a zener diode.

A 1N4746 would be perfect.
Leo..

uvamosk:
So you think this is the best setup I could use with the limitations I have.

Also 6v wont hurt the arduino input pin?

A zener is perfectly ok for this job.
Not commonly used when you can get to the relay, because a common diode across the relay is cheap and easy.

150k:100k is (100/250) * 12 = 4.8volt. Just below Arduino's 5volt supply.
150K also limits fault current when the Arduino happens to be off.
Leo..

The 6v question was ignorance on my part I only had 10k on hand used two. Got 6v. Now I understand how divders work and why using two of the value resistors yields half the input voltage. Lol so I guess you helped me understand something I wasn't really grasping.

I also think I figured out why im seeing voltage in the divder when the button isn't being pressed.

It's because the electricity is flowing through the relay and using the voltage divider as path to ground. The resistance path is so high it doesn't trigger the relay. Is this correct?

Which is fine because my 12v source is only on when the arduino is being used. So no fear of running a battery flat (even though I'm sure current draw is super super low).

I don't fully undestand how the zener diode protects from emf so I will try to learn how they work and why. Hopefully I'll figure it out.
Thanks

Wawa:
A zener is perfectly ok for this job.
Not commonly used when you can get to the relay, because a common diode across the relay is cheap and easy.

150k:100k is (100/250) * 12 = 4.8volt. Just below Arduino's 5volt supply.
150K also limits fault current when the Arduino happens to be off.
Leo..

Wawa I think I get it now.

So I use the divider so the voltage is in safe range. Then when EMF (over 18v) comes the zener breaks down and lets it flow to ground. It being a path of less resistance than the voltage divider.

Is this the corret train of thought.
Also if my math is correct 1/4 watt resistors are more than enough right?
Sorry to ask so many questions but I'm looking to learn and understand not just take your answer.

You know the teach a man to fish metaphor. Lol

Correct.

Also, when the Arduino is off, the voltage divider does not work anymore (pin at ground level).
Then the 150k resistor acts as a current limiting resistor.
It is said (not in the datasheet) that pin protection diode current has to be kept under 1mA.
So the 150k resistor could protect the pin to 150volt.
Leo..