# Micro:bit V2 and soil sensor using nails?

**URL:** https://forum.makecode.com/t/micro-bit-v2-and-soil-sensor-using-nails/8921
**Category:** micro:bit
**Created:** [June 25, 2021, 5:40pm UTC](https://forum.makecode.com/t/micro-bit-v2-and-soil-sensor-using-nails/8921 "2021-06-25T17:40:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mathpun](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@mathpun](https://forum.makecode.com/u/mathpun)
#### Post date: [June 25, 2021, 5:40pm UTC](https://forum.makecode.com/t/micro-bit-v2-and-soil-sensor-using-nails/8921/1 "2021-06-25T17:40:38Z")

</div>

Hi! I am working with this project:

> **[Code](https://makecode.microbit.org/projects/soil-moisture/code)**
>
> You will code your moisture meter using a pot of dry dirt and wet dirt. This is so you can set the micro:bit to know what both dry and wet conditions are.

which is great and uses 2 nails connected to ‘0’ and ‘3V’ on the micro:bit but I am wondering if its possible to do this with just 1 nail? If yes, where would the nail be connected to and would the code change? Thanks!

---

<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: [June 27, 2021, 6:27am UTC](https://forum.makecode.com/t/micro-bit-v2-and-soil-sensor-using-nails/8921/2 "2021-06-27T06:27:40Z")

</div>

The code in the example is using `analogRead()`, which reads the voltage on the `P0` nail and compares it to the 3 volts from the `3V` nail.

Here’s a way to think about it: The `3V` (they use `P1` at the end) “puts” three volts into the soil. The `P0` measures how much of that 3 volts was “lost” as it travelled through the soil to the `P0` nail. It is doing a comparison (somewhat like subtraction) to see how much it’s changed…it needs both the “start” (`3V`) and end (`P0`) to do the comparison needed here.

If you haven’t studied voltage and current before, you might take a look at some tutorials. I like SparkFun’s: [Voltage, Current, Resistance, and Ohm’s Law](https://learn.sparkfun.com/tutorials/voltage-current-resistance-and-ohms-law), which has a few videos that may help.

Bill

---

<div class="post-metadata">

### Author: ![Mrdilizio](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@Mrdilizio](https://forum.makecode.com/u/Mrdilizio)
#### Post date: [December 21, 2021, 6:40pm UTC](https://forum.makecode.com/t/micro-bit-v2-and-soil-sensor-using-nails/8921/3 "2021-12-21T18:40:08Z")

</div>

Hey!

I was working on a similar project and ended up making a video for it.  
As mentioned you will need to measure the current flowing between two probes (hence the two nails). Using a ready made gives better contact and more sensitivity though it can definitely be done without.  
[Micro:bit self watering](https://www.youtube.com/watch?v=Kt17GFAu-D8)

---

<div class="post-metadata">

### Author: ![mathpun](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@mathpun](https://forum.makecode.com/u/mathpun)
#### Post date: [January 19, 2022, 6:11pm UTC](https://forum.makecode.com/t/micro-bit-v2-and-soil-sensor-using-nails/8921/4 "2022-01-19T18:11:08Z")

</div>

WOW love this, will take a look now!
