Merge pull request #582 from Microsoft/projects-edits-02

Some edits to 'soil moisture' projects
This commit is contained in:
Galen Nickel 2017-12-04 12:27:26 -08:00 committed by GitHub
commit 18beffb7b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 48 deletions

View File

@ -1,17 +1,15 @@
# Code
Let's add the code so that _when the soil moisture level is low, the servo waters the plant._
Let's add code so that when the soil moisture level is low, the servo waters the plant.
From the **soil moisture** project, we know that the moisture is low when the ``reading`` is roughly less than ``500``.
We can use this information to add an ``if reading < 500`` in the code.
From the **[soil moisture](/projects/soil-moisture)** project, we know that the moisture is low when the ``reading`` is roughly less than ``500``. We can use this number to add an ``if reading < 500`` in the code to decect a dry condition.
```block
let reading = 0
if (reading < 500) { }
```
The servo is connected to pin ``P2`` so we can use ``pins servo write`` block to change the angle of the servo.
We need it to change the angle to ``0``, wait until the water has fallen off, and move it back to ``80``.
The servo is connected to pin **P2** so we can use the ``||pins:servo write||`` block to change the angle of the servo. We want the angle to change to ``0``, wait until the water pours off, and then move the angle back to ``80``.
```block
let reading = 0
@ -25,7 +23,7 @@ if (reading < 500) {
}
```
We insert the code above in the **forever** loop of the [soil moisture code](/projects/soil-moisture/connect).
Insert the code above in the ``||basic:forever||`` loop of the [soil moisture](/projects/soil-moisture/connect) code.
```blocks
radio.setTransmitSerialNumber(true)
@ -56,6 +54,8 @@ basic.forever(() => {
})
```
Here's a video showing the @boardname@ watering a plant.
https://youtu.be/7eC_VjH1eP0
```package

View File

@ -1,21 +1,18 @@
# Make
## The pump
Follow the instructions on the move to build a mini water-pump using a @boardname@ and a servo.
Follow the instructions in the video to build a mini water-pump using a @boardname@ and a servo.
https://youtu.be/jANCdtkJAKY
## The soil moisture sensor
Follow the instructions of the [soil moisture project](/projects/soil-moisture) to build a soil moisture sensor
and upload the code to your @boardname@.
Use the instructions of the [soil moisture project](/projects/soil-moisture) to make a soil moisture sensor and upload the code to your @boardname@.
The final wiring should look like this:
![](/static/mb/projects/plant-watering/make.jpg)
![Soil moisture meter](/static/mb/projects/plant-watering/make.jpg)
## ~button /projects/plant-watering/code

View File

@ -1,17 +1,15 @@
# Code
You will need to get a pot of dry dirt and wet dirt for the coding.
You will code your moisture meter using a pot of dry dirt and wet dirt. This is so you can set the @boardname@ to know what both dry and wet conditions are.
## Step 1: Measuring moisture
![](/static/mb/projects/soil-moisture/nailsv3.jpg)
The soil acts as a variable resistor based on the amount of water and nutrient.
The water is not conductive but the nutrient are, so more water, more nutrient, so the soil will be less resistive.
The soil itself has some electrical resistance which depends on the amount of water and nutrients in it. It acts like a variable resistor in an electronic circuit. The water is not conductive but the nutrient content is. The combination of water and soil nutrients makes the soil have some conductivity. So, the more water there is, combined with the nutrients, the less the soil will have electrical resistance.
To measure this, we read the voltage on pin ``P0`` using [analog read pin](/reference/pins/analog-read-pin)
which returns a value between ``0`` (no current) and ``1023`` (max current). The value is graph on the screen
using [led plot bar graph](/reference/led/plot-bar-graph).
To measure this, we read the voltage on pin **P0** using ``||pins:analog read pin||``
which returns a value between ``0`` (no current) and ``1023`` (maximum current). The value is graph on the screen using ``||led:plot bar graph||``.
```blocks
basic.forever(() => {
@ -22,17 +20,16 @@ basic.forever(() => {
})
```
## Experiment!
### Experiment!
* insert the nails in the dry dirt and you should see most LEDs off
* insert the nail in the wet dirt and you should see most LEDs on
* Insert the nails in the dry dirt and you should see most LEDs turn **off**.
* Insert the nail in the wet dirt and you should see most LEDs turn **on**.
## Step 2: Sensor data values
In the previous program, we only have a rough idea of the value of the sensor... since it is using a tiny screen
to display it! Let's add code that displays the current reading when button ``A`` is pressed.
In the previous program, we only have a rough idea of what the sensor value is. It's using just a tiny screen to display it! Let's add code that displays the current reading when button **A** is pressed.
This code has to be inserted in the forever loop. We've also added a variable ``reading`` to store the reading value.
This code needs to go into the ``||basic:forever||`` loop. We've also added the variable ``reading`` to store the reading value.
```blocks
let reading = 0
@ -48,26 +45,25 @@ basic.forever(() => {
})
```
## Experiment!
### Experiment!
* insert the nails in the dry dirt, press ``A`` and note the value. You should see a value close to ``250``
for dry dirt.
* insert the nails in the wet dirt, press ``A`` and note the value. You should see a value close to ``1000``
for wet dirt.
* Insert the nails in the dry dirt, press **A** and note the value. You should see a value close to around ``250``for dry dirt.
* Insert the nails in the wet dirt, press **A** and note the value. You should see a value somewhere near ``1000`` for wet dirt.
<br/>
https://youtu.be/S8NppVT_paw
## Step 3: Don't waste energy!
![](/static/mb/projects/soil-moisture/nailsp1.jpg)
We want our probe to work for a long time on batteries so we need to tweak our code to save energy.
We want our soil probes to work for a long time and to save our battery power, so we need to tweak our code so our moisture sensor doesn't use too much energy.
* Our circuit connects directly to the ``3v`` pin so it is always using electricity. Instead,
we will connect it to ``P1`` and turn that pin high only while the measurement is taken.
* Our circuit connects directly to the **3V** pin so it is always using electricity. Instead,
we will connect it to **P1** and turn that pin **high** only while the measurement is taken.
This saves electricty and also avoids corrosion of the probes.
* We will also lower the brightness of the screen to lower the energy consumption from the LEDs.
* Soil moisture changes very slowly so we don't need to measure all the times!!! Let's add a **sleep** of 5 seconds in the loop as well.
* Soil moisture changes very slowly so we don't need to measure it all the time!!! Let's add a **sleep** of 5 seconds in the loop as well.
```blocks
led.setBrightness(64)
@ -87,9 +83,9 @@ basic.forever(() => {
})
```
## Experiment!
### Experiment!
* using the dry and wet dirt pots, test that your ciruit still works. Remember you'll have to wait up to 10 seconds to see a change!
* Using the dry soil and wet soil pots, test that your circuit still works. Remember you'll have to wait up to 10 seconds to see a change!
## ~button /projects/soil-moisture/connect

View File

@ -1,15 +1,12 @@
# Connect
We are going to use radio to send the current moisture
level to a dashboard @boardname@. The dashboard
will display one LED per @boardname@.
Use the radio to send the current moisture level to a dashboard @boardname@. The dashboard will display one LED per @boardname@.
## Moisture sensor
To make it happen, we need to change the program to
To make it happen, we need to change the program to:
* setup the radio by choosing group 4 and sending the serial number of the device
* send the moisture level **divided by 4**
as the dashboard takes values between ``0`` and ``255``.
* send the moisture level **divided by 4** as the dashboard takes values between ``0`` and ``255``.
```blocks
radio.setTransmitSerialNumber(true)
@ -34,15 +31,17 @@ basic.forever(() => {
## The dashboard
The dashboard code can be found at [/examples/radio-dashboard](/examples/radio-dashboard).
The dashboard code is found in the [radio dashboard](/examples/radio-dashboard) example.
Download the code from that example into the @boardname@ that will be used to display the result.
### Setup a dashboard @boardname@
When the dashboard receives a message from a @boardname@, it find a pixel for that board (and remembers it)
and uses the number received as the brightness of the LED.
Download the code from that example into the @boardname@ that will be used to display the results.
When a message hasn't been received by a board for some time, it's pixel will start to blink. After more time, it will simply turn off.
### Dashboard operation
When the dashboard receives a message from a @boardname@, it finds a pixel to use for that board (and remembers it). The number sent in the messages from the board are used to set the brightness of the LED.
When a message hasn't been received by the dashboard for awhile, it's pixel will start to blink. Then, after some time, it will simply turn off.
```package
radio

View File

@ -2,8 +2,11 @@
https://youtu.be/S8NppVT_paw
* Connect a nail to the ``3V`` pin with a croc clip and insert it in the soil
* Connect the other nail to the ``P0`` pin with a croc clip and insert it in the soil
<br/>
Here's what you need to do to make your soil moisture sensor:
* Connect a nail to the **3V** pin with a croc clip and insert it into the soil.
* Connect the other nail to the **P0** pin with a croc clip and insert it into the soil.
That's it!