0% found this document useful (0 votes)
9 views2 pages

Iot 6

This document provides wiring instructions and code for a moisture sensor connected to an Arduino. It outlines the connections for the moisture sensor and two LEDs (green for dry and red for wet), as well as the Arduino code to read the sensor values and control the LEDs based on a defined threshold. The setup includes pin assignments and a loop to continuously monitor moisture levels and update the LED indicators accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Iot 6

This document provides wiring instructions and code for a moisture sensor connected to an Arduino. It outlines the connections for the moisture sensor and two LEDs (green for dry and red for wet), as well as the Arduino code to read the sensor values and control the LEDs based on a defined threshold. The setup includes pin assignments and a loop to continuously monitor moisture levels and update the LED indicators accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Wiring (simple)

 Moisture sensor VCC → Arduino 5V


 Moisture sensor GND → Arduino GND
 Moisture sensor SIG → Arduino A0 (analog input)
 Green LED (DRY): D7 → 220Ω → LED anode; LED cathode → GND
 Red LED (WET): D8 → 220Ω → LED anode; LED cathode → GND
 Make sure Arduino GND ↔ sensor GND are common.

// Dry/Wet classifier using analog moisture sensor (recommended)

// pin assignments

const int moisturePin = A0; // analog pin connected to sensor's signal (SIG)

const int ledDry = 7; // green LED -> indicates DRY

const int ledWet = 8; // red LED -> indicates WET

int sensorValue = 0; // variable to store analog reading

int threshold = 600; // threshold (0-1023): tune after testing

void setup() {

pinMode(ledDry, OUTPUT); // set green LED pin as output

pinMode(ledWet, OUTPUT); // set red LED pin as output

// NOTE: optionally use Serial.begin(9600); during calibration

void loop() {

sensorValue = analogRead(moisturePin); // read analog value from sensor (0..1023)

// If reading is above threshold → consider it WET (some sensors are reversed;

// if yours gives lower values when wet, change '>' to '<' below)
if (sensorValue > threshold) {

digitalWrite(ledWet, HIGH); // turn ON WET (red) LED

digitalWrite(ledDry, LOW); // turn OFF DRY (green) LED

} else {

digitalWrite(ledWet, LOW); // turn OFF WET LED

digitalWrite(ledDry, HIGH); // turn ON DRY LED

delay(500); // wait 0.5s before next reading

You might also like