HOW TO SENSE 12 VOLT DC VOLTAGE USING MICROCONTROLLER? - Page 1
Forum section: electronics / beginners

author: wabhavkumar
author_rank: Contributor
timestamp: July 02, 2018, 11:33:15 am
content: I WANT TO USE 12V OPERATING NO NC SENSOR WITH MICROCONTROLLER. PLEASE SHARE METHODS OF DOING THIS

author: Kjelt
author_rank: Super Contributor
timestamp: July 02, 2018, 11:38:37 am
content: Your caps lock is stuck

author: Kjelt
author_rank: Super Contributor
timestamp: July 02, 2018, 11:41:58 am
content: But to answer your question many possibilities, I use mainly:1) voltage divider (two resistors)https://en.wikipedia.org/wiki/Voltage_divider2) opto couplerThe first one I use with local (on pcb) voltages that are referenced to the same ground.The second I use mainly with off pcb voltages from different devices.

author: Kjelt
author_rank: Super Contributor
timestamp: July 02, 2018, 12:28:29 pm
content: Quote from: GeorgeOfTheJungle on July 02, 2018, 11:43:58 amHahaha the topic text was more clear but rereading this it really does not compute

author: wabhavkumar
author_rank: Contributor
timestamp: July 02, 2018, 12:33:31 pm
content: thank you for the valuable reply. Please suggest optocoupler circuit.

author: DTJ
author_rank: Super Contributor
timestamp: July 02, 2018, 12:45:40 pm
content: Quote from: wabhavkumar on July 02, 2018, 12:33:31 pmHave a read of these links. They will get you started.http://www.onsemi.cn/PowerSolutions/document/AN-3001.pdf.pdfhttp://www.nutsvolts.com/magazine/article/optocoupler-circuits

author: wabhavkumar
author_rank: Contributor
timestamp: July 02, 2018, 01:03:52 pm
content: Can we use 12v input at Pin no 1 of optocoupler?

author: wabhavkumar
author_rank: Contributor
timestamp: July 02, 2018, 01:26:01 pm
content: is using 12volt input at pin no 1 of optocoupler pc817 correct? kindly check the circuit image

author: Kjelt
author_rank: Super Contributor
timestamp: July 02, 2018, 01:37:42 pm
content: Check the led current for that opto, usually about 10-15mA. So for 10mA and a 1,3V Vfw of the led your 12V needs aprox a 1kOhm resistor not a 10kBut what is the REED_SW ?

author: wabhavkumar
author_rank: Contributor
timestamp: July 03, 2018, 05:39:36 am
content: hello sir,REED_SW is a type of NO NC sensor which is connected at pin no 1 and pin no 2 of the optocoupler.

author: Kjelt
author_rank: Super Contributor
timestamp: July 03, 2018, 06:56:08 am
content: You mean like a proximity sensor?These are in different versions which need different schematic:1) NPN NO this is a so called open collector output which will put the output hard to ground when active and floating (or 100k pullup or something like this) when passive. This needs to be in the - cathode side of the led, pulling the opto-led to ground when active and the + anode of the led needs to be connected with 1k to 12V.2) NPN NC this is the inverse of above and the only difference is that the software should inverse the logic.Then you have3) PNP NO: it gives 12V on the output when active, 0V when passive. This one you can use as drawn but you can forget about the pullup to 12V not needed.4) PNP NC: it gives 0V when active and 12V when passive. Again same as 3) but the software should inverse the logic.

author: wabhavkumar
author_rank: Contributor
timestamp: July 03, 2018, 07:07:37 am
content: Sir, instead of the optocoupler, can I use a transistor to sense high and low of the NO NC sensor.

author: wabhavkumar
author_rank: Contributor
timestamp: July 03, 2018, 07:13:41 am
content: Sir,Please verify the attached circuit can replace optocoupler circuit?

author: Kjelt
author_rank: Super Contributor
timestamp: July 03, 2018, 08:34:19 am
content: NPN needs a pulldown on the base not a pullup AFAIK.

author: Raj
author_rank: Frequent Contributor
timestamp: July 03, 2018, 09:02:22 am
content: let mistery part be microcontrollerPin 3 can do analogue measurement of input also ground needs to be common for both microcontroller and inputNote: for given values of resistor,the reading microcontroller does will be 4/12th part of inputpin 1 can do digital measurement of input 2 and ground can be isolated

author: wabhavkumar
author_rank: Contributor
timestamp: July 03, 2018, 10:03:46 am
content: At input 2, mentioned in the above circuit, can we use 12volt?

author: Raj
author_rank: Frequent Contributor
timestamp: July 03, 2018, 10:13:31 am
content: yes,Ouch.I forgot to revaluate the r4, it should be 1k ohm for 12v

author: luiHS
author_rank: Frequent Contributor
timestamp: July 03, 2018, 10:36:29 am
content: I convert any logical signal to 3.3v levels with a CD4050 or HEF4050 chip. For example, to read TTL 5v signals on a Kinetis microcontroller (there are no 5v tolerant ports available), or to check the status of switches that switch 12v voltages. This is for digital signals (high-low logical levels), not for analog signals.HEF4050 include 6 buffers, so if you only need read one signal better work with a transistor or optocoupler, though HEF4050 is very cheap and do not need any additional component.The voltage of the output signals in the HEF4050, will be the power supply voltage of the chip, between 3v and 15v, and the maximum voltage at the input is 15v.If you want invert the input signal, then can use the HEF4049 or CD4049.

