Hi there,
I'm currently building a 12V power System for a max of 20 Amps Output controlled by a Arduino Nano Clone
TRU COMPONENTS MF-6402378 Entwicklungsboard ATmega328 NANO Development Board kaufen
It Consists roughly of Solar Cells, a battery and a Backup Power Supply wich is an old, refurbished ATX supply. It now went through many revisions as I'm learning by doing, but it seems I've hit a wall, since I've destroyed 3 Nanos in the last two days.
It should work like this: The Nano gets its power from the 5V sby usb line from the power supply. this line schuld never turn off. Then the nano measures the voltage off the battery. It does that by measuring at A0 where i connected the divided battery voltage.
If it is to low, it turns on the supply on by connecting its power on line to its ground (transistor via D13). Then it turns off the batterie by using a transistor to switch off a relay (with D12).
All parts work fine alone, but they make problems together.
The first Arduino was killed because I accidentally connected the 5V line to a ground pin. oopsie
The second Arduino died Because I didn't had the diode d3. Because of that I connected the battery to my consumers through the Arduino. I was very surprised that the lights suddenly turned on.
But now i don't know what is happening. I connected everything correctly and the system worked fine for a moment but when i tried to upload the non debugging version of the code the chip burned out. So my third and for the point in time last nano went south.
Before i buy new ones I want to get some help by people who might know what they are doing.
What is wrong with my circuit. Is there an easy fix do I need to rethink the whole thing again. I had some "working" solutions before, meaning that nothing got damaged, but for different reasons it wasn't good enough. For example the accuracy of the measurements was really bad.
I sadly can't upload my schematics yet, because I'm a new user.
Here is my source code. I don't think there's anything wrong with it.:
#include <Arduino.h>
int rawVoltage = 0;
const int sampleTime = 120;
const int waitingTime = 1800;
int voltages[sampleTime];
int oldestPoint = 0;
float minVoltage = 11.0;
float startupVoltage = 12.8;
float voltage = 0;
float coefficient = 50.75943001;
bool shutdown = false;
float averageVoltage(){
float sum = 0;
for(int i = 0; i < sampleTime; i++){
sum = sum + voltages[i];
}
return sum/sampleTime;
}
void pushVoltage(int newVoltage){
voltages[oldestPoint] = newVoltage;
if(oldestPoint<sampleTime-1){
oldestPoint++;
}else{
oldestPoint=0;
}
}
void getVoltage(){
pushVoltage(analogRead(A0));
voltage = averageVoltage()/coefficient;
Serial.println(voltage);
delay(1000);
}
void setup() {
analogReference(EXTERNAL);
//power supply on
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
delay(100);
//batterie off
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
Serial.begin(9600);
}
void loop() {
getVoltage();
if(voltage > startupVoltage)
{
//batterie on
digitalWrite(12, HIGH);
delay(1000);
//netzteil off
digitalWrite(13, LOW);
for(int i = 0; i <= sampleTime; i++){
getVoltage();
}
}
if (voltage <= minVoltage)
{
//netzteil on
digitalWrite(13, HIGH);
delay(1000);
//batterie off
digitalWrite(12,LOW);
for(int i = 0; i <= waitingTime; i++){
getVoltage();
}
}
}