Strange behaviour of sensor for usb power vs Vin power

Hi,

I hope i am in the correct catagory...

I am working on a project for automating the watering of two plants, there will be more but this is the basics of the project.

The problem i have is that the soil moisture sensors have their values going down when getting wet and powered by the pc-usb cabe only, so far so good works like a charm.
But when i power the Arduino with a seperate powersuply, the values of the sensors go up when getting wet... So it seems to reverse the values somehow and i can't seem to figure out why.

I am using an Arduino Nano (clone i think).
The sensors are Capacitive soil moisture sensors. I power the sensors with a digital output (D2 and D3) so they only power up when needed. Signal comes in on A0 and A1.
There are 2 relay's for powering the pumps (each plant get's it's own pump).

There is also an ESP32 connected with tx and rx for communication but i am testing the arduino stand-alone before connecting to the ESP32. I have allready connected everything and it works perfectly as long as i don't power up the external powersupply, at the moment this powersupply is connected to the Arduino and the relay's (grounds are all connected).
I have a good quality 5V 10A powersupply.
But because i am using the Vin on the Arduino, i have allready changed to a 9V powersupply for the Arduino's. Unfortunately that did not help.

I have also tried to power the sensors directly from the 5V powersupply, but again, no change in behaviour.

I don't think this is a programming problem as it is working correctly when powered by the pc usb.
And for testing i'm reading the value of A0 (with analogRead(0)) and print it directly to the serial monitor.

I hope someone can help me solve this problem.
Thanks

Hi OmeJozz,

So you have this behaviour in a stand-alone setup (just the Nano) ?
And you have external power to the Nano while it is still connected to USB ?
Not sure what is causing the issue, but here is some advice on powering the Nano.

At the moment for this test I am using only the nano.
When I test it with only the USB connected it works fine, but when I add the external power the sensor seems to inverse the reading..

Thanks for the link. I have tried to power the nano through the +5 pin with regulated 5V. But it has the same result.

I think I'll have to use the USB connector to power the nano eventually. I'll see if I can find an old USB cable I can cut up to connect the 5V. Then reconnect the Esp32 and see if I get the correct values.
But that will be a project for tomorrow.

Still no clue why the sensor readings are reversed but this may be the solution for me.
I'll reply with my findings after testing.

It may be the (protective?) GND coming from the USB cable that makes a difference. You can check when powering the Arduino by the 9V PSU and connect and disconnect the USB cable.

How do you connect the capacitive sensors?

I think I tried that already, actually this is when I noticed the problem.
I have had the nano together with the eps32 working. The esp32 send a signal via serial communication to the nano to start up the sensors and the nano replied with (the wrong) sensor readings. At that moment the nano was powered by the external 5v supply in Vin (I know that is a bit too low voltage but it seemed to work). And no connection on the USB of the nano.

But I will try tomorrow to power the nano with a USB cable and see if the esp32 will get the correct sensor values.

The capacitive sensors are connected together to one of the gnd pins of the nano, signal is connected to A0 and sensor 2 to A1. Vcc is connected to D2 and D3, so I can supply power only when needed (many 2 or 3 times per day).

With 5V to 3.3V level converters?

Vcc of what? Digital I/O pins don't provide enough current to power most peripheral devices, and drawing too much current from them can damage them.

I think it's about time to ask you for a proper wiring diagram. Chances are good, the problem will show up there.

Make sure that every device (the sensors, Nano, esp32, usb) has a good connection to one single common ground.

Then just the on-board regulator may cause problems!

Spend a twisted pair for each sensor, no common ground in the field.

A picture is worth a thousand words

A block diagram would also be useful

TL:DR

If you powered the Nano with 5V on the 5V pin, it should have worked.
Do you have a volt meter? Please post a detailed wiring diagram, pencil & paper, photographed with cell phone and posted as a .jpg or .png file will do.

I hope it works with uploading the drawing.
Sorry for the bad quality.
i have only connected the lines for the power supplies and the grounds of the sensors to prevent a spiderweb of lines on the drawing.

