simple soil sensor examples
adding micropython and arduino examples for simple soil sensor
This commit is contained in:
parent
caffaec092
commit
3efeca69df
6 changed files with 134 additions and 0 deletions
|
|
@ -0,0 +1,53 @@
|
|||
// SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/* micro:bit Advanced Soil Sensor Demo */
|
||||
|
||||
#include <Adafruit_Microbit.h>
|
||||
|
||||
Adafruit_Microbit_Matrix microbit;
|
||||
|
||||
int sensorPin = 0;
|
||||
int onPin = 2;
|
||||
int moisture = 0;
|
||||
|
||||
const uint8_t
|
||||
frown_bmp[] =
|
||||
{ B00000,
|
||||
B01010,
|
||||
B00000,
|
||||
B01110,
|
||||
B10001, };
|
||||
const uint8_t
|
||||
smile_bmp[] =
|
||||
{ B00000,
|
||||
B01010,
|
||||
B00000,
|
||||
B10001,
|
||||
B01110, };
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while ( !Serial ) delay(10);
|
||||
Serial.println("micro:bit advanced soil sensor");
|
||||
microbit.begin();
|
||||
pinMode(onPin, OUTPUT);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
digitalWrite(onPin, HIGH);
|
||||
delay(50);
|
||||
// read the value from the sensor:
|
||||
moisture = analogRead(sensorPin);
|
||||
Serial.print("Soil moisture: ");
|
||||
Serial.println(moisture);
|
||||
if (moisture > 200) {
|
||||
microbit.show(smile_bmp);
|
||||
} else {
|
||||
microbit.show(frown_bmp);
|
||||
}
|
||||
digitalWrite(onPin, LOW);
|
||||
delay(5000);
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
// SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/* micro:bit Simple Soil Sensor Demo */
|
||||
|
||||
#include <Adafruit_Microbit.h>
|
||||
|
||||
Adafruit_Microbit_Matrix microbit;
|
||||
|
||||
int sensorPin = 0;
|
||||
int moisture = 0;
|
||||
|
||||
const uint8_t
|
||||
frown_bmp[] =
|
||||
{ B00000,
|
||||
B01010,
|
||||
B00000,
|
||||
B01110,
|
||||
B10001, };
|
||||
const uint8_t
|
||||
smile_bmp[] =
|
||||
{ B00000,
|
||||
B01010,
|
||||
B00000,
|
||||
B10001,
|
||||
B01110, };
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while ( !Serial ) delay(10);
|
||||
Serial.println("micro:bit simple soil sensor");
|
||||
microbit.begin();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the value from the sensor:
|
||||
moisture = analogRead(sensorPin);
|
||||
Serial.print("Soil moisture: ");
|
||||
Serial.println(moisture);
|
||||
if (moisture > 200) {
|
||||
microbit.show(smile_bmp);
|
||||
} else {
|
||||
microbit.show(frown_bmp);
|
||||
}
|
||||
delay(5000);
|
||||
}
|
||||
18
Simple_Soil_Sensor_Demos/MicroPython/adv_soil_sensor_demo.py
Normal file
18
Simple_Soil_Sensor_Demos/MicroPython/adv_soil_sensor_demo.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# pylint: disable=wildcard-import, undefined-variable
|
||||
|
||||
"""MicroPython Advanced Soil Sensing Demo for micro:bit"""
|
||||
from microbit import *
|
||||
|
||||
while True:
|
||||
pin2.write_digital(1)
|
||||
sleep(100)
|
||||
moisture = pin0.read_analog()
|
||||
if moisture > 200:
|
||||
display.show(Image.HAPPY)
|
||||
else:
|
||||
display.show(Image.SAD)
|
||||
pin2.write_digital(0)
|
||||
sleep(5000)
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# pylint: disable=wildcard-import, undefined-variable
|
||||
|
||||
"""MicroPython Simple Soil Sensing Demo for micro:bit"""
|
||||
from microbit import *
|
||||
|
||||
while True:
|
||||
moisture = pin0.read_analog()
|
||||
if moisture > 200:
|
||||
display.show(Image.HAPPY)
|
||||
else:
|
||||
display.show(Image.SAD)
|
||||
sleep(5000)
|
||||
Loading…
Reference in a new issue