Energy monitoring with Arduino and current clamp sensor

SNS-CURRENT

SNS-CURRENT-CT013-100A is split core current transformer which allow you to non-intrusively measure AC current. It’s safe even for people who do not know electronics as there is no access to high voltages etc.

All you have to do is to clamp the current sensor around one of the wires where the current flows. Note if you clamp the both wires you will not measure anything as the current flow from one wire will neutralize the current flow from the other wire and the sum will be always 0.

SNS-CURRENT-1

The sensor easily clamps around the current flow wire:

SNS-CURRENT-2

On the other end the sensor have 3.5 mm audio jack where you can plug in mating connector and connect to Arduino.

As any other transformerSNS-CURRENT-CT013-100A has primary and secondary windings, the ratio is 100:0.05 i.e. when 100A flow through primary 1 turn wire the secondary coil will have 50mA.

The current transformers must always have burden resistor connected to the second coil, the purpose is to measure the voltage drop on this resistor which will be proportional to the input current. This burden resistor value also should be low enough to prevent core saturation.

Safety: Current transformers should never operate without burden resistor, as if left open very high voltage may generate through second winding which to cause sparking. So never use this sensor without connecting it to proper circuit with burden resistor!

ConnectingSNS-CURRENT-CT013-100A to Arduino is well explained here. We have nothing to add. Based on same setup we tested the emon library and it works perfectly.

We used for our setup OLIMEXINO-32U4 + MOD-LCD3310 and breadboard where two 10K 1% resistors + 10 uF capacitor make the bias circuit to the sensor with 33 ohm 1/4W 1% burden resistor connected.

arduino-sns

For device under test we used toaster and we clamped one of the heater wires:

toaster

The Arduino code is quite simple:

#include "lcd3310_GPIO.h"
#include <math.h>
#include "EmonLib.h"

EnergyMonitor emon1;
String toPrint1, toPrint2;
double Irms, thePower;
char buffer1[30], buffer2[30];

void setup()
{
 Serial.begin(9600);
 emon1.current(1, 111.1);  //pin for current measurement, calibration value
 pinMode(8, OUTPUT);   //enable UEXT power supply
 digitalWrite(8, LOW);
 LCDInit();   //initialize LCD display
 LCDContrast (0xFF);
 LCDClear();
 LCDUpdate();
}

void loop()
{
 Irms = emon1.calcIrms(1480); // measure current
 thePower = Irms*230.0;   // we assume voltage is 230VAC if you add transformer to connect to other input you can measure real voltage too

 toPrint1 = "Power:" + String((int)thePower) + "." + String(((unsigned int)(thePower*100))%100) + " ";
 toPrint2 = "Current:" + String((int)Irms) + "." + String(((unsigned int)(Irms*100))%100) + " ";
 toPrint1.toCharArray(buffer1, 30);
 toPrint2.toCharArray(buffer2, 30);
 LCDStr(0, (unsigned char *) buffer1, 0);
 LCDStr(2, (unsigned char *) buffer2, 0);
 LCDUpdate();   // print power and current
 delay(10);
}

as you see emon library is very easy to use, so with just few component andSNS-CURRENT-CT013-100A you can easily monitor your home power consumption, log it to the cloud with ESP8266 for instance etc.

When the toaster is switched on the power is displayed:

power

If you look at the first picture when the toaster is not switched on there is still some 0.012A displayed and fake 28 W energy registered, this is just noise on ADC input. The easiest way is to filter this noise in software and if energy is less 30W to ignore it.

New Product in stock: Ultrasound distance measurement sensor SNS-US020 for range 2-200 cm with 0.3cm accuracy

SNS-US020-1

SNS-US020 is low cost ultrasonic sensor, perfect for your next robot project. It measures the distance by sending ultrasonic waves and reading back when the reflected wave. SNS-US020 operates with 5V and requires only 3mA in active mode. Note that for best results the reflection must be in hard surface, soft surfaces tend to absorb ultrasonic waves and weak the reflected signal.

Features:

  • power supply 5V
  • consumption 3 mA
  • distance 2-200 cm
  • accuracy +-0.3 cm
  • working angle 15 degree
  • trigger and echo TTL 5V
  • operating temperature 0-70C
  • dimensions 45 x 20 x 15 mm

