Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Arduino UNO unsure about coding for project, help appreciated!!

Status
Not open for further replies.

ckinger

Junior Member level 3
Joined
Feb 3, 2017
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
291
Hello, I am doing a project of current measurement using the LEM LA 55-P transducer which senses the strength of magnetic field produced by a current carrying conductor traveling through the hole of the sensor and outputs a linear milliamp output. I want to interface this sensor with an Arduino UNO but am not to certain about the code required. A little bit about the sensor, it can measure a primary current up to 50 Amps which will output 50 milliamps; I am going to have the output going to a 100ohm precision resistor so that 50mA max output will equal 5 volts; 50mA x 100 ohms = 5 volts. I want to then send this output to the Arduinos analog to digital converter, and have an LCD display wired to the Arduino, with a code stating that 5 volts input will display 50 Amps to the LCD, 1 volt will display 10 amps etc. basically every 0.1 Volt = 1 Amp. if anyone has any insight on how to go about writing this code it would be much appreciated, I don’t think it will be an overly complicated code but I have next to no experience with C++, Thanks for your help.
 

Try this code which I wrote.

Code:
#define LEM_LA_55_P_Transducer A0
double current = 0;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(100);
}

void loop() {
  // put your main code here, to run repeatedly:
  current = analogRead(LEM_LA_55_P_Transducer) * 50.0 / 1023.0;
  Serail.print(current);  
  Serial.println(" Amperes");
}

Input 0-5V from 100 Ohms resistor to A0 pin of Arduino Uno.

You have to convert AC Current to DC using a diode and scale it to 0-5V range.
 

awesome, thanks for your help.. i will most definitely give this code a try and will get back to you with the results. As for converting AC to DC that is how i have it set up, i am using a unidirectional supply instead of a bidirectional supply in which it states in this link, **broken link removed** that you have to put a diode in series with the output.. this trick does indeed work but through playing around with this circuit i came to find out that, when measuring DC it works perfectly fine with the expected output extremely accurate, but when measuring AC through this circuit it only puts out half of the expected output. The diode cuts off the bottom half of the AC wave, which i assume because of this i only get half of my expected output. I supposed one way of getting around this would be to double the measuring resistor when using this circuit to measure AC? where as, say i am measuring a load that draws 10 amps AC, and get a 5 mA output, instead of the 100 ohm resistor to get .5V which would be half of the expected output, i could use a 200 ohm resistor to get the ranged voltage of 1V.. mind you the only thing with that is that 200 ohm resistor exceeds the range of the datasheet of the lem la 55-p **broken link removed** , although i dont think this will effect much other than maybe decreasing the capability of the upper measuring range of the sensor, which i am only using as a thesis project so i wont be measuring very large currents, more so just to prove the circuit works and do a detailed explanation on how it works.
 

0.7V drop across 1N4007 diode. Choose resistor such that for 50A (sec: 50mA) gets converted to 5.7V. This will give 5V after diode and then it will work with my code.

Also read this.

https://learn.openenergymonitor.org...ensors/interface-with-arduino?redirected=true

50mA through 100 Ohms = 5V rms

5Vrms through diode gives 5 * 1.4142 = 7.071V

You can't feed 7.x V to ADC pin. You have to scale this value to 5V using voltage divider.
 

but where as the sensor is in the current domain, the output current shouldn't be effected by the diodes in series, since current in series is equal throughout and the resistor is after the diode shouldn't there be no voltage drop considered in the calculation?

- - - Updated - - -

Just checked out the link you posted, thats actually really helpful, although the LA 55-P isnt a current transformer it is still relatable, this sensor has 1000 loop, 1:1000 ratio

- - - Updated - - -

As i look further into your claim, would i have to adjust the 100ohm resistor when measuring DC? as DC has no rms and is just a steady value. When measuring AC i used the website you provided to figure a 70 ohm resistor would scale the AC mA value for the 0-5V range for the ADC where 50mA x sqrt 2 = 70.7mA x 70 ohms = 4.949 volts
 

Provide link for the datasheet of your sensor. Is it hall effect based sensor ?
 

certainly, it was in one of the links above but here it is, **broken link removed** yes, the sensor is hall effect.
 

Was the datasheet of any use? your code uploaded properly, now to test it..
 

I am busy with some project. I will check the datasheet.

After this line

Code:
Serial.println(" Amperes");

Add line

Code:
delay(1000);

and upload the sketch to Arduino. You will be able to see what it is printing on Serial Terminal.
 

20170322_072136.jpg here is a picture of my project so far, if the picture works..
 

