Skip to the content
PCBKitNew board
2 layers31.1 × 57.6 mmMAhTime, the printed circuit board in 3D

This repository includes all the KiCAD based circuit designs and the code for calculating battery life

Size
31.1 × 57.6 mm
Copper layers
2
Thickness
1.6 mm
Parts
31
Nets
32
Pads
89
Tracks, vias
139, 15
Pours
2
Routed
Yes
KiCad
KiCad 5 (file 20171130)
Created
19 Jul 2019
Updated
25 Jul 2019

Overview

MAhTime is an open-source printed circuit board by Rohit04121998, from the Rohit04121998/mAhTime repository on GitHub, published under the MIT licence. It is a 2-layer board of 31.1 × 57.6 mm with 31 parts on 32 nets, routed with 139 tracks and 15 vias.

It is built around the IRLML6401TRPBF and SI2302. Its parts include 9 resistors, 5 transistors, 3 connectors, 1 IC and 1 switch. It belongs with the power boards and the ESP8266 boards of this library.

Main components

2

README

README.md

mAhTime

Objective

To calculate the battery life for a device using small batteries and in turn use the data to calculate for any bigger battery.

Why do we need this?

The capacity of a battery is measured in Ah (ampere-hours, for large batteries) or mAh (milliampere-hours, for small batteries). This is usually mentioned on the battery or in the datasheets provided by the manufacturer. But the capacity changes depending on the age of the battery, operating conditions, slightly different chemical composition, etc. So it affects the final result.

To get the actual capacity (close-enough-value), measuring the same is the method. Different methods are there using which one can measure the capacity, for example, Coulomb counting, Voltage monitoring, etc. (Learn more here or here).

Here we use the second method; monitoring the terminal voltage when a known load (resistive) is connected.

Method:

The batteries are charged and connected to a custom-designed shield for the ESP8266 microcontroller and a load is selected using a button. The microcontroller logs the terminal voltage read from its pin to the MQTT broker in RPi until the lower cut off voltage for the batteries is reached. The loads are automatically disconnected using logic level p-MOS switches.

The values read by the microconttrollr is sent to a RPi using a MQTT broker named mosquitto. MQTT is a pub-sub based protocol where one device reads and sends the data to a topic and another device subscribes to the same topic to get the data published by the first device. A brief explanation of how values are sent via a broker is explained in the next heading. The recieved data is run through a python script to display the discharge curve and the area under the curve is calculated(area under the V*I v/s t curve is power rating and area under the I v/s t curve is the mAh / Ah of the batteries).

Once again the batteries are charged, but this time, Device Under Test (DUT) is selected instead of a load (using the same microcontroller). The time taken for the DUT to discharge the batteries is found. This can then be used to calculate the life of any battery using ratios ( Eg.: If for X (mAh) it is Y (no. of days) then for Z (mAh)? = YZ/X ).

MQTT

MQTT is one of the most commonly used protocols in IoT projects. It stands for Message Queuing Telemetry Transport.

In addition, it is designed as a lightweight messaging protocol that uses publish/subscribe operations to exchange data between clients and the server. Furthermore, its small size, low power usage, minimized data packets and ease of implementation make the protocol ideal of the “machine-to-machine” or “Internet of Things” world.

WHY MQTT??

MQTT has unique features you can hardly find in other protocols, like:

  • It’s a lightweight protocol. So, it’s easy to implement in software and fast in data transmission.
  • It’s based on a messaging technique. You know how fast your messenger/WhatsApp message delivery is. MQTT protocol is a similar one.
  • Minimized data packets. Hence, low network usage.
  • Low power usage. As a result, it saves the connected device’s battery.

How MQTT works

Like any other internet protocol, MQTT is based on clients and a server. The server is the guy who is responsible for handling the client’s requests of receiving or sending data between each other. MQTT server is called a broker and the clients are simply the connected devices.

So:

When a device (a client) wants to send data to the broker, we call this operation a “Publish” and the device "Publisher". When a device (a client) wants to receive data from the broker, we call this operation a “Subscribe” and this device as "Subscriber".

MQTT Components

  • Broker, which is the server that handles the data transmission between the clients.
  • A Topic, which is the place a device want to put or retrieve a message to/from.
  • The Message, which is the data that a device receives “when subscribing” from a topic or send “when publishing” to a topic.
  • Publish, is the process a device does to send its message to the broker.
  • Subscribe, where a device does to retrieve a message from the broker.

