← Back to Course
Power Saving with Pico W
🔋 Power Saving for Battery Operation
Pico W has several power-saving features for battery-powered sensors.
💤 Light Sleep Mode:
import machine
import time
# Light sleep reduces power to ~1.5mA
print("Going to light sleep for 60 seconds...")
machine.lightsleep(60000) # Sleep 60 seconds
print("Woke up!")
# After wake, reconnect WiFi and send data
📖 Complete Power-Saving Sensor Station:
import network
import urequests
import machine
import time
from machine import Pin, ADC
ssid = "YOUR_WIFI"
password = "YOUR_PASSWORD"
token = "YOUR_TOKEN"
moisture_sensor = ADC(Pin(26))
def connect_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while not wlan.isconnected():
time.sleep(0.5)
def read_and_send():
raw = moisture_sensor.read_u16()
moisture = 100 - (raw / 65535 * 100)
url = "https://api.oceanremote.net/device/state"
data = f"token={token}&soil_moisture={moisture}"
try:
response = urequests.post(url, data=data)
response.close()
print("Data sent")
except:
print("Send failed")
while True:
# Wake, connect, send
connect_wifi()
read_and_send()
print("Going to sleep for 15 minutes...")
machine.lightsleep(15 * 60 * 1000)
💡 Battery Life:
- Active + WiFi: 70-100mA
- Light sleep: 1.5mA
- Deep sleep: 0.5mA (requires RTC alarm)
- With 2000mAh battery and 15-minute wake: 2-3 months
💡 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.
×