← Back to Course
Complete Solar-Powered Pico W Weather Station
☀️ Complete Solar-Powered Weather Station
Combine soil moisture + DHT22 + WiFi + power saving for a complete farm monitoring system!
📖 Complete Project Code:
import network
import urequests
import machine
import time
import dht
from machine import Pin, ADC
# WiFi credentials
ssid = "YOUR_WIFI"
password = "YOUR_PASSWORD"
token = "YOUR_OCEANREMOTE_TOKEN"
# Sensors
moisture = ADC(Pin(26))
dht_sensor = dht.DHT22(Pin(0))
def connect_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while not wlan.isconnected():
print("Connecting...")
time.sleep(1)
print("✅ WiFi connected")
def read_all_sensors():
# Soil moisture
raw = moisture.read_u16()
moisture_percent = 100 - ((raw - 20000) * 100 / (60000 - 20000))
moisture_percent = max(0, min(100, moisture_percent))
# DHT22
try:
dht_sensor.measure()
temp = dht_sensor.temperature()
hum = dht_sensor.humidity()
except:
temp = 0
hum = 0
return temp, hum, moisture_percent
def send_data(temp, hum, soil):
url = "https://api.oceanremote.net/device/state"
data = f"token={token}&temperature={temp}&humidity={hum}&soil_moisture={soil}"
try:
response = urequests.post(url, data=data)
response.close()
print("✅ Data sent to OceanRemote")
except Exception as e:
print(f"Failed: {e}")
while True:
# Read sensors
temp, hum, soil = read_all_sensors()
print(f"🌡️ Temp: {temp}°C | 💧 Humidity: {hum}% | 🌱 Soil: {soil:.0f}%")
# Connect and send
connect_wifi()
send_data(temp, hum, soil)
# Deep sleep for 15 minutes
print("💤 Sleeping for 15 minutes...")
machine.lightsleep(15 * 60 * 1000)
🔋 Components Needed:
- Raspberry Pi Pico W ($6)
- DHT22 sensor ($5)
- Soil moisture sensor ($8)
- 6V solar panel ($10)
- 18650 battery + charger ($8)
- Total cost: ~$37
🎉 Congratulations!
You've built a complete solar-powered weather station! This system runs for months, providing real-time farm data to help African farmers make better decisions.
💡 Key Takeaways:
- Apply these concepts directly to your farm or project.
- Take notes on important details for the quiz.
- Use the button below to track your progress.
×