By now hopefully you would have an idea how a MQTT network might look or works like.

The common methods used to transfer data are:

  • Making use of test.mosquitto.org server as a MQTT broker and sending the data via this server.

  • Making use of a common WiFi network to share the data.

  • Making one of the ends (i.e either ESP8266 or the RPi) as an Access Point and connect the other to it.

    The 2nd and the 3rd methods do not use any online brokers. Therefore a broker is to be installed in the RPi. For information on how to install mosquitto broker on your RPi use the link Getting Started with Mosquitto MQTT Broker on a Raspberry Pi.

Hardware & Firmware:

A microcontroller unit (ESP8266-12E on LOLin board) has an inbuilt ADC (Analog to Digital Converter) with a precision of (1/1024)th of a volt. But the input voltage range is only 0 (0) - 1V (1024). To use this in 0 - 3V range a resistor voltage divider is implemented using precision resistors and an n- MOS switch to enable this voltage divider. The voltage divider is not the one which is present on the LOLin board. Those are not precision resistors, hence the readings may not be accurate. The n-MOS switch is required as the voltage divider acts as another resistive load parallel to the selected load. An OLED display is used to display the selected load, time, etc.

The hardware limits the maximum battery voltage to 3.6V as the battery voltage appears at pin A0 when voltage divider is disabled and the absolute maximum voltage given is 3.6V for ESP8266. The time taken for measurement is determined by the capacity of the battery and the chosen load.

The circuit connections and the designed PCB can be found in the directory PCB_KICAD. The details about the charger and the battery can be found in the 'Charger_hacked' directory. Arduino IDE is used to program the microcontroller. The required header files and libraries are in the upload_voltage directory.

Fig 1. Unsoldered PCB

PCB FrontPCB Back

Fig 2. Soldered PCB

Fig 3. Display

