DC sensor

Hi everyone,

I am monitoring AC, temperature and humidity using an EmonTx and EmonTh to comunicate with EmonBase and send data to EmonCMS.

Now i want to measure DC to monitor a solar panel.
I am thinking about using a voltage divider to get an analog input, but not sure if i can modify my EmonTh or EmonTx to read the value and send to EmonCMS.

I found some options but not sure if it is possible:

  • voltage divider
  • hall effect sensor
  • ACS 712 current sensor

Any help??

The emonTx is relatively easy. A5 is available on the screw terminal block, and A6 is available in the RJ45 connector. Both are used by the standard sketch, so if your sketch is based on that, you must remove the code that sets these. (A5 is also D19 and powers the One-wire temperature sensor, A6 is also D20).
Both need 0 - 3.3 V to read 0 - 1023. Any positive voltage greater than 3.3 V or a negative voltage risks damaging the input.

It would be possible, but not easy, to convert the emonTH. ADC 3 appears on the screw terminal block, ADC0, ADC6 & ADC 7 are free, but are only available as pads next to the processor.

The big problem with measuring voltage is isolation. You MUST be certain that nothing else is ever connected to your emonTx while it has a direct connection to your battery, otherwise you may easily have an earth fault that is likely to damage both the emonTx and the computer it is connected to.

People have successfully used the ACS712, that is isolated to 2 kV so you don’t have the same problem as with the voltage. But it needs a 5 V supply, so that too must be isolated if you use a direct galvanic connection to measure voltage.

Thanks Robert.

Finally, I have decided for the voltage divider. I set up the circuit and checked with a voltmeter that the voltage i am measuring is right.
Then I connect the input voltage (3V) to A5 in the emonTx and Ground.
I am receiving data from CT sensors in Emoncms, but not from A5.

As you said before, I should remove the standard code, but not sure how and where (EmonHub, Rpi…)

Any help??

It is in the emonTx where you must change the sketch.

Download the source files from Github.
I’m giving the line numbers for the copy of the sketch I have here. Yours might be different if there has been a change that I don’t know about.
[Edit - line numbers had changed.]

First, remove everything concerning A5 / D19 & A6 / D20.
These are
Line 120: const byte DS18B20_PWR= 19;
Line 182: pinMode(DS18B20_PWR, OUTPUT);
Line 292: digitalWrite(DS18B20_PWR, HIGH); delay(100);
Line 304: digitalWrite(DS18B20_PWR, LOW);
Line 452: digitalWrite(DS18B20_PWR, HIGH);
Line 460: digitalWrite(DS18B20_PWR, LOW);

I don’t think A6 / D20 is used in the default sketch.

Note: You must connect your temperature sensor using the RJ45 socket, or move the power connection to the 3.3 V power on the screw connector. The screw connector labelled “ADC5 / Dig19 DS18B20 PWR” will become one of your inputs.

Now you need to add some code to read the new inputs and send the data. I you don’t want the current, simply leave that out:

In lines 145 - 146, add two new variables. I’ll call them Ipv & Vpv:
  int power1, power2, power3, power4, Vrms, Ipv, Vpv, temp[MaxOnewire];
  unsigned long pulseCount;

Before line 463 if (pulseCount) add these new lines:
emontx.Vpv = analogRead(A5);
emontx.Ipv = analogRead(A6);

If you wish, in the next section you can add:
Serial.print(",Ipv:"); Serial.print(emontx.Ipv);
Serial.print(",Vpv:"); Serial.print(emontx.Vpv);

Compile and reload the sketch into your emonTx. This will give you the PV voltage and current not scaled - you will get a raw number 0 - 1023 representing the input voltage over the range 0 - 3.3 V. You can adjust the scale in emonHub to read Volts & Amps.
I cannot test this, because I do not have your PV.

Now change emonhub.conf to match. If your emonTx is Node 8, it will be this (change whichever node is your emonTx):
[[8]]
   nodename = emonTx_3
   firmware =V2_3_emonTxV3_4_DiscreteSampling
   hardware = emonTx_(NodeID_DIP_Switch1:OFF)
   [[[rx]]]
     names = power1, power2, power3, power4, Vrms, Ipv, Vpv, temp1, temp2, temp3, temp4, temp5, temp6, pulse
     datacodes = h,h,h,h,h,h,h,h,h,h,h,L
     scales = 1,1,1,1,0.01,1,1,0.1,0.1, 0.1,0.1,0.1,0.1,1
     units =W,W,W,W,V,A,V,C,C,C,C,C,C,p

It is the two numbers “1” that you added in ``scales = …" that you change to give the correct current & voltage. Example: if 1023 represents 46.7 V, you put the number 0.04565 (= 46.7 ÷ 1023)
Note: when you have loaded the new sketch and before you change emonhub.conf, it will not receive any data from your emonTx.

I think that will work, but I don’t have your set-up so I cannot prove it.

Remember, unless you know that your PV system is isolated from everything else, you must NEVER connect anything except the a.c. adapter and the 5 V USB adapter to the emonTx. The only exception is when the thing you connect is also completely isolated from everything else, so you can connect a laptop running on its internal battery. Also, be aware that any metal parts may be live.