Devices & Components
Arduino Nano
USB 2.0 Cable Type A/B
Assorted DuPont Wires
ELEGOO 17 Values 1% Resistor Kit Assortment
LM393 Soil Moisture Sensor
Chanzon 60pcs 5mm LED Diode Lights Assortment Kit
Software & Tools
Arduino IDE
Google Gemini
Project description
Code
Soil Moisture Sensor Code
cpp
1// Define the pins 2int sensorPin = A0; 3int ledPin = 7; 4 5// Variables to store sensor value 6int sensorValue = 0; 7 8void setup() { 9// Initialize serial communication at 9600 baud rate 10Serial.begin(9600); 11 12// Initialize the LED pin as an output 13pinMode(ledPin, OUTPUT); 14} 15 16void loop() { 17// Read the analog value from the sensor 18sensorValue = analogRead(sensorPin); 19 20// Print the sensor value to the Serial Monitor 21Serial.print("Soil Moisture Value: "); 22Serial.println(sensorValue); 23 24// Check if the soil is dry 25if (sensorValue > 500) { 26// Turn the LED on 27digitalWrite(ledPin, HIGH); 28} else { 29// Turn the LED off 30digitalWrite(ledPin, LOW); 31} 32 33// Wait for a second before taking another reading 34delay(1000); 35}
Downloadable files
Layout picture
moisture_layout.png

Comments
Only logged in users can leave comments