Code:

  • In the upload_voltage.ino file, Vbat variable is used to store the voltage value. The queue is sized to hold a maximum of 1000 values. Here, the value is stored and sent every 4 seconds.

  • To get the date and time info from the ESP8266, NTTP Client has been used . The getFormattedDate() function gives the date and time format as 2018-05-28T10:00:13Z. So modifications were done and the final output was 2018-05-28_10:00:13. This was further modified in the plot.py by replacing ':' with 'H', 'M' and 'S'. This was then appended to the .csv file having the load value as its initial name.

  • The code is made such that a short press of the button is conssidered as next option and a long press is considered as select. The long press for one of the load values sets the value of variable seleted to a umber between 1 and 8. The load is selected according to the value of variable selected in the function LoadVal. The function attachLoad attaches the load and changes the state of the mosfets accordingly. The discharging of the battery starts as soon as the load is attached.

  • Before any value is sent through MQTT, the variable filename which contains the device ID, load, date and time with the .csv extension is published to inform the subscriber that a new discharge cycle has started and to create a new CSV file by the name of the variable sent. Only after the filename are the voltage values to be sent.

  • Once all the values are sent over through MQTT, a "Fully Discharged" message is sent stating that te experiment's finished.

  • The code for MQTT subscribe is a simple code which tells the interpreter what to do when the connection with the MQTT broker is established and when a message is recieved. The funtion on_connect will be executed as soon as connection is established. The on_message funtion is executed as soon as a message is received. The messaged is checked for a .csv extension and a new CSV file is created if the result of this comparision is positive.

  • This message with a .csv extension contains the ID of the device which published the message,the load selected, date and time of the moment a load is selected. The name of the new CSV file created contains only load,date and time(format containing 'H' 'M' and 'S' specified in one of the above points. Here data and time are included to differentiate between experiments conducted on the same day.

  • The voltage values received are added to this file along with the time elapsed. At the end of the experiment "FUlly Discharged" message is recieved once and is added to the file informing the plotter that the experiment is finished and the mAh value can be calculated.

  • In the script Plot_value.py FuncAnimate function is used to create an interactive mode i.e to plot a real time graph. The mAh value of the battery is shown only when the message "Fully Discharged" intercepts by the interpreter.

Result:

The result of the experments need not be the same everytime. The mAh value might change if the battery is not fully charged before the start of the experiment. The time taken for the discharge and the numbeer of voltage values recorded varies if a different load value is used or if the initial voltage of the battery is different.

The device was tested for 3 different loads and the graph plotted were as follows:

Load093 Ohms161 Ohms(Not fully charged)
Graph

232 Ohms

Parts

31
QtyValueFootprintReferences
5232lib_fp:R_0805_2012Metric_Pad1.15x1.40mm_HandSolderRL1, RL2, RL3, RL4, RL5
4100klib_fp:R_0805_2012Metric_Pad1.15x1.40mm_HandSolderR1, R3, R4, R5
4IRLML6401TRPBFlib_fp:SOT-23Q1, Q2, Q3, Q4
4MountingHolelib_fp:MountingHole_3.2mm_M3_ISO7380H1, H2, H3, H4
330klib_fp:R_0603_1608Metric_Pad1.05x0.95mm_HandSolderR7, R8, R9
1lib_fp:LOGO_2G***
110klib_fp:R_0805_2012Metric_Pad1.15x1.40mm_HandSolderR6
11klib_fp:R_0805_2012Metric_Pad1.15x1.40mm_HandSolderR2
1BATTERYlib_fp:PinHeader_1x02_P2.54mm_VerticalJ1
1Conn_01x04lib_fp:128x32_OLED_DisplayJ3
1DUTlib_fp:PinHeader_1x02_P2.54mm_VerticalJ2
1KiCad-Logo2_5mm_SilkScreenSymbol:KiCad-Logo2_5mm_SilkScreen
1NodeMCU1.0(ESP-12E)lib_fp:NodeMCU-LoLinV3_without_borderU1
1OSHW-Logo2_9.8x8mm_SilkScreenSymbol:OSHW-Logo2_9.8x8mm_SilkScreen
1SI2302Package_TO_SOT_SMD:SOT-23Q5
1SW_Pushlib_fp:SW_PUSH_6mmSW1

Questions

How big is the MAhTime PCB?

It measures 31.1 × 57.6 mm and has 2 copper layers, 1.6 mm thick.

What parts does the MAhTime use?

31 parts, built around the IRLML6401TRPBF and SI2302. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the MAhTime KiCad files?

From the Rohit04121998/mAhTime repository on GitHub, at the commit this page was made from: the board is PCB_KiCAD/mAhTime.kicad_pcb. PCBKit opens the board in the browser, with nothing to install.

Can I use the MAhTime design in my own project?

Its repository publishes it under the MIT licence: you may reuse it on that licence's terms (keep the author's notice, and for a copyleft licence share your changes alike).

Similar boards

  • 4 layers121.9 × 44.4 mmBurnedHead, the printed circuit board in 3D

    BurnedHead

    justinbalexander/BurnedHead

    A handheld game console

    92 parts45Unlicense
  • 2 layers74.8 × 49.8 mmBMW BT, the printed circuit board in 3D

    BMW BT

    Christian-Ristevski/E9X-CAN-BT

    Using BM83 and MCP2515 to add CAN-bus connected bluetooth audio to BMW E9X series

    95 parts3
  • 2 layers31.5 × 23.3 mmBLE thingy, the printed circuit board in 3D

    BLE thingy

    MarcelMG/BLE_thingy

    31 parts2
  • 2 layers250 × 250 mmRgb led cube, the printed circuit board in 3D

    Rgb led cube

    antonu17/rgb_led_cube

    98 parts
  • 2 layers50.8 × 50.8 mmAngst, the printed circuit board in 3D

    Angst

    electrodonkey/angst

    DIY camera gimbal

    90 parts
  • 6 layers176 × 70.2 mmIida devkit, the printed circuit board in 3D

    Iida devkit

    SakuGlumoff/iida-devkit

    PCB design exercise

    273 partsMIT
  • 2 layers98.5 × 59.8 mmNeuron, the printed circuit board in 3D

    Neuron

    giant-axon/lu.i-neuron-pcb

    Lu.i is an electronic neuron circuit mimicking and illustrating the basic dynamics of real, biological neurons. The printed circuit board (PCB) features a configurable, fully analog implementation of the leaky…

    90 parts73CERN-OHL-S-2.0