AC & DC Current Measurement with Arduino and LTSR 25-NP Sensor

This is another post that shows how to measure AC and DC currents using Arduino. The current sensor used in this project is LTSR 25-NP hall-effect current sensor which can be used to measure AC and DC currents.
A 1602 LCD connected to the Arduino board is used to display current values, the Arduino also sends the same values to the Laptop which can be viewed using serial monitor.
A pushbutton connected to the Arduino board to choose between AC and DC currents.

Hints:
No warranty is provided with this project, so do it at your own risk!
A part of project circuit may be subjected to high voltage which is very harmful to human body, so be-careful!

DIY circuit for Arduino uno and LTSR 25-NP current sensor

Abbreviations:
AC: Alternating Current
DC: Direct Current
TRMS: True Root Mean Square
ADC: Analog-to-Digital Converter
PCB: Printed Circuit Board
DIY: Do It Yourself
Op amp: operational amplifier

About LTSR 25-NP current sensor:
The LTSR 25-NP is a small current sensor designed for direct PCB mounting. This sensor belongs to the LTSR series of hall-effect based current sensors from LEM. This sensor generates a voltage that is proportional to the current passing through it where the generated voltage is galvanically isolated from the passing current. This means at all times, high power circuit is isolated from low power circuit.

The LTSR series consists of 3 types according to nominal primary RMS current IPN:
LTSR 25-NP  —> IPN = 25A
LTSR 15-NP  —> IPN = 15A
LTSR 6-NP   —> IPN = 6A

This type of sensors can be used to measure AC and DC currents with very good accuracy, they are also easy to use which makes them a good choice for DIY and hobbyists projects.

The LTSR sensor is supplied with unipolar supply voltage of 5 Volts. At 0 A load current, the output of this sensor is 2.5V which is the same as an internal band gap reference voltage. The sensor provides this reference voltage at Ref pin (ref in mode). The user also is able to apply an external voltage reference (ref out mode) with voltage between 1.9 and 2.7V .

At nominal primary current, the LTSR sensor output voltage is 3.125V, it is just the offset voltage (2.5V) plus nominal primary current multiplied by device sensitivity.
The sensitivity of the LTSR 25-NP sensor is 25mV/A, whereas the LTSR 15-NP has a sensitivity of 41.6mV/A and the LTSR 6-NP is 104.16mV/A .

Current measurement with Arduino and LTSR 25-NP sensor circuit:
Project circuit diagram is shown below (click on the image for better view).

Current measurement using Arduino LTSR 25-NP sensor circuit

Note that in the circuit there is 1 ground only which is the same as Arduino board ground (GND).
The Arduino uno board is represented by U1 and the LTSR 25-NP by U2.

As shown in circuit schematic, the LTSR 25-NP current sensor is connected between the AC/DC source and the load. Instead of the LTSR 25-NP the other 2 models of the same LTSR series can also be used (LTSR 15-NP and LTSR 6-NP), the only thing has to be changed is device sensitivity in Arduino code.
The voltage source may be AC or DC according to the connected load.

Hardware required:
This is a summary of circuit required parts (circuit schematic diagram may contain some component parameters not mentioned below).

  • Arduino Uno or equivalent board such as Arduino Nano (U1)
  • LTSR series current sensor (LTSR 25-NP, LTSR 15-NP, LTSR 6-NP) (U2)  —> LTSR 25-NP datasheet
  • OPA2191 op amp (U3)   —> details
  • 1602 LCD screen
  • 1 µF capacitor (C5)
  • 0.47 µF capacitor (C3)
  • 2 x 0.1 µF capacitor (C1, C2)
  • 2.2 nF capacitor (C4)
  • 2 x 10k Ohm resistor (R2, R3)
  • 330 Ohm resistor (R5)
  • 75 Ohm resistor (R1)
  • 10 Ohm resistor (R6)
  • 10k variable resistor (R2)
  • Pushbutton (S1)
  • Breadboard
  • Jumper wires

Circuit description:
The LTSR 25-NP current sensor is noted in the circuit schematic above as U2. It is supplied with voltage of 5V from the Arduino board.
Basically, the LTSR 25-NP has total of 10 pins, the 6 numbered pins are for high voltage (1 ~ 6) and the rest 4 are low voltage pins.
The low voltage pins are: +5V, 0V, Out and Ref. The +5V and 0V pins are sensor power supply pins and they are respectively connected to Arduino board 5V and GND.

LTSR 25-NP Out is sensor output voltage pin, the voltage at this pin is proportional to the current flowing through the sensor.
The output signal from the current sensor is filtered and attenuated using resistors R2 & R3 and capacitor C4. The filtrated signal is then goes to an op amp voltage follower circuit in order to properly buffer that signal, the op amp used in this project is OPA2191.

After the buffer circuit, the signal is filtered again using resistor R1 and capacitor C3 and then goes directly to Arduino analog channel 2.

