How to sense on/off status of a switch that has voltage in it.

I have a switch that I want to sense ON/OFF status (short or open status).
However, the switch is on a 12 volt line. (This is a switch, that will be opening a gate).

I used the 2 connectors as a switch to Pin 2 to ground on my arduino with appropriate programming.

If I short pin 2 to ground, it works as I want to (I'm able to send an email to myself successfully).

However when i use these 2 cables for testing open/closed status, I keep getting emails non stop, as if the wires are shorted already.

I am sure the 12 volt is causing the problem.

Can someone suggest what I can do to resolve this problem? That is to be able to sense the on/off condition, on a switch that has voltage in it?

Thanks
Mark

I can't picture your circuit in my head from your words: best if you post a sketch.

We also can't see your "appropriate programming" from where we are :wink: so best post that too.

Wild guess is that you're enabling your email based on a pin being high, which would explain the stream of emails. You should be looking for the pin having gone high from low, so only one email per event. But, wild guess.....

How are you reconciling the Arduino to the presence of 12V?

I basically started off with the example of a button switch, turning on(or off) an LED light.
Started off with this basic simple example: http://arduino.cc/en/Tutorial/Button

I continued to augment the code to implement sending email each time a button is pressed, along with reading information on a website, parsing the info and displaying on the screen.
Everything works perfectly on my test bench as I want.

When putting this into a live environment, the only difference is the push button is having voltage across its contacts, it is not just a dead switch thats either zero ohms almost, or infinity. In this case (live environment), the Arduino senses "pressed" state all the time.

I need to figure out a way to not sense the voltage across the switch. I might have to end up using a diode or something, but am not sure at this point, I am not yet successful in my goal.

At the risk of repeating myself.....

JimboZA:
I can't picture your circuit in my head from your words: best if you post a sketch.

We also can't see your "appropriate programming" from where we are :wink: so best post that too.

Hi,

an you please post a copy of your sketch, using code tags?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

We need to see how you have connected the 5V arduino into the 12V switch arrangement.

Thanks Tom........ :slight_smile:

I have solved the problem by using a relay to isolate the two circuits, the Arduino and the swing arm-gate system at my factory. Thereby no 12 volt interfering with the Arduino.

I might make a DWG (CAD drawing) for both circuits, when if I find some free time on the weekend perhaps, for anyone to download and see (using the free cad viewer). OR maybe i might post a PDF from the CAD so anyone can see whether they have Cad viewer or not. I am sure this might come in handy for someone who has a similar need. This was my first project using Arduino and I must say it was exciting when it finally worked!