i have now, interesting project.. it seems to be using the same sensor as i, although i believe it to be overly complicated for myself, i am just a student of electronic technologies and my project is for my thesis class. The documentation i have to do with the project is worth a lot more point wise then actually having the project working extremely accurately, i am just trying to get the Arduino to process the simple output from the sensor and send the signal to an LCD, nothing more :roll: but hey i do greatly appreciate your help.
 

So I tried your code to no avail, unless I have my lcd hooked up wrong, I used the pin layout a friend used for a timer hooked up to an ardunio to lcd as the pin diagram.. here is a picture of the test setup, I had roughly .60volts going into A0 but nothing at all displayed on the lcd

- - - Updated - - -

20170322_170110.jpg20170322_170120.jpg20170322_154644.jpg

- - - Updated - - -

with the picture of the arduino i actually have the 5volt and ground wires removed, but i did have them there.. as you can see them in the total picutre.. the arduino ground went to pins 1 and 16 of the lcd and 5v pin of arduino went to pins 2 and 15

- - - Updated - - -

Pin 1 and pin 16 are connected to the terminal strip I have that goes to Arduino GND, I also have the 5v on the Arduino going to the terminal strip which pin2 and pin 15 are connected, Pin D7 is connected to pin 4 on the LCD, pin D8 is connected to pin 6 on the LCD, pin D9 is connected to pin 11 on the LCD, pin D10 is connected to pin 12 on the LCD, pin D11 is connected to pin 13 on the LCD, pin D12 is connected to pin 14 on the LCD.

- - - Updated - - -

im going to try wiring the lcd again with this instructable https://www.instructables.com/id/Connecting-an-LCD-to-the-Arduino/?ALLSTEPS and see if that can get me some text on the display
 

The Code I gave prints Current Value on Serial Terminal that is UART (Tx Pin transmits the data) and not Lcd Code. If you want to use Lcd then I will make a new code.
 

Hello, i have spent hours on this problem over the past few days reading countless articles and came up with something, here is your original code that i altered...

#define LEM_LA_55_P A0
double current = 0;
int voltageinput_pin=A0;
int voltageinput;


// include the library code:
#include <LiquidCrystal.h>


// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(100);

lcd.begin(16, 2);
lcd.print(" Current =");
}

void loop() {
voltageinput=analogRead(voltageinput_pin);
lcd.setCursor(0, 1);
// print the number of primary current going through);LEM_LA_55_P:
lcd.print(voltageinput*0.0048828125/100);
lcd.print(" Amperes");

// put your main code here, to run repeatedly:
current = analogRead(LEM_LA_55_P) * 10.0 / 1023.0;
Serial.print(current);
Serial.println(" Amperes");
delay(1000);

}

- - - Updated - - -

20170324_204631.jpg here is my display at the moment

- - - Updated - - -

i havent tried it out, although i can tell you on your original serial coding i was getting whacky numbers, it was reading like.. 17 amps constant without any input, i tried to come out with an equation, i have voltageinput as analog pin 0, and the .0048828125 number i got from dividing 5volts(max input) / 1024 (2^10) and that / 100 because of the 100 ohm resistor.. i feel like this isnt going to work out, say i have 10 amps primary = 10 mA out x 100 ohms = 1 volt into A0, so it would be.. 1 volt x .0048828125 / 100 = ~.0000488281 ..... where the LCD to display 10 Amps
 

Attachments

  • 20170324_204624.jpg
    20170324_204624.jpg
    325.2 KB · Views: 155

I have not used that sensor. I can only help you with code.
 

im getting outputs from the sensor... thats the easy part.. and i have the lcd reading "current =" its the coding i am not sure about.. i just tested it out and that conversion is no good, i had .6 volts going into A0.. it seems like its not changing the reading value of the lcd.. heres the summary, the sensor measures 0-50A and outputs 0-50 mA (analog) x 100ohm ranging resistor = 0-5volts into A0.. i just cant seem to figure out how to convert this 0-5 volts into A0 to display 0-50 Amps on the lcd as i want the lcd to display the primary current not the secondary output.. i know its all done within the software but as i said before.. i am very novice with this
 

You should not give more than 5V to adc pin. if you give then adc module gets damaged. If your sensor output voltage is greater then 5V then scale it to 0-5V range using two resistors (voltage divider) and feed it to adc.

analogread() returns 0 to 1023 raw adc value

so, if you need to convert it to 0 to 50 value then


value = analogRead(A0) * 50 / 1023.0;

if analogRead(A0) returned 1023 then

1023 * 50 / 1023 = 50
 

0 to 50 A = 0 to 1023 bits with 0=0 and 1023 = 5 volts in so maybe it would be (Vin*50)/1023 ?
 

Vin is 0 to 5V

for 0 to 5V you get 0 to 1023 raw adc value and so

raw_adc_value * 50 / 1023

why don't you feed 5V to A0 pin and see if it displays 50 on lcd ?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top