Hello community,
I recently bought a module and I want to retrieve the current is consumed by a device.
For this I made a mount for the module can measure a voltage of 230 V AC.
When I perform the measurement module returns me a value smaller than 0 and there is no change in Current.
Here is the code and the accompanying diagram that I made.
Here the value that the module returns me :
-0.38794525904198629
-0.38825610948187084
-0.38633919843592857
-0.38696089931569411
-0.38499217986310263
CODE C#
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
namespace courant
{
public partial class Program
{
GT.Timer timer;
void ProgramStarted()
{
Debug.Print("Program Started");
timer = new GT.Timer(500);
timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(GT.Timer timer)
{
Debug.Print(current_ACS712.Read_AC_Current().ToString());
}
}
}
As soon as you have an idea ?
Looks like the tutorial on the module is missing. I would go to the datasheet directly:
http://www.allegromicro.com/Products/Current-Sensor-ICs/Zero-To-Fifty-Amp-Integrated-Conductor-Sensor-ICs/ACS712.aspx
The module driver uses some constants maybe they provided in the datasheet.
public double Read_AC_Current()
{
double read = 0.0;
double calculation = 0.0;
for (int i = 0; i < 400; i++)
{
read += ain.ReadProportion();
}
read /= 400;
calculation = 21.2 * read - 13.555;
return calculation;
}
1 Like
I have no experienc with this modul, but I find this indication on the ghi-site:
http://www.ghielectronics.com/catalog/product/324
[quote]4.The clip must be placed around one of the 2 power lines going to a device. Clipping around unseparated wires will result in zero reading.
[/quote]
maby its a hint…
@ VB-Daniel - This is a different current module.
We talking about this one:
http://www.ghielectronics.com/catalog/product/390
sorry, have read inaccurate
@ Alicorne - Also check this thread
http://www.tinyclr.com/forum/topic?id=9681
there is an interesting external link for that sensor from EriSan500 (Eric).
@ Architect
I dont understand how you do to use this function :
ain.ReadProportion();
If I understand correctly, this function reads the (socket.pin) where the value is returned by the sensor and adjust the values ?
public double Read_AC_Current()
{
double read = 0.0;
double calculation = 0.0;
for (int i = 0; i < 400; i++)
{
read += ain.ReadProportion();
}
read /= 400;
calculation = 21.2 * read - 13.555;
return calculation;
}
Here is the code for ReadProportion method:
/// <summary>
/// Reads the current analog input value as a proportion from 0.0 to 1.0 of the maximum value (3.3V).
/// </summary>
/// <returns>The analog input value from 0.0-1.0</returns>
public double ReadProportion()
{
Active = true;
return ain.Read() / 3.3;
}
1 Like
@ Architect
thank you for your reply, but how do you for read the pin (AnalogInput) - > GT.Socket.Pin.Five.
On the diagram it returns the value of the pin 5 :
http://www.ghielectronics.com/downloads/Gadgeteer/Module/Current%20ACS712%20sch.pdf
@ Architect
Thank you very much, I’ll try that.
Hello,
I try the class, but the values ​​are not always right.
So I’ve put it in the main program but valeures are still not consistent.
Here are the values if I use -> intt.ReadVoltage();
30.738809677419376
30.733851612903266
30.736245161290327
30.731970967741965
here are the values if I use -> intt.ReadProportion();
-0.13144183773215801
-0.1334105571847477
-0.13335874877810205
-0.13284066471162959
Code C# -> Program.cs
public partial class Program
{
GT.Timer timer;
private const int AC_SAMPLE_COUNT = 400;
GT.Socket socket;
GT.Interfaces.AnalogInput intt;
void ProgramStarted()
{
Debug.Print("Program Started");
timer = new GT.Timer(500);
timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
timer.Start();
socket = GT.Socket.GetSocket(10, true, null, null);
socket.EnsureTypeIsSupported('A', null);
intt = new GT.Interfaces.AnalogInput(socket, Socket.Pin.Five, null);
}
void timer_Tick(GT.Timer timer)
{
//double dd = intt.ReadVoltage() / 3.3;
Debug.Print(Read_AC_Current().ToString());
}
public double Read_AC_Current()
{
double read = 0.0;
double calculation = 0.0;
for (int i = 0; i < AC_SAMPLE_COUNT; i++)
{
read += intt.ReadVoltage();
}
read /= AC_SAMPLE_COUNT;
calculation = 21.2 * read - 13.555;
return calculation;
}
}
Code C# -> Program.generated.cs
using Gadgeteer;
using GTM = Gadgeteer.Modules;
namespace dd
{
public partial class Program : Gadgeteer.Program
{
// GTM.Module definitions
//Gadgeteer.Modules.GHIElectronics.Current_ACS712 current_ACS712;
Gadgeteer.Modules.GHIElectronics.UsbClientDP usbClientDP;
public static void Main()
{
//Important to initialize the Mainboard first
Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();
Program program = new Program();
program.InitializeModules();
program.ProgramStarted();
program.Run(); // Starts Dispatcher
}
private void InitializeModules()
{
// Initialize GTM.Modules and event handlers here.
usbClientDP = new GTM.GHIElectronics.UsbClientDP(1);
//current_ACS712 = new GTM.GHIElectronics.Current_ACS712(10);
}
}
}
Are you an idea ?
I don’t think you will get “exact” readings each time.
Is the precision you are getting not good enough?
[b]30.73/b
[b]30.73/b
[b]30.73/b
[b]30.73/b
@ Architect
I try with my pc and i find this values:
30.755564516128963
30.750264516128965
30.764283870967681
30.746674193548316
30.757445161290249
So I do not think my pc consumes 30 amps.
Oh you are talking about the actual values not the precision. Ok.
calculation = 21.2 * read - 13.555;
I am not sure about these constants that are used in the formula. Did you verify the meaning and values of these constants from the Datasheet?
1 Like
@ Architect
No i dont check the values in the datasheet.
I’ll read it to find values.
Ok, try this formula:
calculation = 5.4054*read - 8.9189;
using ReadVoltage version
Thank you for your answer.
With this formula, its return this values if my pc is power on.
And if it is power off values ​​are almost the same:
2.3661802580645208
2.3639134774193558
2.3635211500000004
2.3643058048387182
2.3648289080645171