The OPA2191 from Texas Instruments contains 2 independent op amps in one package. The first op amp (A) is used to buffer the LTSR 25-NP output voltage as described above.
The 2nd op amp (B) is also used as a voltage follower for the LTSR 25-NP sensor internal band gap reference (2.5V) from sensor’s Ref pin. The output of op amp B is connected to a RC circuit and then to Arduino AREF pin, it is used as positive voltage reference for the Arduino ADC module.

The 1602 LCD screen (2 rows and 16 columns) is used to display the value of the current that flows through the LTSR 25-NP sensor (load current), it is connected to the Arduino board as follows:
RS —> Arduino digital pin 3
E   —> Arduino digital pin 4
D4 —> Arduino digital pin 5
D5 —> Arduino digital pin 6
D6 —> Arduino digital pin 7
D7 —> Arduino digital pin 8
VSS, RW, D0, D1, D2, D3 and K are connected to GND,
VEE to the 10k Ohms variable resistor (or potentiometer) output,
VDD to Arduino 5V and A to Arduino 5V through 330 ohm resistor.

VEE pin is used to control the contrast of the LCD. A (anode) and K (cathode) are the back light LED pins.

The pushbutton (connected to Arduino digital pin 2) is used to choose between 3 current types: AC, DC or AC+DC.
With the Arduino code below and when AC type is selected, the Arduino calculates TRMS value of the AC current flows through the LTSR 25-NP sensor, any DC current will not be included in the results.
Alternatively, when DC type is selected, the Arduino calculates average (mean) value of the current applied to the LTSR 25-NP sensor.
However, when AC+DC type is selected, the Arduino calculates TRMS value of the current that passes through the LTSR 25-NP sensor where the DC component (offset) is included in calculations.

Current measurement with Arduino and LTSR 25-NP sensor code:
Project code is the one below, it was tested with Arduino UNO board.
This Arduino code calculates RMS values for AC and AC+DC currents, and average (mean) values for DC current. The user can switch between the 3 current calculation modes using the pushbutton connected to Arduino digital pin 2, the default current type is AC (at startup).

Simply the average (mean or DC offset) value in discrete-time is the sum of all sample values divided by number of samples:

mean value equation

And the RMS value in discrete-time can be calculated using the following equation:

RMS value equation

The Arduino uno board microcontroller (ATmega328P) contains a 10-bit ADC module, the positive voltage reference is 2.5V means that a 2.5V is digitally represented by 1023 and 0V is represented by 0.

To get more precise and higher resolution readings, I wrote a simple code to use what’s known as oversampling and decimation technique to add another 2 bits to the 10 bits of the ADC. This gives us a total of useful 12-bit words.

Firstly, I declared an array of 256 elements named r_array , it is used to store reading samples which are used later to calculate average (dc offset) and RMS values.
With oversampling of 2 bits, we’ve to do 16 analog readings for each element of the ‘r_array’ variable. These readings are summed and divided by 4, where 16 = 4² and 4 = 2² and this ² is number of oversampling bits.

Oversampling code is located in a void function named get_smaples() which is used to fill sample array r_array by doing a total of 4096 (16 x 256) successive ADC readings.

Programming hints:
At startup, the Arduino MCU executes an auto calibration code, so before powering the Arduino make sure that there’s no current flows through the LTSR 25-NP sensor, otherwise results of DC and AC+DC current calculations may not be accurate, auto calibration has no effect on AC calculations.

I added the auto calibration code to read and save circuit default offset voltage. The auto-calibrated DC offset value is saved to a float variable named: dc_offset.

Functions used in the Arduino code:
void current_type_set(): selection of current type AC, DC or AC+DC is made by pressing the pushbutton connected to digital pin 2. When pressed, the Arduino immediately executes an interrupt routine and then in the loop() function a variable named current_type is incremented, it is later used to distinguish between the 3 current types.

void gain_set(uint8_t g): this function is used to change circuit gain according to g.

void get_smaples(): this function fills the sample array mentioned above with 256 12-bit of data.

bool debounce (): used to debounce the pushbutton connected to Arduino digital pin 2. Returns true if OK and false if error.

Full Arduino code:

The following small video shows my DIY circuit for this project, to test the accuracy of my circuit I connected a multimeter in series between the LTSR 25-NP sensor and the load.
Note that wires connecting the Arduino uno and the DIY PCB are soldered on the back of the two boards, this removes small voltages & noise caused by poor connections between jumper wires and Arduino board female header pins.

Related Projects:
AC Current Measurement using Arduino and Current Transformer
Measure AC & DC Currents with Arduino and ACS758 Sensor
Interfacing Arduino with Current Transformer – AC Current Measurement
AC Current Measurement using Arduino and Current Transformer


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

1 thought on “AC & DC Current Measurement with Arduino and LTSR 25-NP Sensor”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top