Arduino Driver Program That We Will Write to Make the Devices

The program that we will write to make the devices in the Arduino system of the Arduino Solar Hybrid project work as desired. 

Note : sumitrapower.com The company was established to support the use of alternative energy that is environmentally friendly by generating electricity from solar cells ติดตั้งโซล่าเซลล์ using new technologies. “Micro Inverter System” If you are interested in the product. or want to find more information Please visit us

Will create a condition according to the variable is the voltage that is supplied from the solar cell battery. The voltage measurement module will send the voltage measurement data to the Arduino board at all times and if and when. (While the system is working normally means the load receives electricity from the solar cell battery)

  1. Voltage from solar cell battery is lower than 40% or voltage is less than 12.12V, Arduino board will cut off Signal Pin 3 (connected to Pin IN2 which is relay 2 to stop using battery power) and Send signal OUTPUT at Pin 2 (Connected to Pin IN1, which is Relay Channel 1 to use power from the transformer) immediately.
  2. When the module measures voltage The voltage from the battery cell is detected to be higher than 80% or the voltage is greater than or equal to 12.46V. The Arduino board cuts signal Pin 2 (connected to pin IN1, which is the channel relay that stops power from the transformer) and sends a signal. OUTPUT at Pin 3 (connected to pin IN2 is the 2nd channel relay to switch to use the power from the solar cell battery as before) to switch the power supply to the solar cell battery.

The program of the project is as follows.

#include <Wire.h>

#include <Adafruit INA219.h>

Adafruit INA219 ina219;

void setup(void)

{

Serial.begin(115200);

pinMode(2,0UTPUT);

pinMode(3,0UTPUT);

uint32 t currentFrequency;

ina219.begin();

Serial.println(“Measuring voltage and current with INA219 …”);,

}

void loop(void)

{

float shunt voltage = 0;

float bus voltage = 0;

float current mA = 0;

float load voltage = 0;

float power mW = 0;

shunt voltage = ina219.getShuntVoltage_mV();

bus voltage = ina219.getBusVoltage_V();

current _mA = ina219.getCurrent_mA();

power mW = ina219.getPower mW();

load voltage = bus voltage + (shunt voltage / 1000);

Serial,print(“Bus Voltage: “);

Serial.print(bus voltage);

Serial.println(“V”);

Serial.print(“Shunt Voltage: “);

Serial.print(shunt voltage),

Serial.println(” mV”);

Serial.print(“Load Voltage:”);

Serial.print(load voltage);

Serial.println(“V”);

Serial.print(“Current: “);

Serial.print(current mA);

Serial.println(” mA”);

Serial.print(“Power: “);

Serial.print(power mW);

Serial.println(” mW”);

Serial.println(“”);

delay(1000);

if (bus voltage <= 12.1) [

digitalWrite(2, HIGH);

digitalWrite(3, LOW);

Serial.println(“Pin 2”);

}

if (bus voltage > 12.5) f

digitalWrite(2, LOW);

digitalWrite(3, HIGH);

Serial.println(“Pin 3”);

}

}

Voltages that range between 12.1V and 12.5V, for example, 12.3V will be in the range of using the solar cell battery (Pin 3 HIGH) until the voltage is lower than 2.1V, then the power supply will be switched. to use a transformer (Pin 2 HIGH), we should not use similar numbers. Or use more than 1 decimal place to prevent the Arduino board from confusing the command signal.

For this code, we can use values other than voltage as variables, such as current values. We will need to change the variable in the void loop from bus voltage to Current, e.g. if (Current <= 323) f (current value 323 mV or 3.23 amps). Or according to the current (mA), according to the voltage and capacity of the electrical supply (e.g. battery) as needed, such as if (bus voltage > 24.1) f (voltage 24 volts), etc.

for beginners

For those who are just starting to use the Arduino board, there is no way to create a better experience than modifying and developing the program. Let’s just start with a fun experience. It’s enough to build a big project and go on a professional path.

