Analog read pin messing with sensor

Hello everyone.

I am setting up a few very simple things with a Uno but I'm having a very frustrating issue. The principle is the following: the power supply of a temperature sensor is piloted with a logic-level mosfet (IRLZ34N) by the Arduino. Arduino GND is common with the 24V power supply and the Arduino has so far been powered by being plugged to my laptop.

You can see below on the left the setup when the analog read is not connected; the yellow figures are the voltage readings: when the output pin is set to 5V, the transistor is conducting which loads the sensor with the supply voltage and allows the reading to be made (here, ~2.5V which is the room temperature of 25°C). When the pin is at 0, the transistor is blocking and the 24V power supply is found as V_DS. So far so good...

When I connect the A0 pin however, it all goes to shit as can be seen on the right figure. I've no notion of what is happening, the transistor is not blocking anymore and the sensor is partially powered... What is going wrong here ?

Thanks a lot for your suggestions, this is making me crazy ^^

When the transistor is off, you are effectively cutting the ground connection - leaving the sensor "floating".

I'd guess that when you connect the A0 you get some sort of leakage to ground, so the sensor is "partially" powered - giving weird results.

I think it would be better to switch the positive supply to the sensor - so that you have a permanent common ground reference.

Are you meaning that I should try this instead ?

Take a look at this - you need a high-side switch:

1 Like

Use one of these to turn the 24V ON/OFF

1 Like

1 Like

Thank you for all the answers ! I guess I should go & buy some P-channel mosfets to try this out then...

@LarryD I'm not sure about why a BJT is necessary in front of the Arduino; could you clarify this ? What is this circuit doing in the first place exactly ?

Thanks !

First a couple of things, the image shows 3 different circuits that serve the same function.

MOSFETS have a rating called Vgs maximum.

Since you are using a 24v power supply, we must ensure this maximum is not exceeded, hence we add a zener diode to protect the MOSFET.

If the MOSFET has a Vgs maximum greater than 24v you can omit the zener.

The Arduino output is 5v to 0v or in some cases, 3v3 to 0v.

A gate voltage of 5v will not turn OFF the P MOSFET in this configuration.

We therefore add a BJT to translate the 5v level to 24v.

The top left P channel MOSFET is for reverse input voltage protection (if needed).

The middle P channel MOSFET controls the 24v power going to the load.

In circuit C, the resistors have to be chosen so the required Vgs turn on voltage is achieved.

This just popped up on Twitter...

Or just get a chip; eg,

I use these, AO4614B , about $0.40 each.

Thanks again for all the suggestions; as you can probably tell I am not very literate when it comes to electronics, so I have two additionnal questions:

  • As an alternative, would using relays work ? I'm already using one to pilot a 220V powered appliance; it looks like total overkill for a 24V sensor, but given that this voltage is problematic for high-side mosfet configurations, it would minimize the "hassle" (and satisfy my cowardly laziness).
  • I'm not sure I understand how the chips you showed are different from two mosfets in a common packaging. Which means i would not know how to use them. Do you know of any arduino tutorials using those ? I'm not even sure what they are generally called as an element, so my searches are not yielding anything relevant.

Thank you so much for educating me ^^

Which temperature sensor are you using?

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