Smart Solar Energy Monitor

by Kobe__Lamote in Circuits > Raspberry Pi

77 Views, 1 Favorites, 0 Comments

Smart Solar Energy Monitor

IMG_7223.JPG

This project is designed to help homeowners optimize their solar energy usage by monitoring the energy production from their solar panels and comparing it to their household's total energy consumption. When the demand for energy is high and the solar output is low or insufficient, non-critical devices (such as an electric car charger) will be automatically turned off to minimize the grid usage.

To keep the project transportable and manageable, we are building a miniature version that incorporates all the necessary components. However, the goal of this project is for it to be applicable to an actual household.

Supplies

The total cost of this project amounts to approximately $200. It is powered by a Raspberry Pi 4B. For a comprehensive list of materials used, please refer to the Bill of Materials (BOM).

Fuse Box

IMG_0885 3.jpeg
IMG_0887 2.jpeg

In this project, we will utilize 10A relays to control our non-critical devices. It is important to note that these relays should not be used to operate an actual car charger, as car chargers typically exceed the 10A limit. The relays come pre-equipped with the necessary diodes and transistors, allowing them to function with a 3V signal directly from the Raspberry Pi. Additionally, I have 3D printed a custom mount to securely place the relay within the fuse box.

Downloads

Energy Meter

IMG_0886 2.jpg

To measure the energy usage of the household, we will use an energy meter typically found in a fuse box. These meters emit pulses for every specified amount of energy consumed. In this project, for my non-critical devices, I am using a meter that generates 1000 pulses per kWh, equivalent to one pulse per Wh.

For solar energy and household energy, given the miniature scale of the setup, the power consumption is too low to be measurable by a standard energy meter. Therefore, we will simulate these measurements.

I will connect my solar panel to a Raspberry Pi Pico, which will drive an INA226 current sensor. This setup will calculate the energy usage and emit a pulse for every mWh, scaled up by a factor of 1000 to simulate energy consumption comparable to an actual household.

For the power usage of household appliances, pulses will be generated based on the number of appliances turned on, purely for simulation purposes.

Solar Energy Setup

IMG_0956 2.jpeg
Screenshot 2024-06-16 at 12.26.04.png

To measure solar energy, we will configure the sensor according to the schematic. The GPIO3 pin will activate a transistor to emit pulses, as detailed later.

The Raspberry Pi Pico is soldered onto a perfboard and housed within a 3D-printed enclosure designed for mounting within a fuse box. However, for this project, I will mount it externally to the fuse box.

Miniature House

IMG_0950 2.jpeg
IMG_0951 2.jpeg
IMG_0949 2.jpeg
IMG_0948 2.jpeg
IMG_0996.jpg
IMG_0998.jpg
IMG_0916 2.jpg

The miniature house features a laser-cut outer layer and a 3D-printed base designed to accommodate all necessary components.

Within this setup, three LEDs will be placed to simulate appliances visible through the windows. Additionally, two LDR sensors will enable the solar panel to track the sun's movement throughout the day. To facilitate this tracking mechanism, a servo motor will be employed to adjust the position of the solar panel accordingly.

The base includes a cutout designed to accommodate a 60x40mm perfboard, where components such as the ADC (MCP3008), LDR sensors, LEDs, and the capacitor for the solar panel will be mounted directly.

NOTE: Due to the current placement of the LDR sensors, the solar panel casts his own shadow over them. For the prototype, I will proceed without redesigning this issue.

Downloads

Raspberry Pi Setup

IMG_0954 2.jpeg
Screenshot 2024-06-16 at 14.17.07.png
IMG_0967 2.jpeg
IMG_0952 2.jpeg
IMG_0999.jpg

For the central processing unit of this project, I have opted for a Raspberry Pi 4B enclosed in a custom 3D-printed enclosure, specifically designed for mounting in a fuse box. To avoid direct soldering onto the Raspberry Pi pins, I utilized a riser to mount a perfboard. This perfboard accommodates essential components, including a real-time clock sensor for uninterrupted timekeeping in the absence of internet connectivity and terminal block connectors to facilitate pulse detection and power supply for the servo motor.

To read out the energy meters, it's crucial to apply the correct voltage based on your device specifications. My energy meter operates with a signal range between 5-27V. Therefore, I will directly utilize the 5V output from the Raspberry Pi and implement a resistor divider to reduce this to 3V, ensuring the Pi is not damaged.

For the custom solar energy meter, a 3V signal is adequate since it employs a simple transistor circuit. Here, I will include a resistor to regulate the current appropriately.

The small OLED display will be attached to the top part using hot glue. The button will be precisely fitted into its designated slot. For this purpose, any MX switch can be utilized.

Software

Screenshot 2024-06-17 at 02.30.54.png
Screenshot 2024-06-17 at 02.37.46.png

All the necessary code is available on GitHub

Here's a breakdown of the code functionality:

  1. Logging Pulses to Database: Every pulse generated by the energy meters is logged into a database. This allows for accurate tracking and recording of energy consumption over time.
  2. Calculating and Displaying Used Power: Upon loading the web interface, the Raspberry Pi computes the total power usage based on the logged pulses from the database. This calculated value is then sent to the front-end interface for display, providing real-time information on energy consumption.
  3. Solar Panel Positioning: The position of the solar panel is adjusted dynamically based on readings from two LDR sensors. These sensors detect sunlight intensity and guide the Raspberry Pi in rotating the solar panel to maximize solar energy capture throughout the day.
  4. Front-End Interface: The front-end interface features three buttons that allow users to view the state of household appliances. These buttons toggle between displaying whether appliances are on. This information is communicated to the Raspberry Pi, which then simulates pulses based on the current state of the appliances.
  5. Settings Tab with Threshold Variable: The settings tab on the frontend includes a threshold variable. This variable determines when our non-critical consumers should be turned on or off. It calculates the surplus solar energy generated beyond household consumption. If the surplus meets or exceeds the threshold, the Raspberry Pi controls the relays accordingly to optimize energy usage.



Setup


  • Database Initialization:
  • Locate the SQL files needed for database initialization in the "database" folder. Execute these SQL files to set up your database schema and tables according to your project requirements.
  • Configure config.py File:
  • Open the config.py file and configure it based on your setup.
  • Setting Up Python Environment:
  • First, create a virtual environment for isolating your project dependencies:
python -m venv venv
  • Activate the virtual environment. On Windows:
. /.venv/bin/activate
  • Once the virtual environment is activated, install the necessary libraries.
pip install -r requirements.txt


With the database initialized, config.py configured, and dependencies installed in the virtual environment, your setup should be complete.