thebenchmark
Posts: 5
Joined: Sun Mar 19, 2017 3:26 am

Sensing 12v input using GPIO

Sun Mar 19, 2017 3:47 am

Hello guys

I'm doing quite a large project in which I'm planning to control a spa from the raspberry PI.
I've got most of the things figured out but i'm stuck at the following problem.

I've got 4 12vdc lines that I need to sense whether they are powered or not and read this into the pi by gpio.
I've found on the web that I should ideally use an optocoupler for each line so I refrain from frying the PI.
Unfortunately I wasn't able to find a clear how-to for connecting the whole, as I've only done a couple of projects I'm still a bit wary of calculating resistors and such.

From my current knowledge I should do the following:
-> The optocoupler has a forward voltage of 1.2 V at 0,02 A
-> This means the 12+ should be connected to a 560 ohm resistor and that should be connected to the anode, the cathode should be connected to the negative pin. (does the wattage of the resistor matter?)
-> The emitter should be connected to ground and the collector to the gpio pin and to the 3,3v rail with a 10k ohm resistor in between.

Is that correct?
As an extra question how much power would such a setup draw from the 3,3 pins? I think I'm getting very limited in available power there :?

Thanks in advance!

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 11995
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Sensing 12v input using GPIO

Sun Mar 19, 2017 3:11 pm

12V=1.2V = 10.8V if R =560 then I = 10.8/560 = 0,0192 A or 19.2 mA close enough!

Wouldn't worry about the 0.33mA a 10K pullup would draw from the 3V3 device, when pulled low.

you are golden.

Two tips, a 100nF capacitor between the GPIO and GND would cure any glitches and most "key-bounce" problems that could occur, and a 560 Ohm resistor between the GPIO and the emitter of the optocouplers-isolator would prevent you could fry your GPIO if you accidentally program it to output 3V3, while the transistor of the optocouplers-isolator is open.

thebenchmark
Posts: 5
Joined: Sun Mar 19, 2017 3:26 am

Re: Sensing 12v input using GPIO

Sun Mar 19, 2017 5:39 pm

Thanks for your reply :)

So this should be correct?
schama 12v sensing.PNG
schama 12v sensing.PNG (9.74 KiB) Viewed 2657 times

pcmanbob
Posts: 6401
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Sensing 12v input using GPIO

Sun Mar 19, 2017 7:10 pm

Hi.

No you have R3 in the wrong place it needs to go between the GPIO and the point were R2 connects.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 11995
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Sensing 12v input using GPIO

Sun Mar 19, 2017 7:14 pm

yeah, i meant collector not emitter.

thebenchmark
Posts: 5
Joined: Sun Mar 19, 2017 3:26 am

Re: Sensing 12v input using GPIO

Sun Mar 19, 2017 9:33 pm

Okay thanks for the correction, so this should be it?
schema 12v sensing.PNG
schema 12v sensing.PNG (10.29 KiB) Viewed 2534 times

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 11995
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Sensing 12v input using GPIO

Mon Mar 20, 2017 9:52 am

Yes!

again, sorry for the confusion.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: Sensing 12v input using GPIO

Mon Mar 20, 2017 10:30 am

I think you also meant to say "while the transistor of the optocouplers-isolator is closed", or even better conducting, not open.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 11995
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Sensing 12v input using GPIO

Mon Mar 20, 2017 12:06 pm

No! I don't think I made a lapsus here..

I was learned that you can "steer a transistor open", that is you steer (send) current into it's base and the transistor "opens", meaning it starts to conduct current. But yes its a bit confusing because an "open switch" means that the switch does not conduct current.

But IMHO a transistor that is "open" is conducting, in normal parlor.

But I could be wrong... I guess its open to two interpretations.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: Sensing 12v input using GPIO

Mon Mar 20, 2017 12:30 pm

I've always used open/closed for a transistor in the switch sense ie on=conducting=closed and off=non-conducting=open. But there again I'm a self-taught hobbyist of 40 years, not the electronics pro I suspect you are... also that's why i suggested "conducting" may be less ambiguous.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 11995
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Sensing 12v input using GPIO

Tue Mar 21, 2017 12:58 am

yeah conducting would have been better.

By the way I have been "into electronics" for about 50 years, and a professional for about 40 years.
Also English isn't my native language, and so maybe I learned "steering open" in my native language, and it might not apply well to English.

Still I think you shouldn't apply terminology meant for switches to transistors, or things like Opamps, or for that matter Tubes.
When I think about it, I think I picked up "steering open" in relation to tubes where the grid is used to "open or close a path for the electrons" so steering open means leaving a conductive path open for the electrons.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: Sensing 12v input using GPIO

Tue Mar 21, 2017 6:56 am

The use of open/closed & my misunderstanding/its ambiguity seems to stem from whichever crude model you relate to: the plumbing model with a valve controlling the flow of water (open=on), or the electrical model of a mechanical switch (open=off).

User avatar
romilly
Posts: 15
Joined: Fri Dec 02, 2011 7:02 am
Location: London
Contact: Website

Re: Sensing 12v input using GPIO

Tue Mar 21, 2017 7:16 am

@mahjongg

Your use of '[steering] open' is definitely not something a native English speaker would understand; the phrase conveys the opposite of what you intend.

You're right that 'Conducting' would make your meaning clear. It's also common to refer to a conducting transistor as 'on', but that is less intuitive to a beginner.
http://blog.rareschool.com/

Return to “Automation, sensing and robotics”