How to measure 12v signal?



  • Hello all, I am building a sensor that would be able to tell if a pump turns on. The signal would be 12v. I am not sure if it is possible to sense this using the GPIO or some other mechanism. I intend to use a GPy with a PyTrack board. I've been told it might be good to use a optio isolator like this one: https://www.digikey.com/product-detail/en/taiwan-semiconductor-corporation/TPC817A-C9G/TPC817AC9G-ND/7359668 but I am not sure how to incorporate it into one of the boards.

    Thanks in advance.



  • @sailorscott I haven't used the GPy myself but looking at the datasheet there are several GPIOs you should be able to use - with some of them you can set an internal pullup but others need you to add a pullup resistor between the pin and +3.3V - that's assuming of course that the input you are trying to read is either open-circuit or pulls the pin down to ground. You can use the same technique to read a float switch: just wire the switch in place of the optoisolator outputs in my previous description.

    I don't have a book recommendation off the top of my head but a web search for 'optoisolator tutorial' should get you started if you know the basics of how to use resistors, LEDs and transistors. If even that's still a bit new to you then a basic electronics course and/or book would be good - learn by playing with some cheap components before you risk frying your expensive GPy.



  • Thanks for the info. Just so I am clear, the GPy will allow additional inputs on the GPIO? I've not built one of these before. Any good books to recommend that show how to build this?

    I am also thinking of adding float switches to set of an alarm if the water gets too high.



  • @sailorscott An optoisolator is a good choice for this kind of interface because (a) you don't have to worry about whether the 12 V circuit and your board share the same ground and (b) you don't have to worry about voltage spikes damaging your board.

    An optoisolator basically consists of an LED coupled to a phototransistor. When you light the LED, the transistor turns on. Looking at the datasheet for the one you linked, you would connect pin 1 via a resistor to the 12 V signal - something like 2k2 should work, putting about 5 mA through the LED - and pin 2 to ground on the 12 V side. Then connect pin 3 to ground on the GPy side and pin 4 to a GPIO pin configured with pull-up, or connected with an external pull-up resistor, e.g. 47k, to 3.3V. Now when the 12 V is present you will read low on this GPIO, otherwise high.


Log in to reply
 

Pycom on Twitter