Skip to content

Commit e9b900c

Browse files
authored
Merge pull request #3073 from adafruit/soil_sensor
simple soil sensor examples
2 parents caffaec + 3efeca6 commit e9b900c

File tree

6 files changed

+134
-0
lines changed

6 files changed

+134
-0
lines changed

Simple_Soil_Sensor_Demos/Arduino/microBitAdvSoilSensor/.none.test.only

Whitespace-only changes.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
/* micro:bit Advanced Soil Sensor Demo */
6+
7+
#include <Adafruit_Microbit.h>
8+
9+
Adafruit_Microbit_Matrix microbit;
10+
11+
int sensorPin = 0;
12+
int onPin = 2;
13+
int moisture = 0;
14+
15+
const uint8_t
16+
frown_bmp[] =
17+
{ B00000,
18+
B01010,
19+
B00000,
20+
B01110,
21+
B10001, };
22+
const uint8_t
23+
smile_bmp[] =
24+
{ B00000,
25+
B01010,
26+
B00000,
27+
B10001,
28+
B01110, };
29+
30+
void setup() {
31+
Serial.begin(115200);
32+
while ( !Serial ) delay(10);
33+
Serial.println("micro:bit advanced soil sensor");
34+
microbit.begin();
35+
pinMode(onPin, OUTPUT);
36+
37+
}
38+
39+
void loop() {
40+
digitalWrite(onPin, HIGH);
41+
delay(50);
42+
// read the value from the sensor:
43+
moisture = analogRead(sensorPin);
44+
Serial.print("Soil moisture: ");
45+
Serial.println(moisture);
46+
if (moisture > 200) {
47+
microbit.show(smile_bmp);
48+
} else {
49+
microbit.show(frown_bmp);
50+
}
51+
digitalWrite(onPin, LOW);
52+
delay(5000);
53+
}

Simple_Soil_Sensor_Demos/Arduino/microBitSimpleSoilSensor/.none.test.only

Whitespace-only changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
/* micro:bit Simple Soil Sensor Demo */
6+
7+
#include <Adafruit_Microbit.h>
8+
9+
Adafruit_Microbit_Matrix microbit;
10+
11+
int sensorPin = 0;
12+
int moisture = 0;
13+
14+
const uint8_t
15+
frown_bmp[] =
16+
{ B00000,
17+
B01010,
18+
B00000,
19+
B01110,
20+
B10001, };
21+
const uint8_t
22+
smile_bmp[] =
23+
{ B00000,
24+
B01010,
25+
B00000,
26+
B10001,
27+
B01110, };
28+
29+
void setup() {
30+
Serial.begin(115200);
31+
while ( !Serial ) delay(10);
32+
Serial.println("micro:bit simple soil sensor");
33+
microbit.begin();
34+
35+
}
36+
37+
void loop() {
38+
// read the value from the sensor:
39+
moisture = analogRead(sensorPin);
40+
Serial.print("Soil moisture: ");
41+
Serial.println(moisture);
42+
if (moisture > 200) {
43+
microbit.show(smile_bmp);
44+
} else {
45+
microbit.show(frown_bmp);
46+
}
47+
delay(5000);
48+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
# pylint: disable=wildcard-import, undefined-variable
5+
6+
"""MicroPython Advanced Soil Sensing Demo for micro:bit"""
7+
from microbit import *
8+
9+
while True:
10+
pin2.write_digital(1)
11+
sleep(100)
12+
moisture = pin0.read_analog()
13+
if moisture > 200:
14+
display.show(Image.HAPPY)
15+
else:
16+
display.show(Image.SAD)
17+
pin2.write_digital(0)
18+
sleep(5000)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
# pylint: disable=wildcard-import, undefined-variable
5+
6+
"""MicroPython Simple Soil Sensing Demo for micro:bit"""
7+
from microbit import *
8+
9+
while True:
10+
moisture = pin0.read_analog()
11+
if moisture > 200:
12+
display.show(Image.HAPPY)
13+
else:
14+
display.show(Image.SAD)
15+
sleep(5000)

0 commit comments

Comments
 (0)