How to turn analog pins on and off?

This may seem like a basic question, so let me expand:

I am working with an EC sensor and a PH sensor. Apparently there is an issue with these sensors sharing a power supply. When both sensors used at the same time the pH increases.

I am trying to find a software way around this. I am trying the following:

setup

pinMode(EC_PIN, OUTPUT)

pinMode(PH_PIN, OUTPUT)

void loop

digitalWrite(EC_PIN, LOW)

digitalWrite(PH_PIN, HIGH)

read_ph()

digitalWrite(EC_PIN, HIGH)

digitalWrite(PH_PIN, LOW)

read_ec()

Read_ph and read_ec are just functions that calculate EC and PH. Basically I am trying to alternate when the reading are taken to avoid the aforementioned issue. I have snooped around online, but I haven't found something that works.

Should this work? So far i am having no luck, but maybe I am missing something. Is there a software method for solving the issue I mentioned above?

Thank you for your help. Let me know if you need to know anything else

Sounds like a bad plan. Sagging voltage supplies are too unpredictable to compensate properly in software.

Please explain exactly what supply you are using, the power requirements of each module, and whether "apparently" means it's something you read, or something you see on your workbench.

That's less than what is usually asked of you, a complete diagram. It would at least give people here something to get started with...

The issue could be power, see post #2.

On another note and something else to look for. If both sensors are analog devices they share a A:D converter on the MCU. The A:D converter has a sample and hold cap that needs to be bleed off between A:D reads. Somewhere there is a spec on how fast the A:D takes a reading has it ready for a read and, after a read is ready to go again.

Perhaps, if all is going well with the power, the A:D converter needs to be cleared between reads.

Say one device is on A0 and the other is on A1 and A2 is grounded. A sequence could go like this read A2, read A0, read A2, read A1 repeat.

Tick/tock

bool tick = true

if tick then read one sensor and set tick to false
else read the other sensor and tick to true.

As a matter of interest, it sounds like you are able to power up/down the sensors. Two issues come to mind. One, can the sensors handle that without errors (e.g. is there any start up or warm up time etc.). Two, can your digital interface handle an interface between powered and non-powered devices correctly?

Well, considering that this is @ardytemp ´s first post in this forum (welcome by the way!), I believe we should consider a more simple hypothesis.

If EC-PIN and PH_PIN are the pins of the sensors that provide the data, they should be set as INPUT pins intead of OUTPUT ones.

At this point, @aarg has a point: it´s always recomended to give more details on your electrical circuit and connections.

It's because they are set to OUTPUT and using digitalWrite() that I made that guess.

Look at the thread title. It makes no sense at all.

The full code is missing, and that's another lost opportunity to understand what is going on.

1 Like

conductivity and pH sensors both make a circuit with the solution they are dipped in - you cannot use both at the same time in the same solution without them interfering with each other, unless they have completely isolated power supplies and electronics each, and are far apart in the container.

pH sensors in particular are incredibly high impedance and need isolation to a high standard (requiring teflon hardware for instance).

1 Like