author: Raj
author_rank: Frequent Contributor
timestamp: July 03, 2018, 01:21:26 pm
content: A resistor divider with at most a zener diode is best...all the rest is overkill and expensive to be honest

author: wabhavkumar
author_rank: Contributor
timestamp: July 05, 2018, 04:04:13 pm
content: Please suggest Zener diode circuit to sense 12 V or 24V circuit instead of the optocoupler.

author: Raj
author_rank: Frequent Contributor
timestamp: July 06, 2018, 08:21:35 am
content: Here's one for 12v...Don't use it for 24 volt input (the zener will prevent anything from getting damaged but still don't...it's unideal)

author: Raj
author_rank: Frequent Contributor
timestamp: July 06, 2018, 08:24:38 am
content: Here's one for upto 24 volt reading,but you can't use it for 12 volts unless you use analogue to digital converter though it won't get damaged from 12 volts,it's the safest choice for you.I think implementing anything that can be done in software is better than hardware implementation.What microcontroller are you using?

author: BravoV
author_rank: Super Contributor
timestamp: July 06, 2018, 08:37:18 am
content: Raj n Kumar, why Indians love to use eyes blinding text all the time ? Not only you two, but I have seen too many at various forums as well.Is it a cultural thing ? As common netiquette, its like shouting out loud when talking, everytime.

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: July 06, 2018, 09:20:04 am
content: You could use a voltage divider to get the correct voltage out for the microcontroller.You could also use a comparator to see if the voltage threshold exceeds 12V.Probable the easier of the two is the voltage divider.Not sure if you’re just exited but your caps lock is on

author: Zero999
author_rank: Super Contributor
timestamp: July 06, 2018, 09:27:45 am
content: Quote from: BravoV on July 06, 2018, 08:37:18 amPerhaps their love of eye burning text is linked to their taste for mouth burning spicy food?Anyway, I recently posted this schematic in another thread. It converts a voltage ranging from 10V to 15V to 0V to 5V, which can be read from an MCU ADC pin.https://www.eevblog.com/forum/projects/mesuring-a-12v-lead-acid-battery/msg1644677/#msg1644677

author: Raj
author_rank: Frequent Contributor
timestamp: July 06, 2018, 04:40:47 pm
content: Yup,its a cultural thing.People don't play attention to the important parts otherwise.It's origin? our schooling system I guess.The textbooks are huge but the parts students are supposed to learn are one or two lines per page,made to underline by our teachers. I still used to read the whole book

author: Raj
author_rank: Frequent Contributor
timestamp: July 06, 2018, 05:25:04 pm
content: Quote from: Hero999 on July 06, 2018, 09:27:45 amInteresting...I would have taken a way expensive route with negative voltage or ground isolation from input,making input ground, -10+diode drop equalvant and a diode at input,or simply use 16 bit mode adc ( there's an article on microchip's website on how to do that on 10 but atmegas without external adc)

author: Raj
author_rank: Frequent Contributor
timestamp: July 08, 2018, 09:46:29 am
content: Hey orignal post author,If I am guessing correctly,I think you are trying to make a car voltmeter or a battery monitor of some sort,right?

author: wabhavkumar
author_rank: Contributor
timestamp: September 29, 2018, 11:46:55 am
content: Hello all,can anyone suggest, below attached circuit diagram can work or not?if not, please suugest pc817 optocoupler circuit for sensing 12 volt using microcontoller.

author: Raj
author_rank: Frequent Contributor
timestamp: September 29, 2018, 02:07:41 pm
content: This will work

author: wabhavkumar
author_rank: Contributor
timestamp: September 29, 2018, 04:32:24 pm
content: this circuit is not working at 50 meters circuit

author: Mr. Scram
author_rank: Super Contributor
timestamp: September 29, 2018, 04:49:31 pm
content: Quote from: wabhavkumar on July 02, 2018, 12:33:31 pmWhat's wrong with a voltage divider? It seems by far the simplest solution. Without more information we're left guessing.

author: Zero999
author_rank: Super Contributor
timestamp: September 29, 2018, 06:50:35 pm
content: Quote from: wabhavkumar on September 29, 2018, 04:32:24 pmWhat do you mean by 50 meters circuit? It makes no sense.Is this connected to circuit, via a long piece of cable? If so, then you should have said before!

author: Kjelt
author_rank: Super Contributor
timestamp: September 29, 2018, 09:19:47 pm
content: At 50 metres you should put a microcontroller on both ends and connect with rs422/485 or ethernet

author: Mr. Scram
author_rank: Super Contributor
timestamp: September 29, 2018, 09:23:13 pm
content: Quote from: Hero999 on September 29, 2018, 06:50:35 pmThis community seems so eager to help that it often starts offering advice before someone has bothered to properly specify the problem. That doesn't foster proper behaviour.

author: SparkyFX
author_rank: Frequent Contributor
timestamp: September 29, 2018, 09:43:32 pm
content: I don´t see why that reed switch should not operate at the microcontrollers operating voltage. Or switch ground with a pull up?

author: wabhavkumar
author_rank: Contributor
timestamp: September 30, 2018, 11:00:50 am
content: I am really sorry for posting an incomplete question.yes, if no/nc switch is connected with 50m length of wire, then this circuit is not working properly.Can anyone suggest some better circuit?

author: Raj
author_rank: Frequent Contributor
timestamp: September 30, 2018, 01:41:00 pm
content: go see Reply #20 on: 06-07-2018, 18:21:35Use it.