# Burden resistor for a Hall Current Sensor to run in CT port?

**URL:** <https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338>\
**Category:** emonTx\
**Created:** [6 July 2019 02:18 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338 "2019-07-06T02:18:17Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ross](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/ross/32/15141_2.png) [@Ross](https://community.openenergymonitor.org/u/Ross)\
**Post date:** [6 July 2019 02:18 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/1 "2019-07-06T02:18:18Z")

</div>

I’m not the brightest when it come to formulas etc and electronic, but i am wondering if possible can i run a Allegro ACS758 Series Bi-directional Hall Current Sensor in a emonTx CT port, I know both are analogue output but the CT sensors are based on a max of 1V output but as far as i can tell that the Allegro ACS758 Series Hall Current Sensor is based on a 5V output, as i dont want to fry the emonTx CT port with over votage, can i put a burden resistor across the output of the Hall Current Sensor to reduce the voltage within the specs of want would have been a CT sensor.  
Want i am trying to achieve is the monitor a DIY lithium battery back on my hybrid inverter solar battery bank, i know i will have reconfigure the comfig file within the enomTx with some sort of maths calc to read the correct amps

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [6 July 2019 05:42 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/2 "2019-07-06T05:42:24Z")

</div>

The purpose of a burden resistor is to convert the _ **current** _ output of the c.t. into a _voltage_ that can be sensed by the analogue _voltage_ input of the analogue to digital converter. So a burden resistor won’t help you.

I _think_ (I don’t have time today to read the data sheet carefully) that you must run your sensor from 3.3 V rather than 5 V, and a direct connection, removing the SMT burden resistor, will be needed.

I’ll look into this fully in a couple of days time.

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [7 July 2019 00:04 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/3 "2019-07-07T00:04:17Z")

</div>

I figured I needed to answer this before it got buried:

> [@Ross](#):
>
> as far as i can tell that the Allegro ACS758 Series Hall Current Sensor is based on a 5V output

Page 2 (Features & benefits) says it’s good for 3.0 to 5.5 V, single supply operation, and the table “COMMON OPERATING CHARACTERISTICS” on page 6 also states that the minimum supply voltage is 3 V and the maximum 5.5 V. Don’t be misled by all the performance characteristics being given for a 5 V supply, this means that to use it with the emonTx you can and you should supply it with 3.3 V - not taken from the emonTx unless the emonTx itself is supplied by 5 V via the USB or FTDI port (the internal supply from the a.c. adapter cannot provide sufficient current) and check the Wiki if you’re using any other add-ons to your emonTx - like temperature sensors, because there’s a limit to the current you can take from the 3.3 V terminals.

As I mentioned, you need to remove the burden resistor for the input you’re using. It is the larger SMT resistor immediately behind the jack socket. You can use the hole in the pcb that’s furthest from the a.c. adapter (voltage input) socket or the plug sleeve to connect to your ACS758 output pin.

The table also states that the quiescent output voltage is VCC/2. The emonTx’s analog input will give you a value of 511 using `analogRead(inPin)` with zero current flowing. (Or it should do - expect the value to be a few counts either way. In your sketch, you first need to subtract that - we call it an ‘offset’ - and be prepared to adjust that offset accordingly so the the result is zero with no current flowing.

And on the next page - Performance Characteristics - you have the sensitivity specified, which should allow you to calculate what to multiply the number you have by to give the current in Amperes:  
The ACS758 will give you 0 V to 3.3 V out for maximum negative current to maximum positive current, and these voltages (and hence the currents) correspond to the numbers 0 - 1023 when you use analogRead(inPin), with zero current giving you 1.65 V or the number 511. And from that, you can calculate a “scale factor” which you apply to give the current in Amperes.  
I can’t help any more with that because you haven’t said which version you’re using.

Now your sketch (“the comfig file within the enomTx”) won’t use emonLib for this input, so where the standard sketch does `calcVI( )`, you’ll need a line that will look like:  
BatteryCurrent = (analogRead(inPin) - offset) \* scaleFactor;

You will also probably need to smooth the BatteryCurrent value, because I’ll expect it to jump about a bit from one reading to the next. You can do that with a couple of lines more:

FilteredBatteryCurrent = FilterConstant \* BatteryCurrent + (1-FilterConstant) \* last\_FilteredBatteryCurrent;  
last\_FilteredBatteryCurrent = FilteredBatteryCurrent;

where you adjust FilterConstant (always a number less than 1) to give the performance you need - close to 1 and the filtered value will respond quickly but jump about more, and the smaller it get the slower but steadier it will be.

Hopefully a minor point: A note to the table says “Customers that plan to operate the device from a 3.3 V regulated supply should contact their local Allegro sales representative regarding expected device accuracy levels under these bias conditions.” I would not expect the values to deviate by a large amount, but it means they don’t guarantee the values given in the tables will apply to you. But you can largely compensate for that by calibrating it against a known good ammeter and adjusting “offset” and “scaleFactor” to give the correct values.

---

<div class="post-metadata">

**Author:** ![Ross](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/ross/32/15141_2.png) [@Ross](https://community.openenergymonitor.org/u/Ross)\
**Post date:** [8 July 2019 09:53 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/4 "2019-07-08T09:53:40Z")

</div>

I have 2 new emonTXs which are v3.4 coming in the post and looking are experimenting with one of these as I brought it as a spare for just for that purpose.Mail is pretty quick from UK to Australia, so at moment it’s a waiting game

---

<div class="post-metadata">

**Author:** ![Ross](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/ross/32/15141_2.png) [@Ross](https://community.openenergymonitor.org/u/Ross)\
**Post date:** [13 July 2019 06:28 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/5 "2019-07-13T06:28:37Z")

</div>

New emonTX has turned up, and first stage i have removed the burden resistors

 ![20190713_160803](https://community.openenergymonitor.org/uploads/default/original/2X/2/20e5d551974a640e11c6264e6cc3584ceca2c69a.jpeg) ![20190713_162053](https://community.openenergymonitor.org/uploads/default/original/2X/9/9d53868baf285ed4719ce34458e3ecad78c292c2.jpeg)

---

<div class="post-metadata">

**Author:** ![Ross](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/ross/32/15141_2.png) [@Ross](https://community.openenergymonitor.org/u/Ross)\
**Post date:** [16 July 2019 15:47 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/6 "2019-07-16T15:47:57Z")

</div>

Just on a savage learning curve in firmware changing, I have added the extra text to the config, but when verify it i get an error saying ,  
‘showString’ was not declared in this scope  
any chance at how to get around this error Robert.Wall

---

<div class="post-metadata">

**Author:** ![Bill.Thomson](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/bill.thomson/32/1834_2.png) [@Bill.Thomson](https://community.openenergymonitor.org/u/Bill.Thomson)\
**Post date:** [16 July 2019 17:26 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/7 "2019-07-16T17:26:32Z")

</div>

> [@Ross](#):
>
> i get an error saying ,  
> ‘showString’ was not declared in this scope

Here’s a thread about that same problem:

> [@Arduino IDE problem - showString( )](https://community.openenergymonitor.org/t/arduino-ide-problem-showstring/8597/):
>
> Some weeks ago I decided to become familiar with the Arduino IDE method for updating an emonTx firmware/sketch. I installed it on my Windows laptop together with the required Libraries. I was successful in burning the latest 3 phase sketch with Calibration constants which I had determined after a few experiments. It all worked perfectly well. Today I decided to further adjust the Calibration constants and made the necessary changes to the src.ino file. I expected the updating process to be a…

HTH

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [17 July 2019 00:06 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/8 "2019-07-17T00:06:45Z")

</div>

Thanks, Bill.

The short version is

All it needs is a **declaration** of showString, in the main file:

`static void showString (PGM_P s);`

I usually insert those just above the first executable statement, viz:

```auto
OneWire oneWire(W1PIN);

static void showString (PGM_P s);

void setup()
{
... etc

```

---

<div class="post-metadata">

**Author:** ![Ross](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/ross/32/15141_2.png) [@Ross](https://community.openenergymonitor.org/u/Ross)\
**Post date:** [17 July 2019 05:45 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/9 "2019-07-17T05:45:41Z")

</div>

> [@Robert.Wall](#):
>
> Now your sketch (“the comfig file within the enomTx”) won’t use emonLib for this input, so where the standard sketch does `calcVI( )` , you’ll need a line that will look like:  
> BatteryCurrent = (analogRead(inPin) - offset) \* scaleFactor;

Just getting back to it before i head away for work for the next 6 days, I am looking for the line calcVI( ), but the only line that comes close to looking like that is ct1.calcVI(no\_of\_half\_wavelengths,timeout);  
Is this the line i have to replace?

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [17 July 2019 10:09 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/10 "2019-07-17T10:09:32Z")

</div>

Yes, that is the one. (There are many versions of the parameters into the calcVI method - I left them out in the hope that you’d realise that the important part was the method call to **calc** ulate **V** voltage and **C** urrent was what you needed to replace.)

---

<div class="post-metadata">

**Author:** ![Ross](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/ross/32/15141_2.png) [@Ross](https://community.openenergymonitor.org/u/Ross)\
**Post date:** [25 July 2019 14:07 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/11 "2019-07-25T14:07:22Z")

</div>

Hi Robert.Wall, I have replaces the calcVI( ) with the line BatteryCurrent = (analogRead(inPin) - offset) \* scaleFactor;, I now have a error message of ‘class EnergyMonitor’ has no member named ‘BatteryCurrent’ , this appears 4 times, one each for CT from CT1 to CT4  
This will have something to do with the lines?  
FilteredBatteryCurrent = FilterConstant \* BatteryCurrent + (1-FilterConstant) \* last\_FilteredBatteryCurrent;  
last\_FilteredBatteryCurrent = FilteredBatteryCurrent;  
as started early which i have not added these lines, do these lines go into the config or the sketch?  
Sorry about this but i am not had to deal with this sort of programming.

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [25 July 2019 16:05 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/12 "2019-07-25T16:05:22Z")

</div>

> [@Ross](#):
>
> a error message of ‘class EnergyMonitor’ has no member named ‘BatteryCurrent’

I didn’t realise that you were converting all four inputs.

Somewhere, you have put `ct1.BatteryCurrent` etc - that’s what the error message is saying. And it’s right. EmonLib doesn’t know about BatteryCurrent.

If you’re doing that for all four inputs, then you need 4 separate variables: `BatteryCurrent1`, `BatteryCurrent2`, `BatteryCurrent3`, `BatteryCurrent4`  
and likewise with `FilteredBatteryCurrent1` etc  
and `last_FilteredBatteryCurrent1` etc.

And those lines do go into the sketch, and it’s `FilteredBatteryCurrent1` that you’re going to send to emonCMS or wherever.

So instead of

```auto
  if (CT1) 
  {
   if (ACAC) 
   {
     ct1.calcVI(no_of_half_wavelengths,timeout); emontx.power1=ct1.realPower;
     emontx.Vrms=ct1.Vrms*100;
   }
   else
     emontx.power1 = ct1.calcIrms(no_of_samples)*Vrms; // Calculate Apparent Power 1 1480 is number of sample

  }
  emontx.power1 = ct1.Irms * 1000.0;

```

You should have

```auto
  if (CT1) 
  {
     BatteryCurrent1 = (analogRead(inPin) - offset1) * scaleFactor1;
     FilteredBatteryCurrent1 = FilterConstant * BatteryCurrent1 + (1-FilterConstant) * last_FilteredBatteryCurrent1;
     last_FilteredBatteryCurrent1 = FilteredBatteryCurrent1;

     emontx.power1 = FilteredBatteryCurrent1 * 1000.0;
   }

```

and you need to repeat that 4 times for each input - putting the appropriate pin number in place of “inPin”.  
Also of course, each input will probably need to have its own offset and scale factor.

“power1” will actually be a current - you can rename it throughout if you wish. The units - when you’ve scaled it - will be mA on account of multiplying by 1000 (That’s because we send integer values to emonCMS, and it surely won’t go above 32 A.)

[There’s no need to be sorry - it’s called learning.]

---

<div class="post-metadata">

**Author:** ![Ross](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/ross/32/15141_2.png) [@Ross](https://community.openenergymonitor.org/u/Ross)\
**Post date:** [26 July 2019 02:30 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/13 "2019-07-26T02:30:11Z")

</div>

I have re-entered the extra text for each input and renamed power1 etc to current1 etc

> [@Robert.Wall](#):
>
> and you need to repeat that 4 times for each input - putting the appropriate pin number in place of “inPin”.

Where you have said appropriate pin number in place of “inPin”.  
BatteryCurrent1 = (analogRead(inPin) - offset1) \* scaleFactor1;  
will that read like?  
BatteryCurrent1 = (analogRead(1) - offset1) \* scaleFactor1;  
etc etc.  
I have a error message of  
‘BatteryCurrent1’ was not declared in this scope

That i have now reads like

```auto
 if (ACAC) {
    delay(200); //if powering from AC-AC adapter allow time for power supply to settle
    emontx.Vrms=0; //Set Vrms to zero, this will be overwirtten by CT 1-4
  }

  // emontx.current1 = 1;
  // emontx.current2 = 1;
  // emontx.current3 = 1;
  // emontx.current4 = 1;

   if (CT1) 
  {
     BatteryCurrent1 = (analogRead(inPin) - offset1) * scaleFactor1;
     FilteredBatteryCurrent1 = FilterConstant * BatteryCurrent1 + (1-FilterConstant) * last_FilteredBatteryCurrent1;
     last_FilteredBatteryCurrent1 = FilteredBatteryCurrent1;

     emontx.current1 = FilteredBatteryCurrent1 * 1000.0;
   }

   if (CT2) 
  {
     BatteryCurrent2 = (analogRead(inPin) - offset1) * scaleFactor1;
     FilteredBatteryCurrent2 = FilterConstant * BatteryCurrent2 + (1-FilterConstant) * last_FilteredBatteryCurrent2;
     last_FilteredBatteryCurrent2 = FilteredBatteryCurrent2;

     emontx.current2 = FilteredBatteryCurrent2 * 1000.0;
   }

   if (CT3) 
  {
     BatteryCurrent3 = (analogRead(inPin) - offset1) * scaleFactor1;
     FilteredBatteryCurrent3 = FilterConstant * BatteryCurrent3 + (1-FilterConstant) * last_FilteredBatteryCurrent3;
     last_FilteredBatteryCurrent3 = FilteredBatteryCurrent3;

     emontx.current3 = FilteredBatteryCurrent3 * 1000.0;
   }

   if (CT4) 
  {
     BatteryCurrent4 = (analogRead(inPin) - offset1) * scaleFactor1;
     FilteredBatteryCurrent4 = FilterConstant * BatteryCurrent4 + (1-FilterConstant) * last_FilteredBatteryCurrent4;
     last_FilteredBatteryCurrent4 = FilteredBatteryCurrent4;

     emontx.current4 = FilteredBatteryCurrent1 * 1000.0;
   }

  if (!ACAC){ // read battery voltage if powered by DC
    int battery_voltage=analogRead(battery_voltage_pin) * 0.681322727; // 6.6V battery = 3.3V input = 1024 ADC
    emontx.Vrms= battery_voltage;
  }

  if (DS18B20_STATUS==1)
  {
    digitalWrite(DS18B20_PWR, HIGH);
    Sleepy::loseSomeTime(50);
    for(int j=0;j<numSensors;j++)
      sensors.setResolution(allAddress[j], TEMPERATURE_PRECISION); // and set the A to D conversion resolution of each.
    sensors.requestTemperatures();
    Sleepy::loseSomeTime(ASYNC_DELAY); // Must wait for conversion, since we use ASYNC mode
    for(byte j=0;j<numSensors;j++)
      emontx.temp[j]=get_temperature(j);
    digitalWrite(DS18B20_PWR, LOW);

```

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [26 July 2019 11:13 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/14 "2019-07-26T11:13:45Z")

</div>

> [@Ross](#):
>
> I have a error message of  
> ‘BatteryCurrent1’ was not declared in this scope

Yes - you need to declare all the new variables at the beginning (sorry, I didn’t realise you didn’t know that).

So at the beginning of `loop( )`, you’ll need:

```auto
double BatteryCurrent1, FilteredBatteryCurrent1, last_FilteredBatteryCurrent1;

```

etc for all 4

and at the top of the sketch, above `setup( )`, I’d put all the constant values that you need:

```auto
int offset1 = 512;  
double scaleFactor1 = 123.4;
int offset2 = 512;  
double scaleFactor1 = 123.4;
int offset3 = 512;  
double scaleFactor1 = 123.4;
int offset4 = 512;  
double scaleFactor1 = 123.4;

```

Of course, you’ll need the numbers there that give you the correct calibration. I can’t calculate that, because I don’t know which ACD758 you’ve got. But the data sheet and my post (no.3) gives you all the information you need

And yes, that’s right for inPin. The pins are 1-4 for c.t. sockets 1-4 (the voltage socket is 0)

---

<div class="post-metadata">

**Author:** ![Ross](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/ross/32/15141_2.png) [@Ross](https://community.openenergymonitor.org/u/Ross)\
**Post date:** [26 July 2019 15:07 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/15 "2019-07-26T15:07:51Z")

</div>

> [@Robert.Wall](#):
>
> Of course, you’ll need the numbers there that give you the correct calibration. I can’t calculate that, because I don’t know which ACD758 you’ve got. But the data sheet and my post (no.3) gives you all the information you need

ACS758LCB-100B-PFF-T ±100Amps 20mV/A. Bidirectional  
The maxamin current flow will be 50Amps in either direction

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [26 July 2019 15:36 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/16 "2019-07-26T15:36:19Z")

</div>

Here’s how to calculate it:

The ACS sensitivity is 20 mV/A, and the ADC inside the emonTx gives you 0 - 1023 counts for 0 - 3.3 V (nominally).

Therefore 1 count represents (3.3 V ÷ 1023 counts ) × (1 A ÷ 20 mV ) = 0.1613 A  
And that’s your scale factor 0.1613 A / count.

---

<div class="post-metadata">

**Author:** ![Ross](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/ross/32/15141_2.png) [@Ross](https://community.openenergymonitor.org/u/Ross)\
**Post date:** [27 July 2019 03:16 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/17 "2019-07-27T03:16:58Z")

</div>

> [@Robert.Wall](#):
>
> 0.1613

int offset1 = 512;  
double scaleFactor1 = 0.1613;  
int offset2 = 512;  
double scaleFactor1 = 0.1613;  
int offset3 = 512;  
double scaleFactor1 = 0.1613;  
int offset4 = 512;  
double scaleFactor1 = 0.1613;

When trying to compile i am getting a error of

redefinition of ‘double scaleFactor1’

on the last line after int offset4 = 512;

I know that CT4 is a slightly different setup on calibration out of the box compared to the other 3 CTs with a different burden resistor, has that got something to do with the error that the other 3 CTs didn’t error on?

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [27 July 2019 10:54 UTC](https://community.openenergymonitor.org/t/burden-resistor-for-a-hall-current-sensor-to-run-in-ct-port/11338/18 "2019-07-27T10:54:56Z")

</div>

It was very hot here yesterday, and my brain wasn’t working. I forget to renumber those when I copied and pasted.
