# Soil moisture, issue when USB connected

**URL:** <https://forum.makecode.com/t/soil-moisture-issue-when-usb-connected/12304>\
**Category:** micro:bit\
**Created:** [February 21, 2022, 11:53pm UTC](https://forum.makecode.com/t/soil-moisture-issue-when-usb-connected/12304 "2022-02-21T23:53:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpbihin](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@jpbihin](https://forum.makecode.com/u/jpbihin)\
**Post date:** [February 21, 2022, 11:53pm UTC](https://forum.makecode.com/t/soil-moisture-issue-when-usb-connected/12304/1 "2022-02-21T23:53:43Z")

</div>

Hello,  
I’m on this: [https://makecode.microbit.org/projects/soil-moisture/code](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](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/2/2026c3efe776544cf424fe6fc935c33e82748cea.jpeg)

---

<div class="post-metadata">

**Author:** ![bsiever](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bsiever/32/1032_2.png) [@bsiever](https://forum.makecode.com/u/bsiever)\
**Post date:** [February 22, 2022, 5:35pm UTC](https://forum.makecode.com/t/soil-moisture-issue-when-usb-connected/12304/2 "2022-02-22T17:35:46Z")

</div>

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:
> 
> - [AdaFruit’s CircuitPlayground Floating Input](https://learn.adafruit.com/circuit-playground-digital-input/floating-inputs)
> - ProgrammingElectronics has a good video: [Floating Pins, Pull-Up Resistors and Arduino](https://www.programmingelectronics.com/floating-pins-pull-up-resistors-and-arduino/)

Bill

---

<div class="post-metadata">

**Author:** ![jpbihin](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@jpbihin](https://forum.makecode.com/u/jpbihin)\
**Post date:** [February 22, 2022, 10:40pm UTC](https://forum.makecode.com/t/soil-moisture-issue-when-usb-connected/12304/3 "2022-02-22T22:40:08Z")

</div>

Thanks Bill, Very instructive !  
Regards
