Voltage divider as INPUT to arduino 12V->5V

Hello,

I'm trying to lower the voltage from inductive PNP NO sensor. It is suppled by 12V and also provides 12V when it detects metal within its distance. I'm working with arduino mega 2560 and therefore I need to lower it to 5V so I can read the signal as digital LOW or HIGH.

I was thinking of using a voltage divider with R1=1k and R2=700 , which comes to around 5V.
Connecting it to the D9 pin. If anyone is able to comment on whether I'm connecting it in the correct way. I read that I need to connect it all to the same ground but I'm afraid of burning my arduino.

I've attached a picture of the schematic, however it says 9V instead of 12V and try to imagine that the LED in the scheme is an inductive sensor(It has 3 wires, 1 connect to GND, 2dn to 12V+ and the 3rd output is the red wire of the LED),so its output is connect to R1 and R2 and inbetween the signal is taken to arduino. Again I'm concered if it is correct setup.

int signal=10;
int reading;
void setup() {

  pinMode(signal,INPUT);
  Serial.begin(9600);
}

void loop() {

  reading=digitalRead(signal);
  Serial.println(reading);
  delay(1000);
}

A voltage divider should work. I assume your sensor is OK with a 1.7K load?

But with inductors you have to careful of negative voltage spikes.

Another option for digital (on/off) signals is a protection circuit. There are versions for protecting against over-voltage and-or negative voltages. (You can increase the current limiting resistor to between 1K and 10K.)

A protection circuit is better option in automotive applications where the "12V" varies.

1 Like

Yes the sensor should be fine with 1.7k load.

Honestly, thank you for commenting , because I had no idea about negative voltage spikes with ind sensors.

The protection circuit you linked, protects from negative voltage lower than -0.7V if I undestood the post corectly. Will small negative voltage up to -0.7V have an negative effect on an arduino

The maximum (or minimum) negative voltage that you should apply to the arduino pins is -0.5V, regarding the datasheet of the ATmega2560. So you should protect it if the sensor can have negative spikes. You can do it with a Schottky diode, that has a voltage drop of only 0.3V.

The Schottky diode will conduct only when the voltage is lower than GND by about 0.3V.

And this will protect only for negative voltage, not for overvoltage. But you could lower a bit the voltage in the divisor, to 4.5V for example, because the pin will trigger anyway above 4.0V. Just in case.

Read the datasheet of sensor carefully. Or post the link here.

1 Like

Could You post a link to the datasheet of the sensor?
I have used some similar sensors and found the easy adaptation is a 5.6k resistor to GND. This due to the internal resistor in the sensor. Maybe it's not exactly the same type, but ......

1 Like

Try putting something in the 50K range in series with the voltage divider and the Arduino Pin. The diode would not be needed. With an input of of 100V you would see 1mA into the Arduino if the divider was not there. The divider will drop the current even more. As a rule of thumb I use 10mA as the max current for the input protection diodes. If you do this on a several ports you need to be sure the VCC does not go above its limit.

1 Like

Here is the sensors data sheet. I might be unexperienced, but ti doesnt tell me much.

here it is : IGYX 08P17B3/L | Inductive proximity switch | Baumer USA

Good idea.

I was worried of current being too low for an arduino to register it

1 Like

You can always use a lower value resistor, try a 10K. I generally use a higher value when on a circuit board.

1 Like

What is missing?

Here is the simulation I did with falstad. If I m not mistaken the maximum negative voltage that the inductive sensor can get is 2.5V ( it says that voltage drop is <2.5V in datasheet). In that case even if it the worst case scenario with schottky diode as you mentioned it is still below -500mV

I will try, thanks.

Ur probabbly right, nothing is missing, I'm just first time working with inductive sensors

Yes, the -445mV that you see in the simulation should be the drop voltage of the Schottky diode.

When you search for the diode, check the forward voltage in the datasheet. It can be anything, but make sure that it is below 0.45V.

For example, this ones: 1N5817, 1N5818 or 1N5819:


At 0.1A the forward voltage is 0.32V, 0.33V, 0.34V And I the current from your sensor will be below 200mA, so you are fine with that.

1 Like

I always make R1 large enough to limit current through the input pin's protection diodes to less than 1mA in the case of circuit failure between R1 and GND, even if Arduino is unpowered. For 12V, that would be 15k, so R2 could be 10k. 10k / (10k + 15k) = 0.4 * 12V = 4.8V.

1 Like

Thank you.

Good idea, I m gonna implement it

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.