Soil moisture, issue when USB connected

Hello,
I’m on this: https://makecode.microbit.org/projects/soil-moisture/code with a v2.
From step 1, I notice something I cannot explain. The measurement of oscillates strongly, between 400 and 800 /1023 while the two connected cables are free (not planted in the soil…the circuit is open.

I would rather expect a flat profile…

This “parasitic oscillation” disappears when:

  • I remove the cable from pin 0 or when
  • I disconnect the board from the USB and power it with the battery box.

Can you help me figure out what’s going on and remove the oscillation? The oscillation frequency is +/- 70Hz… (home network = 50 Hz)???

Thanks in advance !

JP
analog reading

I think this is due to a “floating input”. Below is one of my prior replies about this sort of thing that may help. One way to remove it would be a very high resistor value between the two probes at all times, so when they are not in soil there’s a path / connection and when they are in soil that is the “path of least resistance”.

This idea of a “floating input” is related to voltage being a relative measure rather than absolute. The “ground” isn’t absence of electricity, it’s just where we decide to start measuring from. The 3V is “3 more than at GND”, not 3 of something in total.
Here are two things that may help you understand this idea of “floating inputs” a bit better:

Bill

Thanks Bill, Very instructive !
Regards