Things that beginners should observe and adjust to develop Code Arduino. There are 2 types of programs in this project: variables that will be used as working conditions and when variables meet the conditions, what do you want Arduino to do?

Serial.print(“Bus Voltage:”);

Serial.print(bus voltage);

Serial.println(“V”);

Serial.,print(“Shunt Voltage: “);

Serial,print(shunt voltage);

Serial.println(” mV”);

Serial.print(“Load Voltage: “);

Serial.print(load voltage);

Serial.println(“V”);

Serial.print(“Current: “);

Serial.print(current mA);

Serial.println(” mA”);

Serial.print(“Power: “);

Serial.print(power_mW);

Serial.println(” mW”);

Code Arduino This section is declaring a variable name that the Arduino board will receive from the INA219 module to process. and the values of these variables will be printed to the Serial Monitor.

(“Bus Voltage: “);

(“Shunt Voltage: “);

(“Load Voltage: “);

(“Current: “);

(“Power: “);

The dark letters in parentheses are the variables that we will use as conditions for the program of Arduino. Which these variable names will be used during the next program is

if (bus voltage <= 12.1) f

digitalWrite(2, HIGH);

digitalWrite(3, LOW);

Serial.println(“Pin 2”);

if (bus voltage > 12.5) f

digitalWrite(2, LOW);

digitalWrite(3, HIGH);

Serial.println(“Pin 3”);

Try changing the Bus Voltage to another value, such as a small battery such as alkaline or rechargeable batteries 1.5V or the voltage from the Arduino board 3.3V or we may change the variable to something else to create a site condition such as voltage. Electricity while supplying the load (Load Voltage) or current (Current)

Testing the Arduino Solar Hybrid Project

The test will start when the solar cell battery charge from the solar panel is over 80%, then we will turn on the Arduino system to make the 12VDC lamp work. IN2) will work immediately. We have written a program for Arduino to command the 2nd channel relay to work in order to release electricity from the solar battery to feed the lamp. When the voltage is more than 80% or the voltage is more than 12.5V

  1. When the lamp uses power from the solar cell battery indefinitely The voltage will gradually weaken as well, and when the voltage from the battery drops below 40% or less than 12.1V, the Arduino will immediately switch the power supply to a transformer.
  2. And when the solar panel produces electrical energy, it is continuously charged to store in the battery. And the more our batteries are lithium-ion types as well. or more than 80% charge in less than 3 hours. Therefore, when the voltage from the battery exceeds 80% or the voltage is greater than or equal to 12.5V, the Arduino board cuts the Pin signal. 2 and immediately send the OUTPUT signal to Pin 3 to switch the power supply to use the solar cell battery as before. and iterate through the program like this until we unplug the Arduino board.
  3. We choose to use lithium ion batteries. It may take less than 3 hours to charge, so Komfai will only use electricity from a 12VDC transformer for up to 3 hours. But it all depends on the sunlight that the solar panel can collect as energy. If any day is cloudy, rainy, or no sunlight Charging energy into the battery may be less. thus making the battery charging time longer

What we benefit from this project Of course, the first thing is energy saving. We may use electricity from the house that we have to buy for less than 3 hours. In addition, it is powered by batteries that store electricity that never runs out easily from the sun. but in addition to the savings We also have the experience of building a complementary electric power system. Of course, this 12VDC lamp will never turn off until the Arduino board is unplugged. Even if the battery is deteriorated, there is still power from the transformer that is sent to raise the lamp. Therefore, this project Therefore suitable for the use of appliances or electrical equipment that must work all the time, such as ventilation fans, houses or lighting system or it may be a water supply system, etc., especially for agricultural activities that the rai owners rarely have time to take care of We can apply this project to many systems that require electrical energy to be involved. which we can apply to systems that require a lot of electrical energy by changing the battery to have a greater capacity Change solar panels to produce more power. Or apply it in conjunction with an AC 220V AC power system to obtain helpful electrical energy. and more economical

Solar Panel Installation ติดตั้งโซล่าเซลล์ Guide sumitrapower.com