Soil - moisture (#418)
* updated servo calibrator * updated plot analog pin example * updated servo example * first drop of soil moisture * updated picture * fixing macros * update code section * 5 seconds * adding soil moisture * fixing links
This commit is contained in:
parent
7ac6ae8895
commit
676eee168a
@ -19,6 +19,10 @@
|
|||||||
* [Guitar](/projects/guitar)
|
* [Guitar](/projects/guitar)
|
||||||
* [Duct tape wallet](/projects/wallet)
|
* [Duct tape wallet](/projects/wallet)
|
||||||
* [Watch](/projects/watch)
|
* [Watch](/projects/watch)
|
||||||
|
* [Soil Moisture](/projects/soil-moisture)
|
||||||
|
* [Voting Machine](/projects/voting-machine)
|
||||||
|
* [Infection](/projects/infection)
|
||||||
|
* [Fireflies](/projects/fireflies)
|
||||||
* [Inchworm](/projects/inchworm)
|
* [Inchworm](/projects/inchworm)
|
||||||
* [Milk Carton Robot](/projects/milk-carton-robot)
|
* [Milk Carton Robot](/projects/milk-carton-robot)
|
||||||
* [Milk monster](/projects/milky-monster)
|
* [Milk monster](/projects/milky-monster)
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
# Plot Analog Pin
|
# Plot Analog Pin
|
||||||
|
|
||||||
|
Use this program to graph the analog value on pin ``P0``, ``P1`` or ``P2``.
|
||||||
|
Press ``A`` to scroll the value on the screen.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
|
let reading = 0
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
|
reading = pins.analogReadPin(AnalogPin.P0)
|
||||||
led.plotBarGraph(
|
led.plotBarGraph(
|
||||||
pins.analogReadPin(AnalogPin.P0),
|
reading,
|
||||||
1023
|
1023
|
||||||
)
|
)
|
||||||
|
if (input.buttonIsPressed(Button.A)) {
|
||||||
|
basic.showNumber(reading)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
@ -1,14 +1,21 @@
|
|||||||
# Servo calibrator
|
# Servo calibrator
|
||||||
|
|
||||||
|
Use this program to calibrate the angles of a servo.
|
||||||
|
Press ``A`` to reduce the angle by 5 and ``B`` to
|
||||||
|
increase it by 5.
|
||||||
|
|
||||||
|
The current angle is displayed on the screen
|
||||||
|
in a loop.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let angle = 90
|
let angle = 90
|
||||||
input.onButtonPressed(Button.A, () => {
|
input.onButtonPressed(Button.A, () => {
|
||||||
angle -= 5
|
angle -= Math.max(0, 5)
|
||||||
pins.servoWritePin(AnalogPin.P0, angle)
|
pins.servoWritePin(AnalogPin.P0, angle)
|
||||||
led.stopAnimation()
|
led.stopAnimation()
|
||||||
})
|
})
|
||||||
input.onButtonPressed(Button.B, () => {
|
input.onButtonPressed(Button.B, () => {
|
||||||
angle += 5
|
angle += Math.min(180, 5)
|
||||||
pins.servoWritePin(AnalogPin.P0, angle)
|
pins.servoWritePin(AnalogPin.P0, angle)
|
||||||
led.stopAnimation()
|
led.stopAnimation()
|
||||||
})
|
})
|
||||||
@ -16,5 +23,4 @@ basic.forever(() => {
|
|||||||
basic.showNumber(angle)
|
basic.showNumber(angle)
|
||||||
})
|
})
|
||||||
pins.servoWritePin(AnalogPin.P0, angle)
|
pins.servoWritePin(AnalogPin.P0, angle)
|
||||||
basic.showString("Press A or B to change servo angle")
|
|
||||||
```
|
```
|
||||||
|
@ -100,14 +100,24 @@ Fun games to build with your @boardname@.
|
|||||||
}]
|
}]
|
||||||
```
|
```
|
||||||
|
|
||||||
## More
|
## STEM
|
||||||
|
|
||||||
```codecard
|
```codecard
|
||||||
[{
|
[{
|
||||||
"name": "Timing gates",
|
"name": "Timing gates",
|
||||||
"url":"/projects/timing-gates",
|
"url":"/projects/timing-gates",
|
||||||
"imageUrl":"/static/mb/projects/timing-gates.jpg"
|
"imageUrl":"/static/mb/projects/timing-gates.jpg"
|
||||||
}, {
|
},{
|
||||||
|
"name": "Soil Moisture",
|
||||||
|
"url":"/projects/soil-moisture",
|
||||||
|
"imageUrl":"/static/mb/projects/soil-moisture.jpg"
|
||||||
|
}]
|
||||||
|
```
|
||||||
|
|
||||||
|
## More
|
||||||
|
|
||||||
|
```codecard
|
||||||
|
[{
|
||||||
"name": "Compass",
|
"name": "Compass",
|
||||||
"url":"/projects/compass",
|
"url":"/projects/compass",
|
||||||
"imageUrl":"/static/mb/projects/a5-compass.png"
|
"imageUrl":"/static/mb/projects/a5-compass.png"
|
||||||
@ -125,5 +135,5 @@ Fun games to build with your @boardname@.
|
|||||||
### See Also
|
### See Also
|
||||||
|
|
||||||
[Flashing Heart](/projects/flashing-heart), [Smiley Buttons](/projects/smiley-buttons), [Love Meter](/projects/love-meter), [Rock Paper Scissors](/projects/rock-paper-scissors), [Compass](/projects/compass), [Hack your headphones](/projects/hack-your-headphones), [Banana keyboard](/projects/banana-keyboard), [Telegraph](/projects/telegraph), [Guitar](/projects/guitar), [Wallet](/projects/wallet), [Watch](/projects/watch),
|
[Flashing Heart](/projects/flashing-heart), [Smiley Buttons](/projects/smiley-buttons), [Love Meter](/projects/love-meter), [Rock Paper Scissors](/projects/rock-paper-scissors), [Compass](/projects/compass), [Hack your headphones](/projects/hack-your-headphones), [Banana keyboard](/projects/banana-keyboard), [Telegraph](/projects/telegraph), [Guitar](/projects/guitar), [Wallet](/projects/wallet), [Watch](/projects/watch),
|
||||||
[Milk Monster](/projects/milky-monster), [Karel the LED](/projects/karel), [Infection](/projects/infection),
|
[Milk Monster](/projects/milky-monster), [Karel the LED](/projects/karel), [Infection](/projects/infection), [Voting Machine](/projects/voting-machine)
|
||||||
[Fireflies](/projects/fireflies)
|
[Fireflies](/projects/fireflies), [Soil Moisture](/projects/soil-moisture)
|
||||||
|
@ -390,4 +390,8 @@ basic.forever(() => {
|
|||||||
|
|
||||||
|
|
||||||
basic.showIcon(GameIcons.Pairing)
|
basic.showIcon(GameIcons.Pairing)
|
||||||
|
```
|
||||||
|
|
||||||
|
```package
|
||||||
|
radio
|
||||||
```
|
```
|
28
docs/projects/soil-moisture.md
Normal file
28
docs/projects/soil-moisture.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Soil Moisture
|
||||||
|
|
||||||
|
|
||||||
|
### ~avatar avatar
|
||||||
|
|
||||||
|
Make a funny milky-monster robot!
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Materials
|
||||||
|
|
||||||
|
* 1 @boardname@ with battery pack and batteries
|
||||||
|
* 2 long nails or silver
|
||||||
|
* 2 crocodile clips
|
||||||
|
|
||||||
|
## Activities
|
||||||
|
|
||||||
|
* [Make](/projects/soil-moisture/make)
|
||||||
|
* [Code](/projects/soil-moisture/code)
|
||||||
|
* [Connect](/projects/soil-moisture/connect)
|
||||||
|
|
||||||
|
### ~button /projects/soil-moisture/make
|
||||||
|
|
||||||
|
Let's get started!
|
||||||
|
|
||||||
|
### ~
|
96
docs/projects/soil-moisture/code.md
Normal file
96
docs/projects/soil-moisture/code.md
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
# Code
|
||||||
|
|
||||||
|
You will need to get a pot of dry dirt and wet dirt for the coding.
|
||||||
|
|
||||||
|
## Step 1: Measuring moisture
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
basic.forever(() => {
|
||||||
|
led.plotBarGraph(
|
||||||
|
pins.analogReadPin(AnalogPin.P0),
|
||||||
|
1023
|
||||||
|
)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
This code has to be inserted in the forever loop. We've also added a variable ``reading`` to store the reading value.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let reading = 0
|
||||||
|
basic.forever(() => {
|
||||||
|
reading = pins.analogReadPin(AnalogPin.P0)
|
||||||
|
led.plotBarGraph(
|
||||||
|
reading,
|
||||||
|
1023
|
||||||
|
)
|
||||||
|
if (input.buttonIsPressed(Button.A)) {
|
||||||
|
basic.showNumber(reading)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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 ``B`` and note the value. You should see a value close to ``1000``
|
||||||
|
for dry dirt.
|
||||||
|
|
||||||
|
## Step 3: Don't waste energy!
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
We want our probe to work for a long time on batteries so we need to tweak our code to save 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.
|
||||||
|
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.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
led.setBrightness(64)
|
||||||
|
let reading = 0
|
||||||
|
basic.forever(() => {
|
||||||
|
pins.analogWritePin(AnalogPin.P1, 1023)
|
||||||
|
reading = pins.analogReadPin(AnalogPin.P0)
|
||||||
|
pins.analogWritePin(AnalogPin.P1, 0)
|
||||||
|
led.plotBarGraph(
|
||||||
|
reading,
|
||||||
|
1023
|
||||||
|
)
|
||||||
|
if (input.buttonIsPressed(Button.A)) {
|
||||||
|
basic.showNumber(reading)
|
||||||
|
}
|
||||||
|
basic.pause(5000);
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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!
|
||||||
|
|
||||||
|
### ~button /projects/soil-moisture/connect
|
||||||
|
|
||||||
|
Connect
|
||||||
|
|
||||||
|
### ~
|
49
docs/projects/soil-moisture/connect.md
Normal file
49
docs/projects/soil-moisture/connect.md
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# 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@.
|
||||||
|
|
||||||
|
## Moisture sensor
|
||||||
|
|
||||||
|
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``.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
radio.setTransmitSerialNumber(true)
|
||||||
|
radio.setGroup(4)
|
||||||
|
led.setBrightness(64)
|
||||||
|
let reading = 0
|
||||||
|
basic.forever(() => {
|
||||||
|
pins.analogWritePin(AnalogPin.P1, 1023)
|
||||||
|
reading = pins.analogReadPin(AnalogPin.P0)
|
||||||
|
radio.sendNumber(reading / 4);
|
||||||
|
pins.analogWritePin(AnalogPin.P1, 0)
|
||||||
|
led.plotBarGraph(
|
||||||
|
reading,
|
||||||
|
1023
|
||||||
|
)
|
||||||
|
if (input.buttonIsPressed(Button.A)) {
|
||||||
|
basic.showNumber(reading)
|
||||||
|
}
|
||||||
|
basic.pause(5000);
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## The dashboard
|
||||||
|
|
||||||
|
The dashboard code can be found at [/examples/radio-dashboard](/examples/radio-dashboard).
|
||||||
|
|
||||||
|
Download the code from that example into the @boardname@ that will be used to display the result.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
```package
|
||||||
|
radio
|
||||||
|
```
|
14
docs/projects/soil-moisture/make.md
Normal file
14
docs/projects/soil-moisture/make.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Make
|
||||||
|
|
||||||
|
https://youtu.be/S8NppVT_paw
|
||||||
|
|
||||||
|
* Connect a nail to the ``GND`` 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
|
||||||
|
|
||||||
|
That's it!
|
||||||
|
|
||||||
|
### ~button /projects/soil-moisture/code
|
||||||
|
|
||||||
|
Code
|
||||||
|
|
||||||
|
### ~
|
BIN
docs/static/mb/projects/soil-moisture.jpg
vendored
Normal file
BIN
docs/static/mb/projects/soil-moisture.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
BIN
docs/static/mb/projects/soil-moisture/nailsp1.jpg
vendored
Normal file
BIN
docs/static/mb/projects/soil-moisture/nailsp1.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 114 KiB |
BIN
docs/static/mb/projects/soil-moisture/nailsv3.jpg
vendored
Normal file
BIN
docs/static/mb/projects/soil-moisture/nailsv3.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 110 KiB |
BIN
docs/static/mb/projects/soil-moisture/soil-moisture.jpg
vendored
Normal file
BIN
docs/static/mb/projects/soil-moisture/soil-moisture.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 105 KiB |
Loading…
x
Reference in New Issue
Block a user