akash a s
Published © GPL3+

Solar-panel energy monitoring system

A simple solar energy monitoring system for DIY projects using Pi Pico W (web-server).

BeginnerShowcase (no instructions)7 hours875
Solar-panel energy monitoring system

Things used in this project

Hardware components

Raspberry Pi Pico W
Raspberry Pi Pico W
×1
RobinCore voltage sensor
×2
acs712 current sensor
×1
cn3791 12v mppt solar charger
×1
18650 li-ion cell
×1
12v solar panel
×1

Software apps and online services

thonny

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

circuit diagram

Code

code

Python
import network
import socket
import time
from machine import Pin, ADC
import urandom

# Define the ADC pins for solar panel, battery, and output current
solar_panel_pin = Pin(26, Pin.IN)
battery_pin = Pin(27, Pin.IN)
output_current_pin = Pin(28, Pin.IN)

solar_panel_adc = ADC(solar_panel_pin)
battery_adc = ADC(battery_pin)
output_current_adc = ADC(output_current_pin)

# Your network SSID and password
ssid = ''
password = ''
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)

html = """<!DOCTYPE html>
<html>
<head>
    <title>Solar Power Monitoring System</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
 background-image: url('https://media.istockphoto.com/id/525206743/photo/solar-panel-on-a-red-roof.jpg?s=612x612&w=0&k=20&c=xcAkdNj8dFDhu8734FpRDAZDtN2bjr48RKEd9j2FL0U=');
            background-size: cover;
            background-repeat: no-repeat;
        }

        .container {
            text-align: center;
            background-color: rgba(255, 255, 255, 0.8); /* Adding a semi-transparent white background for better readability */
            border: 1px solid #ccc;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
        }

        h1 {
            text-decoration: underline;
        }

        p {
            font-size: 24px;
        }

        button {
            font-size: 20px;
        }

        #credits {
            display: none;
            font-size: 18px;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>Solar Power Monitoring System</h1>
    <h2>Solar Power Monitoring System using PI PICO W</h2>
    <p>&bull; Voltage from Solar panel: %.2f V</p>
    <p>&bull; Battery Voltage: %.2f V</p>
    <p>&bull; Output Current: %.2f A</p>
    <button onclick="refreshPage()">Refresh</button>
    <button onclick="showCredits()">Credits</button>
    <div id="credits">
        <p><h3>Created by:</h3> A.S. Akash</p>
        <p><h4>College:</h4> HINDUSTAN INSTITUTE OF TECHNOLOGY AND SCIENCE</p>
    </div>
</div>

<script>
    function refreshPage() {
        location.reload();
    }

    // Auto-refresh every 10 seconds
    setTimeout(function () {
        location.reload();
    }, 5000); // 10000 milliseconds = 10 seconds

    function showCredits() {
        var credits = document.getElementById("credits");
        credits.style.display = "block";
    }
</script>
</body>
</html>

"""

max_wait = 10
while max_wait > 0:
    if wlan.status() < 0 or wlan.status() >= 3:
        break
    max_wait -= 1
    print('Waiting for connection...')
    time.sleep(1)

if wlan.status() != 3:
    raise RuntimeError('Network connection failed')
else:
    print('Connected')
    status = wlan.ifconfig()
    print('IP = ' + status[0])

addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]

s = socket.socket()
s.bind(addr)
s.listen(1)

print('Listening on', addr)

# Listen for connections
while True:
    try:
        cl, addr = s.accept()
        print('Client connected from', addr)
        
        # Read sensor values
    
        #
        R1 = 30000.0;
        R2 = 7500.0;
        solar_panel_value = ((solar_panel_adc.read_u16() * 3.3) / 65535)/ (R2/(R1+R2));
        battery_voltage = ((battery_adc.read_u16() * 3.3) / 65535)/ (R2/(R1+R2));
        output_current = (output_current_adc.read_u16() / 65535) * 3300  # Convert to voltage (3.3V reference voltage)
        output_current = ((output_current - 1650) / 100) - 0.10

        response = html % (solar_panel_value, battery_voltage, output_current)
        cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
        cl.send(response)
        cl.close()

    except OSError as e:
        cl.close()
        print('Connection closed')

Credits

akash a s

akash a s

4 projects • 5 followers
Electronics student who loves making projects

Comments