Once trigger pulse of 10 uS is detected to trigger IO the module sends 8 pulses with 40kHz and listen to receive the reflected signal, then calculates the distance assuming speed of sound 340m/s. No temperature compensation is used for the calculation so there is error in the measurement depend on ambient temperature.

Signals to be connected:

  • VCC
  • Trig
  • Echo
  • GND

Can be used directly with Arduino with the provided code. Works perfectly up to 200 cm. All claims you will see on the net for similar devices that works up to 4-7 meters are false, so small sender/receiver can’t achieve such distance in real world.

Here is video of the demo project:

Measuring temperatures from -250C to +1600C with AVR-T32U4 Arduino Leonardo and MOD-TC-MK2-31885 + thermocouple

Image

MOD-TC-MK2-31885 is UEXT module which uses MAX31885 and allow temperatures in range -250C to +1600C to be measured with proper thermocouple.

For this demo we use TC-K-TYPE which is low cost K-type thermocouple.

When the thermocouple is connected pay attention that it have polarity i.e. if your measurements start to decrease when you increase the thermocouple end temperature you have to swap the thermocouple wires to the connector.

Another issue we got with Arduino 1.0.4 is that Serial print from time to time stop working on Leonardo and several uploads usually solve the problem, we guess this is some USB port problem and Leonardo is not properly enumerated as CDC serial port every time.

Also I2C library on Leonardo sometimes beahve weird and in this case you have to decrease I2C speed a bit. So if the sketch do not work correctly just edit TWI_FREQ to 80000L in:

C:\arduino-1.0.4\libraries\Wire\utility\twi.h

#ifndef TWI_FREQ
 #define TWI_FREQ 100000L
 #endif

You can watch the demo at this video: http://www.youtube.com/watch?v=ltS5ZEJiCEM

As you can see there are two temperatures which are measured: the temperature on the thermocouple TC and the internal MAX31855 temperature INT (i.e. cold end thermocouple temperature).

Also MAX31885 recognize if the thermocouple is disconnected, shorted or connected to VCC.

The demo code is at GitHub: https://github.com/OLIMEX/DUINO/tree/master/AVR/MOD-TC-MK2-31885

iMX233-OLinuXino-MAXI measure temperatures -200C to +700C with 0.25 resolution

Image

MOD-TC-MK2-31855 allow tempearture measurement with high precission in range -200+700C.

As this board interface UEXT connector via I2C many such modules and thermocouples can be attached to one UEXT.

This GitHub project https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/iMX233/MOD-TC-MK2 allow iMX233-OLinuXino-MAXI to measure temperature with MOD-TC-MK2 and K-type thermocouple.

DUINOMITE – MEASURING TEMPERATURE II (LM335Z)

Today I decided to try another schematic for measurement of the temperature this time with LM335Z low cost sensor.

LM335Z have 0V at absolute zero temperature i.e. -273.2C and it’s output increase with 10mV/C so at room temperature the sensor will output about 2.73V

to measure this temperature with Duinomite is piece of cake:

10 SETPIN 1,1  ‘setup PIN(1) as analog input

20 PRINT “ROOM TEMPERATURE IS”;PIN(1)*100-273

the problem is that PIC32 Analog input can’t take more than 3.3V on it’s ADC, so maximal temperature measured will be 57C well this still is enough for some application, but why not measure the complete temperature range -40C+100C ? (if you use LM135 the range will be -55+150C)

to do this we have to add resistor ladder which to divide the output voltage, TassyJim uses 18K/27K in his project posted at TheBackShed forum, and I found his 0.6 round divider as nice so decided to use same values.

the schematic if used for industrial applications should have some protection diodes and resistors like on this picture:

Image

but for the experiment I just used R1, R2, R3 and wired them to DuinoMite-Mini with jumper cables:

Image

then  I wrote this simple code:

10 SETPIN 1,1

20 PRINT “ROOM TEMPERATURE IS: “; PIN(1)*166.7-273

RUN

ROOM TEMPERATURE IS: 24.5645

