Devices & Components
Arduino Uno Rev3
Breadboard - 830 contacts
Capacitive Soil Moisture Sensor
Software & Tools
Arduino IDE
Project description
Code
Arduino soil moisture sensor code
c
code for testing soil moisture sensor with arduino
1// Moisture Sensor Arduino Code 2 3 4//By Circuitdigest 5 6 7 8 9 10#define ledPin 6 11 12 13#define sensorPin A0 14 15 16 17 18 19void setup() { 20 21 22 Serial.begin(9600); 23 24 25 pinMode(ledPin, OUTPUT); 26 27 28 digitalWrite(ledPin, LOW); 29 30 31} 32 33 34 35 36 37void loop() { 38 39 40 Serial.print("Analog output: "); 41 42 43 Serial.println(readSensor()); 44 45 46 delay(500); 47 48 49} 50 51 52 53 54 55// This function returns the analog data to calling function 56 57 58int readSensor() { 59 60 61 int sensorValue = analogRead(sensorPin); // Read the analog value from sensor 62 63 64 int outputValue = map(sensorValue, 0, 1023, 255, 0); // map the 10-bit data to 8-bit data 65 66 67 analogWrite(ledPin, outputValue); // generate PWM signal 68 69 70 return outputValue; // Return analog moisture value 71 72 73}
Downloadable files
Github code for soil moisture sensor with Arduino
code and circuit from github
https://github.com/Circuit-Digest/Basic-Arduino-Tutorials-for-Beginners-/tree/main/Interfacing%20Soil%20Moisture%20Sensor%20with%20Arduino
Documentation
Soil Moisture Sensor with Arduino
A Full tutorial on how soil moisture sensor
https://circuitdigest.com/microcontroller-projects/interfacing-soil-moisture-sensor-with-arduino-uno
Comments
Only logged in users can leave comments