Monitoring voltage using SN-B25-VOL voltage sensor, current by
ohm’s law calculation and light intensity using BH1750. Display on
LCD 16x2 L2C and serial monitor
Hardware
connections
Components:
Arduino Uno or compatible board
SN-B25-VOL voltage sensor
10 ohm resistor
BH1750 light sensor
16x2 I2C LCD
Hardware Connections:
Voltage Sensor
(SN-B25-VOL):
Connect the VCC pin of the voltage sensor to the 5V pin on
the Arduino.
Connect the GND pin of the voltage sensor to the GND pin on
the Arduino.
Connect the OUT pin of the voltage sensor to the analog
input pin A0 on the Arduino.
10 Ohm Resistor:
Connect one end of the 10 ohm resistor to the positive
terminal of your DC voltage source.
Connect the other end of the 10 ohm resistor to the positive
terminal of the load or device you want to measure the current.
Connect the negative terminal of your DC voltage source and
the negative terminal of the load to the GND pin on the Arduino.
BH1750 Light Sensor:
Connect the VCC pin of the BH1750 to the 5V pin on the
Arduino.
Connect the GND pin of the BH1750 to the GND pin on the
Arduino.
Connect the SCL pin of the BH1750 to the SCL (A5) pin on the
Arduino.
Connect the SDA pin of the BH1750 to the SDA (A4) pin on the
Arduino.
16x2 I2C LCD:
Connect the VCC pin of the LCD to the 5V pin on the Arduino.
Connect the GND pin of the LCD to the GND pin on the
Arduino.
Connect the SDA pin of the LCD to the SDA (A4) pin on the
Arduino.
Connect the SCL pin of the LCD to the SCL (A5) pin on the
Arduino.
Please Note: Make sure to double-check the connections and ensure they are correct before powering on the Arduino.
Coding - Copy & Paste to Arduino IDE ( Ensure that you have installed the required libraries for the voltage sensor, BH1750, and the 16x2 I2C LCD )
//monitoring solar panel output performance
//initial coding by AI
//modified by Rosedi 23Aug01
#include <Wire.h>
#include <BH1750.h>
#include <LiquidCrystal_I2C.h>
const int voltageSensorPin = A0; // Analog input pin for the
voltage sensor
const float voltageReference = 5.0; // Voltage reference for
the Arduino (5V)
const int resistorValue = 10; // Resistor value in ohms
BH1750 lightMeter;
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address
to 0x27 for a 16x2 display
void setup() {
Serial.begin(9600);
Wire.begin();
// Initialize the
lightMeter object with a high-resolution mode
if
(!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
Serial.println("Error initializing BH1750 sensor!");
while (1); // Halt
the program
}
lcd.begin(16, 2);
lcd.print("V
: ");
lcd.setCursor(0, 1);
lcd.print("A
: ");
}
void loop() {
// Read voltage from
voltage sensor
int sensorValue =
analogRead(voltageSensorPin);
float voltage =
(sensorValue * voltageReference) / 204.6;
// Calculate current
using Ohm's law (I = V/R)
float current =
voltage / resistorValue;
// Read light
intensity
float lux =
lightMeter.readLightLevel();
// Display voltage
and current on LCD
lcd.setCursor(3, 0);
// Move cursor to the position after "V :"
lcd.print(voltage,
2); // Display voltage with 2 decimal places
lcd.print(" L "); // Clear any previous content
lcd.setCursor(3, 1);
// Move cursor to the position after "C :"
lcd.print(current,
2); // Display current with 2 decimal places
// Print voltage and
current to Serial Monitor
Serial.print("V
: ");
Serial.print(voltage, 2);
Serial.print("
V\t");
Serial.print("C
: ");
Serial.print(current, 2);
Serial.print("
A\t");
// Display light
intensity on the LCD
lcd.setCursor(8, 1);
// Move cursor to the position after "C :"
lcd.print(" "); //
Clear previous content
lcd.setCursor(10,
1); // Move cursor to the position after "C :"
lcd.print(lux); //
Display light intensity
// Print light
intensity to Serial Monitor
Serial.print("Light : ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);
}
If you have any better way to measure the Current, let me know in the comment.
-Rosedi-
Sep 2023
Tiada ulasan:
Catat Ulasan