it’s really not so hot in my office so I start thining what is wrong and I found it – I used 5% resistors as I had no preciese resistors so the voltage divider was not exactly 0.6 but something else and was mixing my result, no problem I took preciese ohm meter and measured R2 and R3 the values are:

R2 = 17 860 ohm

R3 = 26 600 ohm

aha so the voltage divider is 0.59829! and the coefficient I have to use in the formula is 100/0.59829 = 167.1

I corrected the formula:

20 PRINT “ROOM TEMPERATURE IS: “; PIN(1)*167.1-273

RUN

ROOM TEMPERATURE IS: 23.6145

so with not preciese resistors I got preciese result because DM-BASIC have no problems to work multiply real numbers

so the complete code to measure temperature in -40C+100C with LM335Z fits in one line

PRINT “ROOM TEMPERATURE IS: “; PIN(1)*167.1-273

Measuring temperature in range -55C +150C with Duinomite and KTY81,110

ImageKTY81,110 is low cost PTC thermistor from NXP. it changes the resistance dependant on the temperature positively i.e. increase with the temperature increase. It’s very nice solution for not so precisely temperature measurement and it’s very cheap.

I evaluate it as potential candidate for Solar Water Heating controller temperature sensor as it works in nice teperature range -55C to +150C.

The NXP datasheet for KTY181,110 is at NXP site as you can see there is table with approximate values at different temperature, the resistance / temperature is not linear but can be easily calculated with DuinoMite.

To measure the temperatuere we connect KTY181.110 in series with 3300 ohm resistor to +3.3V and will measure the temperature with PIN(1) analog input.

Here is the table with the temperature, KTY81.110 resistance and measured voltage

t R V
———————–
-55 490 0.42665
-50 515 0.44548
-40 567 0.48386
-30 624 0.52477
-20 684 0.56657
-10 747 0.60912
0 815 0.65358
+10 886 0.69847
+20 961 0.74426
+25 1000 0.76744
+30 1040 0.79078
+40 1122 0.83731
+50 1209 0.88483
+60 1299 0.93209
+70 1392 0.97903
+80 1490 1.02651
+90 1591 1.07346
+100 1696 1.12026
+110 1805 1.16680
+120 1915 1.21179
+125 1970 1.23359
+130 2023 1.25416
+140 2124 1.29226
+150 2211 1.32395

the code is pretty simple, we store the table in DATA and read it to T() and V() arrays which hold the temperature and voltage at the reference points

5 OPTION BASE 0
10 DATA -55,0.42665,-50,0.44548,-40,0.48386,-30,0.52477,-20,0.56657,-10,0.60912,0,0.65358,+10,0.69847
20 DATA +20,0.74426,+25,0.76744,+30,0.79078,+40,0.83731,+50,0.88483,+60,0.93209,+70,0.97903,+80,1.02651
30 DATA +90,1.07346,+100,1.12026,+110,1.16680,+120,1.21179,+125,1.23359,+130,1.25416,+140,1.29226,+150,1.32395
40 DIM T(23),V(23)
50 FOR I = 0 TO 23: READ T(I): READ V(I): NEXT I

then we setup PIN(1) as analog input:

60 SETPIN 1,1

as the temperature is read pretty fast and we don’t need so fast measurement we read the temperature 1000 times then average it for better precision 😉

70 NRD = 1000 ‘number of times to read
100 ‘read temperature
110 VOL = 0
120 FOR I = 1 TO NRD: VOL = VOL + PIN(1): NEXT I: VOL = VOL / NRD

then check if the voltage is in the range we expect i.e. -55 +150C and if not generate error

130 IF VOL < V(0) OR VOL > V(23) THEN 180

then we search in the table for near higher temperature reference point

140 I = 0
150 DO
160 IF VOL > V(I) THEN I = I + 1 ELSE GOTO 200
170 UNTIL (I=23)
180 PRINT “ALARM – TEMPERATURE OUTSIDE -55+150C”

then calculate exact temperature

200 TEMP = T(I)-(V(I)-VOL)*(T(I)-T(I-1))/(V(I)-V(I-1))
210 PRINT “TEMPERATURE IS:”; TEMP
220 GOTO 100

here you can see screenshot of the program running in my office

Image