additional soil sensor examples
This commit is contained in:
parent
3efeca69df
commit
b74bbaf033
6 changed files with 79 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
||||||
|
// SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/* Advanced Soil Sensor Demo */
|
||||||
|
|
||||||
|
int sensorPin = A0;
|
||||||
|
int onPin = 2;
|
||||||
|
int moisture = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
while ( !Serial ) delay(10);
|
||||||
|
pinMode(onPin, OUTPUT);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
digitalWrite(onPin, HIGH);
|
||||||
|
delay(1000);
|
||||||
|
// read the value from the sensor:
|
||||||
|
moisture = analogRead(sensorPin);
|
||||||
|
Serial.println(moisture);
|
||||||
|
digitalWrite(onPin, LOW);
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
// SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/* Simple Soil Sensor Demo */
|
||||||
|
|
||||||
|
int sensorPin = A0;
|
||||||
|
int moisture = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
while ( !Serial ) delay(10);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// read the value from the sensor:
|
||||||
|
moisture = analogRead(sensorPin);
|
||||||
|
Serial.println(moisture);
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
19
Simple_Soil_Sensor_Demos/CircuitPython_Advanced/code.py
Normal file
19
Simple_Soil_Sensor_Demos/CircuitPython_Advanced/code.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import time
|
||||||
|
import board
|
||||||
|
from analogio import AnalogIn
|
||||||
|
from digitalio import DigitalInOut, Direction
|
||||||
|
|
||||||
|
sensor_power = DigitalInOut(board.D5)
|
||||||
|
sensor_power.direction = Direction.OUTPUT
|
||||||
|
|
||||||
|
analog_in = AnalogIn(board.A0)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
sensor_power.value = True
|
||||||
|
print(f"Soil Moisture: {analog_in.value}")
|
||||||
|
sensor_power.value = False
|
||||||
|
time.sleep(5)
|
||||||
13
Simple_Soil_Sensor_Demos/CircuitPython_Simple/code.py
Normal file
13
Simple_Soil_Sensor_Demos/CircuitPython_Simple/code.py
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import time
|
||||||
|
import board
|
||||||
|
from analogio import AnalogIn
|
||||||
|
|
||||||
|
analog_in = AnalogIn(board.A0)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print(f"Soil Moisture: {analog_in.value}")
|
||||||
|
time.sleep(5)
|
||||||
Loading…
Reference in a new issue