Wireless energy monitor

I have developed the below monitor, based upon the code and designs discussed elsewhere on this site. 

Notable variations from the basic design are: 

  • Programmable Gain Amp on the current input. Since the current can vary so massively (wheras voltabe is reasonably constant), it can be hard to get good resolution from the ADC all the wave from 1-60A. Using an MCP6S21, controlled via SPI by the microcontroller, the gain can be varied as the current changes, to ensure full use is made of the ADC. 
  • 230vAC <> 2 9v AC secondary coil transformer is used both to power the circuit, and to provide a voltage waveform to sample. This introduces some small harmonic distortion, but also makes for a compact design with only a single plug socket used up. 
  • XRF (cheap alternative to zigbee, woth identical pinouts) used to send serial data wirelessly - although current version also has a max233 serial driver on board for a wired connection if needed. 
  • I used a dual rail2rail opamp, configured as a unity buffer,  both to provide a low output impedance for the voltage input to the ADC (because the ADC is muxed, and I want the input to settle as quickly as possible to avoid interference between current and voltage readings). Since the opamp had 2 amps in the package, I used the second to provide a low impedance 2.5v offset voltage. Not really needed, but can't do any harm. 
  • As many others here have done, I used an efergy current clamp, terminating in a mono 3.5mm jack

...and at the other end of the wireless link: 

The modified code samples the current, sets the gain, calculates the output data, outputs as XML over the UART, and then repeats - dumping data to the serial line about every 2 seconds. Currently, I feed this into serial<>ethernet converter, which itself is then scraped by an external server. A php script parses the XML thus obtained, which is logged to a mySQL database and used to create the output here: 

http://energy.bbarker.co.uk 

I hope to rebuild on a proper PCB, so far smaller, if I have time, as well as socumenting the circuit properly. 

In the meantime, below is the circuit schematic:


The sketch used to control the above is available here. It is based heavily on some old eMon code - with a few additions, such as the ability to control the PGA

The below php is used to read data from my serial<>ethernet conevrter every 10 seconds (port forwarding set up to my home router), parse the data and insert it into a database for display

<? 
header ("content-type: text/xml");
putenv("TZ=GMT"); //my electricity supplier uses GMT, so I might as well also...
$now = date ("Y-m-d H:i:s");

$port=80;
$host="ip_address";

set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Unable to create socket\n");
$client = socket_connect($socket,$host,$port) or die("Unable to connect socket\n");
$data=socket_read($socket,550000,PHP_NORMAL_READ);
echo $data;


preg_match_all('/<V>(.*)<\/V><A>(.*)<\/A><VA>(.*)<\/VA><W>(.*)<\/W><PF>(.*)<\/PF>
<F>(.*)<\/F><GAIN>(.*)<\/GAIN><PLOT_T>(.*)<\/PLOT_T><ADC_I>(.*)<\/ADC_I><ADC_V>
(.*)<\/ADC_V><IPLOT>(.*)<\/IPLOT><VPLOT>(.*)<\/VPLOT>/',$data,$results);

$volts=$results[1][0];
$amps=$results[2][0];
$va=$results[3][0];
$pow=$results[4][0];
$pf=$results[5][0];
$freq=$results[6][0];
$gain=$results[7][0];
$plotTime=$results[8][0];
$iPer=$results[9][0];
$vPer=$results[10][0];
$iPlot=$results[11][0];
$vPlot=$results[12][0];

$v=explode(",",$vPlot);

$peak=0;
foreach($v as $value){
	if($value>$peak)
		$peak=$value;
}
$p2p=2*$peak;

$host = "localhost";
$uname = "username";
$pwd = "passw";
$db = "database";

$con = mysql_connect($host,$uname,$pwd);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($db, $con);
$qry="INSERT INTO consumption (volts, p2p, amps, apparent, power, freq, pf,
gain, iPer, vPer,timeLog) VALUES ($volts, $p2p,$amps, $va, $pow, $freq, $pf, 
$gain, $iPer , $vPer, '$now')";
echo $qry."<br>";
mysql_query($qry);
	
$qry="UPDATE latestPlot SET timeLog='".$now."', plotTime=".$plotTime.", 
vPlot='".$vPlot."', 
iPlot='".$iPlot."'";
	
mysql_query($qry);

mysql_close($con);
?> 

 


 

Any questions - ben at bbarker dot co dot uk

TrystanLea's picture

Re: Wireless energy monitor

Great work! thanks for posting your work up here, really interesting addition of the programmable gain and using the same transformer. I see you say your transformer is 2x 9V secondary. Are you using a dual polarity full-wave center tap rectifier configuration like the one half way down this page: http://www.allaboutcircuits.com/vol_3/chpt_3/4.html, its meant to reduce total harmonic distortion compared with a bridge rectifier configuration right? I looked into it a while back and did some LTspice simulations but never built the circuit.

Love the way you can see the waveform in the webpage!

Thanks for sharing. Trystan

Ben's picture

Re: Wireless energy monitor

I did try using a centre-tapped transformer, but found that since they were not isolated from each other I got some very strange results.

The transformer I ended up using has two independent secondaries. Generally these are designed to be used either in the USA, or the EU - by wiring them either in parallel or series you can get (roughly) the same secondary voltage whether your primary is 110 or 230. I just left them entirely separate though, and then ran one of them through a diode ring and voltage regulator.

TrystanLea's picture

Re: Wireless energy monitor

What a good idea, that keeps both functions nice and isolated and it wont matter that the supply from the diode ring is floating, exellent! for some reason I did not think of that.