There is a 12V powersupply to provide power to the pumps, i also need it for the small board that transformes it to 3.3V. I use the 3.3V to power a Logic Level Converter so ican connect the Tx and Rx of the Nano to the ESP. The 5V side of the Logic Level Converter is connected to the 5V powersupply.

I have cut up a usb cable to use to power the Nano for testing today, but the results are confusing.
I connected one side of the cable to the 5V power suply and plugged the other side in the usb connector of the Nano.
This time the Nano received the command to start taking measurements, but now it sends no sensor information back to the ESP at all?!??

Now it gets complicated...
I have a second Nano in this circuit. nano 2 has a pessure sensor and a relay connected. This should give me the waterdepth in a barrel (to see if it needs refiil or we can go on and water the plants). The relay is similar to he others, it gets the 5V and ground from the 5V power supply. The sensor gets it's 5V from the +5V pin and a ground pin from the Nano2. Rx and Tx are connected to the Rx and Tx line from Nano1 (and together they are connectedto the Logic Level Converter).

I have tried some different powersuply combinations, but the results make no sense to me.
In all setups, both Nano's receive commands through serial communication from the ESP32.
But the Nano's seem to send data back only in some setups.

Nano1 = moisture sensors.
Nano2 = pressure sensor.
usb = usb cable connected to 5V powersupply and the other side to the usb connector on theNano.
9V = 9V connected to the Vin and Gnd on Nano, from step down board connected to 12V powersupply.

Nano1 - usb & Nano2 - usb
Nano1 - no data received
Nano2 - data received

Nano1 - 9V & Nano2 - usb
Nano1 - data received (still reversed, levels go down when they should be going up)
Nano2- no data received

Nano1 - 9V & Nano2 - 9V
Nano1 - no data received
Nano 2 - data received

Nano1 - usb & Nano2 9V
Nano1 - no data received
Nano2 - data received

So only when i use the Vin on Nano1 and usb on Nano2 i get serial data back from Nano1, but then not from Nano2. And still the sensor readings seem to inverse (value going up when sensor gets wet when i should be going down).

I have connected the grounds from both the 12V and the 5V powersupply together, no change.

Oh, before i forget, the 9V comes from a small DC-DC Step Down Module connected to the 12V powersupply.

This is getting realy frustrating.
I do have a basic knowledge of electronics and i work as a service engineer, so problemsolving is what i do... But this one has got me beat. I hope (and assume) you all are much smarter then me and can find the mistake i'm making. I can't seem to find it.


Sorry for my possibly dumb suggestions.

Have all grounds connected?
Nanos show 5V on their 5V pins?
Rx and Tx crossed over (null modem) between Nanos?
2 Nanos and a level converter are too many Serial stations - please explain.

All grounds are connected. The only exception is the pressure sensor, this is only connected to a gnd pin on Nano2.

Rx and TX from the ESP (3,3V) are connected to the level converter. On the other side of the level converter (5V) Rx and TX from both the Nano's are connected.
So Rx from Nano1 and Rx from Nano2 are connected to Tx of the Esp32 (through the level converter). And Tx from both Nano's to Rx from Esp32.
The ESP has to be able to give orders to both Nano's (1 at a time), the Nano's only have to reply to the Esp32.

I have not checked the 5V pin of the Nano's, I will do that.

That's wrong! Both Tx are outputs which work against each other.

I don't see:
A GND connection between Nano and 5V PS.
A GND or Vcc between Nano and relays.
A 3V3 between level shifter and ESP.
A 5V between level shifter and Nano.

I think I made too many errors for an easy fix.
It is probably better to break it all down and start over, to be honest the wiring is getting a bit of a mess by now.

Thank you all for your replies.
I'll be back with new questions when I mess up again.

Well... I couldn't leave it beand i decided to simplify things a bit.
I am sharing this to let you know that my problems seem to solved for the moment.
And everything works like a charm, even the soilsensor value's come back correct now (no longer inversed in vallue).
So i think the sensor problems were probably a result of connecting the Tx from two Nano's together.

I have removed one of the Nano's and connected all the sensors and relay's to one Nano and communicate with Tx and Rx with the ESP32 (through a logic level converter). Works great.

I am thinking of using RS-485 modules for future multiple arduino projects, seems to do exactly what i need.

Thanks for the help.