Interfacing Raspberry Pi 3 with Soil Moisture Sensor ๐ฑ
๐ฏ Objective
Use the Soil Moisture Sensor with Raspberry Pi 3 to measure soil humidity levels. This setup is ideal for building smart irrigation systems for gardens and farms. ๐พ
๐งฐ Components Required
Component | Quantity |
Raspberry Pi 3 | 1 |
Soil Moisture Sensor (Analog) | 1 |
MCP3008 ADC | 1 |
Breadboard | 1 |
Jumper Wires | As required |
⚡ Circuit Connections
Sensor to MCP3008:
Soil Sensor Pin | Connect To |
VCC | 3.3V (RPi) |
GND | GND (RPi) |
Analog Out | CH0 of MCP3008 |
MCP3008 to Raspberry Pi:
MCP3008 | RPi3 GPIO Pin |
VDD, VREF | 3.3V |
AGND, DGND | GND |
CLK | GPIO11 |
DOUT | GPIO9 |
DIN | GPIO10 |
CS | GPIO8 |
๐ง Python Code
import spidev
import time
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1350000
def read_channel(channel):
adc = spi.xfer2([1, (8 + channel) << 4, 0])
data = ((adc[1] & 3) << 8) + adc[2]
return data
try:
while True:
moisture_level = read_channel(0)
print("Soil Moisture Level:", moisture_level)
time.sleep(2)
except KeyboardInterrupt:
spi.close()
๐ Output
- Continuously prints soil moisture levels to the console every 2 seconds.
- Higher value = Dryer soil ๐ฅ
- Lower value = Wet soil ๐ง
๐ก Applications
- Smart irrigation systems
- Automatic watering in gardens and pots
- Soil monitoring for agriculture
๐ฏ เคเคฆ्เคฆिเคท्เค
Soil Moisture Sensor เคเคฃि Raspberry Pi 3 เคตाเคชเคฐूเคจ เคเคฎिเคจीเคคीเคฒ เคเคฒाเคตा เคคเคชाเคธเคฃे. เคนे เคाเคฐ्เคกเคจเคธाเค ी เคธ्เคฎाเคฐ्เค เคตॉเคเคฐिंเค เคธिเคธ्เคीเคฎเคธाเค ी เคเคชเคฏुเค्เคค เคเคนे. ๐ฟ
๐งฐ เคฒाเคเคฃाเคฐे เคธाเคนिเคค्เคฏ
เคเคเค | เคธंเค्เคฏा |
Raspberry Pi 3 | 1 |
Soil Moisture Sensor (Analog) | 1 |
MCP3008 ADC | 1 |
เคฌ्เคฐेเคกเคฌोเคฐ्เคก | 1 |
เคंเคชเคฐ เคตाเคฏเคฐ | เคเคฐเคेเคจुเคธाเคฐ |
⚡ เคธเคฐ्เคिเค เคเคจेเค्เคถเคจ
เคธेเคจ्เคธเคฐ เคคे MCP3008:
Soil Sensor | เคुเค े เคोเคกाเคฏเคं |
VCC | 3.3V (RPi) |
GND | GND (RPi) |
Analog Out | CH0 (MCP3008) |
MCP3008 เคคे เคฐाเคธ्เคชเคฌेเคฐी เคชाเคฏ:
MCP3008 | RPi3 GPIO |
VDD, VREF | 3.3V |
AGND, DGND | GND |
CLK | GPIO11 |
DOUT | GPIO9 |
DIN | GPIO10 |
CS | GPIO8 |
๐ง เคชाเคเคฅเคจ เคोเคก
import spidev
import time
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1350000
def read_channel(channel):
adc = spi.xfer2([1, (8 + channel) << 4, 0])
data = ((adc[1] & 3) << 8) + adc[2]
return data
try:
while True:
moisture_level = read_channel(0)
print("เคฎाเคคीเคคीเคฒ เคเคฒाเคตा เคชाเคคเคณी:", moisture_level)
time.sleep(2)
except KeyboardInterrupt:
spi.close()
๐ เคเคเคเคชुเค
- เคช्เคฐเคค्เคฏेเค 2 เคธेเคंเคฆांเคจी เคฎाเคคीเคคीเคฒ เคเคฒाเคตा เคเคจ्เคธोเคฒเคตเคฐ เคฆเคฐ्เคถเคตเคคो.
- เคाเคธ्เคค เคต्เคนॅเคฒ्เคฏू = เคोเคฐเคกी เคฎाเคคी ๐️
- เคเคฎी เคต्เคนॅเคฒ्เคฏू = เคเคฒเคธเคฐ เคฎाเคคी ๐ง️
๐ก เคเคชเคฏोเค
- เคธ्เคฎाเคฐ्เค เคธिंเคเคจ เคช्เคฐเคฃाเคฒी
- เคฌाเคेเคฎเคง्เคฏे เคिंเคตा เคुंเคก्เคฏांเคฎเคง्เคฏे เคเคो เคตॉเคเคฐिंเค
- เคถेเคคीเคธाเค ी เคฎाเคคी เคคเคชाเคธเคฃी
Comments