Measure (car)battery level and set min/max level

Goodevening to y all.
As @alto777 said earlier: you are trying to understand Shakespear, without knowing English.
But therefore I won't give up and try to built my system.

For now, and with your help too, I managed to set 2 temp sensors, devide them and with the average I am able to turn on a velve.
Today I managed to connect the RTC module and set another velve.

This is powered by a battery 12V 92Ah. And the battery is powered by 2 solarpanels.
So far this battery has to power the arduino and 2 velves + a small 12V waterpomp for in a pond
And here comes my question:

I need a safe way to measure the battery power level, and I want to switch the pump off below lets say 15%. So the arduino and velves keeps working.


This is what I built sofar. As you can see there is a failsafe (on/ off switch) between the battery and the solar module.

But does anybody know what hardware I need?
And should I connect it to the battery pole or to the 12V output of the solarmodule?
After this I would think and have to come up with an arduino software programm for measuring.

I've read this topic where almost the same question is asked - but is there in time a simpler way of doing this... ?

:upside_down_face:

Starting out neatly. :slight_smile:

But not that much better than Fritzing diagrams. :frowning:


Show us a good schematic of your proposed circuit.

1 Like

Here is the task I use to measure the voltage on my battery bring charged by a MPPT charge controller,

void fReadBattery( void * parameter )
{
  const float r1 = 50500.0f; // R1 in ohm, 50K
  const float r2 = 10000.0f; // R2 in ohm, 10k potentiometer
  const TickType_t xFrequency = 1000; //delay for mS
  float    adcValue = 0.0f;
  float    Vbatt = 0.0f;
  int      printCount = 0;
  float    vRefScale = (3.3f / 4096.0f) * ((r1 + r2) / r2);
  uint64_t TimePastKalman  = esp_timer_get_time(); // used by the Kalman filter UpdateProcessNoise, time since last kalman calculation
  SimpleKalmanFilter KF_ADC_b( 1.0f, 1.0f, .01f );
  TickType_t xLastWakeTime = xTaskGetTickCount();
  for (;;)
  {
    adc1_get_raw(ADC1_CHANNEL_0); //read and discard
    adcValue = float( adc1_get_raw(ADC1_CHANNEL_0) ); //take a raw ADC reading
    KF_ADC_b.setProcessNoise( (esp_timer_get_time() - TimePastKalman) / 1000000.0f ); //get time, in microsecods, since last readings
    adcValue = KF_ADC_b.updateEstimate( adcValue ); // apply simple Kalman filter
    Vbatt = adcValue * vRefScale;
    xSemaphoreTake( sema_CalculatedVoltage, portMAX_DELAY );
    CalculatedVoltage = Vbatt;
    xSemaphoreGive( sema_CalculatedVoltage );
    
      printCount++;
      if ( printCount == 3 )
      {
      //log_i( "Vbatt %f", Vbatt );
      printCount = 0;
      }
    
    TimePastKalman = esp_timer_get_time(); // time of update complete
    xLastWakeTime = xTaskGetTickCount();
    vTaskDelayUntil( &xLastWakeTime, xFrequency );
    //log_i( "fReadBattery %d",  uxTaskGetStackHighWaterMark( NULL ) );
  }
  vTaskDelete( NULL );
}

I used a 50K to 10K voltage divider.

Do put a diode between the PWM charge controller and the solar cell so that the solar cell does not drain the battery at night.

I also found the display for the charge controller remains on 24/7 and draws a lot of current. I switched to a MPPT charge controller without a display, Amazon.com, less of a resource drain on the battery.

1 Like

@LarryD just a typical DIY project... but nevertheless a learning curve :slight_smile:

So I don't have a good schematic, because I am not able to draw one. And if I would do this, it would take me ages to read and understand it aswell. So I hope you are able to just talk me through this Fritzing project of mine... :slight_smile:

I would like to add a safe voltage/current meter that meassures the out of the battery, and can be read by the arduino to turn off the pump.
So the part of turning off is understood... I will add another relay which is in normal state open. But when the battery drops under 15% capacity it will turn off.

Can you put me in the right direction sir?

I think of the solar cell battery thing as having 3 sections.

Section one is the connection between the solar cell and the charge controller where current must only flow from the solar cells to the charge controller.

Section 2 is the connection from the battery to the charge controller. This section current must be allowed to flow both ways.

Section 3 the connection from the battery to the load.

Section 3 is where to measure battery volts.

@Idahowalker Thank you for your so quick reply, feedback and information!

  • Oke, so I have to put a diode into my system - can you perhaps point me to the right one? Which capacity do I need? (probably 20V max, because the panels only are 16V 60W... right?)
  • I will do some research on a voltage divider, are there any other methods?
  • Thanks for the tip on the MPPT controller.
  • So if I understand you well, you should measure the current and battery level in section 3. In this part...

Do you have a link to the Solar Charge Controller ?

Why not connect the Arduino to the USB jack on the controller ?

Section 3 the connection from the battery to the load is where I measure the current of the load and the battery volts.

@Idahowalker
And what about this current sensor? Am I able to use this one too, instead of a voltage devider?
As long as I don't take risks at burning wires etc. ....

*edit: voltage sensor into current sensor

That is a current sensor.

I used one of those to measure load current.

@Idahowalker and @LarryD Yes the PMMT is Battery intelligent - but I think it isn't able to turn off just one of the loads. The pump individual in this case.
And I thought I wont use the USB port to power the Arduino, just for safety. I will lead it through a fuse first...

Oke.. sorry to ask.. but can you take me through the difference between the load current sensor and the voltage divider you used? Or do I have to use the load current sensor!!!!?

the voltage divider is to measure the voltage of the battery. The module you linked to measures the current being passed through the sensor.

1 Like

And just to understand it completely.
I need to measure the voltage for being able to know what the load of the battery is? And monitoring the output of the battery?

Shouldn't I measure the current? and if the battery is at 15% from its total power. Then give a signal for turning off?

Actually why measure the Vbatt and Ibatt?

The Controller you are using has a low volts power off setting. Though you will find the solar controller you are using will NOT turn off. It will turn off the load but not the controller. The controller continues to draw power even when the load has been shut off.

Here's my thought: The waterpump will be the biggest consumer in the system.
If I can turn this single one off - instead of shutting off all the load - I will safe some battery power and still will be able to use the others.

Therefore I thought if I am able to controle/ measure the battery load I am able to turn this pump off ...

How bored am I :woozy_face: .

Submit changes.


EDIT:
Upadated Schematic.

2 Likes

YOU ROCKKKKK!!!! Thnx Sir!

But - @LarryD - Idahowalker stated that the voltage devider comes at the output of the PMMT.
Would it make a difference? I think your option is the most pure one. You measure most direct to the battery, without any loss from the PMMT display for instance... right?