12v+ relay sensor to pull up ardiono GPIO

So I'm going to use a 12v microwave sensor with a built-in relay to trigger a 3.3v microcontroller. The 12v might be slightly higher than the 12v as running from a car-based system, think alarm.
The way I see it is, that I could use an optocoupler or another relay powered by the 12v relay to set the pin high. I'm looking for the easiest plug and play result.

The microwave sensor and relay (DC 12V-24V 5.8GHz Microwave Radar Sensor Body Motion Detector Light Switch ATF | eBay
Other threads I've read https://forum.arduino.cc/t/12v-to-3-3v-signal-to-arduino/880298

https://forum.arduino.cc/t/optocoupler-for-3-30v-input/655337

Thank you in advance.

Tip: the link can be shortened to: https://www.ebay.co.uk/itm/192445427522

1 Like

I think the simplest and safest would be to use the relay to connect an Arduino pin to ground. Use pinMode(pin, INPUT_PULLUP);.

1 Like

Thank you, I swear link icons in other forums shorten the link automatically!!

As in using a second relay, you mean? These will be all running from separate common grounds ( I think the expression is)? A rough schematic would be the MC is running off of a 5v supply where the 12v relay sensor will be running from the same battery as the 5v source before it has been lowered, which then reads 3.3v. Regards

The opto-isolator doesn't need a voltage divider. It completely isolates the Arduino from 12V (but there might be a common ground).

Or, you can use an Over-voltage Protection Circuit (Increase the current-limiting resistor to between 1K and 10K).

Or, you can make 15V-to-5V voltage divider and add a diode like the protection circuit,

No.

Please explain why you think a second relay would be needed.

Please explain how grounds can be both separate and common.

1 Like

I very much doubt that (other than by using "bitly" or "tinyurl" etc). :face_with_raised_eyebrow:

I was going to mention that, but generally you need to remove the "?" and all following which is simply tracking information for the website to follow your search process. If you actually look at it you get some idea of what they are doing - things such as "campaignid" and "merchantid", "targetid", "googleloc". :grin:

1 Like

Paul, my mistake. I will operate the microwave sensor from a leisure battery then the relay will also activate a 12v piezo alarm from the same battery. I was hoping to use this 12v to pull a pin high.

The MC is controlled from the same 12v source but reduced down to 5v to power the MC, but the pins need 3.3v. I was taught or led to believe that unless it is communication voltage, then the grounds should be separate. I.E does not share the same ground as the battery.

A second relay could be used after the first one to set the 3.3v pin high or use an optocoupler.

Thank you for the insight on the link thing. I don't know what forum it was now but it used to show the first part of the link and the rest would have been hidden behind the actual link.

Also, a lot of optocouplers I have seen seem to want to control from lower voltage to higher voltage and not the other way around. They also say the output voltage should be from 3.6v and I'm worried that 3.3v might not be enough to send a pin to high.

https://www.ebay.co.uk/itm/265516830356?hash=item3dd2094e94:g:4TIAAOSwviVh7xkI

But then this one seems like it might be a better choice?

Ah, you did not mention this before. My suggestion won't work after all.

My idea was to use the relay inside the sensor as a way to trigger the Arduino pin while keeping it isolated it from the 12V circuit, but you can't do that and have it switch the 12V current at the same time.

My question about "separate common ground" was only meant to help you realise it is a contradiction! :wink:

1 Like

The modules you have seen may have been designed to be used that way. But opto-coupler components themselves will work either way, as long as the associated components are appropriately chosen.

The first module you posted the link to would probably be damaged if you connected 12V to the input. But that's only because the module will have a resistor in series with the opto-coupler input who's value has been chosen for a lower voltage. If you connect a higher voltage to the input, too much current would flow, damaging the opto-coupler. But knowing the value of that resistor, you could calculate the correct value for a second resistor, which, if connected in series with the module's input, would make it safe to connect a higher input voltage.

Yeah sorry, I couldn't have expected you to have known that, my bad.

So 2nd relay seems the most dooable option?

A second relay is an option, yes.

Or an opto-isolator, with appropriate external resistor, if needed.

Do you always want the alarm to sound if the sensor is triggered? If there are some situations where you don't want the alarm to sound, you could use the sensor output as I originally suggested, and use a second relay, controlled by another Arduino pin, to activate the alarm, or not activate it, as appropriate. When I say relay, this would need to be a relay module with a built-in driver circuit (which might include an opto-isolator).

1 Like

Yes because this is going to be an internal alarm for when someone actually gains access. I will have other PIR sensors around the van with a PVC tube around them to narrow the beam that will flash some LEDs when triggered, then send an SMS and alarm the alarm on the second or third trigger. This way I can arm certain zones so to speak.

Thank you for your help Paul, I think you have helped me many years ago on a project. You are one of the best forum users on here. The Opto-isolator would have been great if I knew it would be getting a direct voltage but as it may fluctuate from 12.6 to 14 v can not say for sure. Placing a Zener or Schottky diode could have been another option but looking for a more plug and play option. Easier to replace parts and less soldering etc is key for this one!

That variation is absolutely trivial in respect of an optocoupler. Normal design practice would be to provide at least 100% leeway so that it would work for anywhere between 8 and 24 V, if not more.

Most optocouplers are rated for up to 50 mA on the LED, but in this application you connect the photodiode between an Arduino or ESP input and ground and use INPUT_PULLUP, so it only requires a fraction of a milliamp to switch the microcontroller input. So given a CTR of minimum 50% (which generally refers to the relatively obsolete "4N35" series) you only need a milliamp or two, so the resistor can be calibrated to pass anything from 3 to 20 mA to the LED.

3 mA at 6 V would be a 1k5 resistor and it would take 30 V to drive the LED with 19 mA, so you would have plenty of leeway. Mind you, you would need a half watt resistor if you expected to go near that 30 V. A quarter Watt 1k5 resistor would be just fine at 14 V.

1 Like

Yeah to be fair I'm just going to put a relay there. For the amount it will get used I think it will be more than fine.

If someone else reads this later on that sounds like an awesome setup, and maybe if I done a MK2 version I might incorporate it.

Regards

Hi Paul, so I'm on a night shift and it got me thinking. So the LED will be on the 12v side, so putting a .6w 1.5k resistor before the LED on the optocoupler would be ok for this project?
This one?
PC817, 2 channel opto-isolator breakout for Arduino optoisolator optocoupler ST | eBay?

It does mention 3.6v on both the input and the output and uses the pc817. Am I right in thinking the transistor in the chip will conduct at 3.3v?

Or something like this, which does say it can work on 3v
TLP281, 4 channel opto-isolator breakout for Arduino, optoisolator, optocoupler | eBay?

That sounds about right.

I think you have to be cautious on a number of counts.

In the calculations I gave previously, I was taking into account that the IR LED in the optocoupler has a voltage drop of 1.2 (to maybe 1.4) V. So it can work perfectly well - with an appropriate series resistor - on just about anything over 2 V and with care, even less.

The phototransistor can pull its emitter-collector voltage down to less than 1 V. So when you see voltages and such quoted as in those links, it refers to the expectations for which those particular modules were designed.

Note that each of those modules contains additional components and in the case of the second one, additional transistors. Both of them have a common (negative) ground for the input side and the first has jumpers to common the (same) ground to each output side. On the second, the output grounds are simply all commoned (and not connected to the input).

So whether either would suit your application remains a question - all my explanations presume you are simply using the optocoupler component itself and choosing what resistor or resistors to connect to it. And I thought you only wanted to control or sense one channel?

1 Like