Sensor Reading/Arduino/Coding/

Hello Forum,

I'm currently having an issue with a project that my friends and I are working on and your advice would be greatly appreciated.
We are using a LV 25-P and as the input going into the device is 300VDC. The LV 25-P output with our chosen resistor is 3VDC and that 3VDC is plugged into A0 pin. After that we found the collaborated the LV 25-P and the equation was 100*x (x= The voltage output). We programmed the Arduino w/ SD Card Shield with our equation and for some reason the when we look at the file from the SD Card the voltage is displaying 420 Volts when that's incorrect, it should be displaying 300VDC. I'm not too sure if it has something to do with the coding. I'm not really good at programming. In the code we're mainly focusing on Pin 0 and Pin 1, which are our voltage readings. Almost forgot to mention we are using a 3 output power supply (LDC30F-2) to power up the arduino and our sensors.

* SD card attached to SPI bus as follows:

** MOSI - pin 11

** MISO - pin 12

** CLK - pin 13

** CS - pin 4

#include <SPI.h>

#include <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not

// used as the CS pin, the hardware CS pin (10 on most Arduino boards,

// 53 on the Mega) must be left as an output or the SD library

// functions will not work.

const int chipSelect = 4;

// Analog pin which we're monitoring 

int sensorPin0 = 0;

int sensorPin1 = 2;

int sensorPin2 = 1;

int sensorPin3 = 5;

const int numReadings = 15;

const int chipselect = 4;

const int echipselect = 10;

double Voltreadings[numReadings]; // the readings from the analog input

double Currentreadings[numReadings];

double Volt2readings[numReadings];

double Current2readings[numReadings];

int index = 0; // the index of the current reading

double total = 0; // the running total

double total1 = 0;

double total2 = 0;

double total3 = 0;

float voltaverage = 0; // the average

float currentaverage = 0;

float volt2average = 0;

float current2average = 0;

float powern=0;

float powers =0;

long int tag=1;

void setup()

{

// Open serial communications and wait for port to open:

Serial.begin(9600);

while (!Serial) {

; // wait for serial port to connect. Needed for Leonardo only

}

Serial.print("Initializing SD card...");

// make sure that the default chip select pin is set to

// output, even if you don't use it:

pinMode(10, OUTPUT);

// see if the card is present and can be initialized:

if (!SD.begin(chipSelect)) {

Serial.println("Card failed, or not present");

// don't do anything more:

return;

}

Serial.println("card initialized.");

for (int voltReading = 0; voltReading < numReadings; voltReading++)

Voltreadings[voltReading] = 0;

for (int currentReading = 0; currentReading < numReadings; currentReading++)

Currentreadings[currentReading] = 0;

for (int volt2Reading = 0; volt2Reading < numReadings; volt2Reading++)

Volt2readings[volt2Reading] = 0;

for (int current2Reading = 0; current2Reading < numReadings; current2Reading++)

Current2readings[current2Reading] = 0;

}

void loop()

{

double sensorReading = analogRead(sensorPin0);

double outvolt = sensorReading*5/1024;

double voltageread= (100.03)*outvolt + 0.1436;

double sensorcurrent = analogRead(sensorPin2);

double outcurrent = sensorcurrent *5/1024 ;

double currentread = (3.3727)*outcurrent - .0025;

double sensorReading2 = analogRead(sensorPin1);

double outvolt2 = sensorReading2*5/1024;

double voltageread2= (99.653)*outvolt2 + 1.8825;

double sensorcurrent2 = analogRead(sensorPin3);

double outcurrent2 = sensorcurrent2 *5/1024 ;

double currentread2 = (3.3649)*outcurrent2 - .002;

Voltreadings[index] = voltageread;

total= total + Voltreadings[index];

Currentreadings[index] = currentread;

total1= total1 + Currentreadings[index];

Volt2readings[index] = voltageread2;

total2= total2 + Volt2readings[index];

Current2readings[index] = currentread2;

total3= total3 + Current2readings[index];

index = index + 1;

if (index >= numReadings)

{

voltaverage = total / numReadings;

currentaverage = total1/numReadings;

volt2average = total2 /numReadings;

current2average = total3 / numReadings;

powern = voltaverage * currentaverage;

powers = volt2average * current2average;

index = 0, total = 0, total1 = 0, total2 = 0, total3 = 0;

int v1,v2;

v1 = floor (voltaverage);

v2 = voltaverage * 100 - v1 *100;

int c1,c2;

c1 = floor (currentaverage);

c2 = currentaverage * 100 - c1 *100;

int p1,p2;

p1 = floor (powern);

p2 = powern * 100 - p1 *100;

int v3,v4;

v3 = floor (volt2average);

v4 = volt2average * 100 - v3 *100;

int c3,c4;

c3 = floor (current2average);

c4 = current2average * 100 - c3 *100;

int p3,p4;

p3 = floor (powers);

p4 = powers * 100 - p3 *100;

// make a string for assembling the data to log:

// String dataString = String (tag)+","+String(voltaverage)+","+String(currentaverage)+","+String(powern)+","+String(volt2average)+","+String(current2average)+","+String(powers);

String dataString = String (tag)+","+String(v1)+"."+String(v2)+","+String(c1)+"."+String(c2)+","+String(p1)+"."+String(p2)+","+String(v3)+"."+String(v4)+","+String(c3)+"."+String(c4)+","+String(p3)+"."+String(p4);

// open the file. note that only one file can be open at a time,

// so you have to close this one before opening another.

File dataFile = SD.open("ITWORKS.csv", FILE_WRITE);

// if the file is available, write to it:

if (dataFile) {

dataFile.println(dataString);

dataFile.close();

// print to the serial port too:

tag =tag+1;

Serial.println(dataString);

}

// if the file isn't open, pop up an error:

else {

Serial.println("error opening ITWORKS.csv");

}

}
delay(3000);
}

We are using a LV 25-P and as the input going into the device is 300VDC.

No clue what a LV 25-P is.

The LV 25-P output with our chosen resistor is 3VDC

You'll need to prove that.

double sensorReading = analogRead(sensorPin0);

The analogRead function does NOT return a double.

String dataString = String (tag)+","+String(v1)+"."+String(v2)+","+String(c1)+"."+String(c2)+","+String(p1)+"."+String(p2)+","+String(v3)+"."+String(v4)+","+String(c3)+"."+String(c4)+","+String(p3)+"."+String(p4);

Pisses away resources uselessly.

Your use of arrays to store the readings is completely unnecessary.

Hi,

A LV 25-P is a voltage transducer, allowing you to measure DC,AC and pulsed voltages with galvanic isolation.

Tom.... :slight_smile:

LV-25-P is a very important transducer, you have no problems in the code, at least as I've check it by reading, if you can post the schematic (or the LV part wiring from the power supply to measure to the arduino), by the way, I see currnt measuring, did you use the LA-25? if yes and you dont get any troubles with measuring current, so the problem is in the circuit that you have designed, but if you dont know if the current measuring is correct, than you need to check that out too coz the LV is very simple than the LA and may you have check the voltage reading but not the current coz may be you dont know it how much is it.