## How to measure current and voltage using Arduino?

Programming, Tutorial, Coding, New Design, and/or any project for your Arduino and Raspberry Pi can post your topic /suggestion here.
dondon pramis
Inventor
Contact:
Location: Philippines
Posts: 51
Joined: Sun Feb 12, 2017 8:28 am

### How to measure current and voltage using Arduino?

How to measure current and voltage using Arduino and LTC2945?
This is very easy to work with. so i will not give much more explanation. try it for yourself. Let me know how you move forward by your reply below

Code: Select all

``````//LTC2945 Test Code
//  http://www.kevindarrah.com/wiki/index.php?title=Power_Monitor
//
#include <Wire.h>

//defines
#define LTCADDR B1101111//Table 1 both LOW (7bit address)
byte ADCvinMSB, ADCvinLSB, curSenseMSB, curSenseLSB, AinVMSB, AinVLSB;
unsigned int ADCvin, ADCcur, AinV;
float inputVoltage, ADCvoltage, current10, current1, current0p1, current0p01;

void setup() {//setup
Serial.begin(9600);
Wire.begin();
}

void loop() {

Wire.beginTransmission(LTCADDR);//first get Input Voltage - 80V max
Wire.write(0x1E);
Wire.endTransmission(false);
Wire.requestFrom(LTCADDR, 2, true);
delay(1);
ADCvinMSB = Wire.read();
ADCvinLSB = Wire.read();
ADCvin = ((unsigned int)(ADCvinMSB) << 4) + ((ADCvinLSB >> 4) & 0x0F);//formats into 12bit integer
inputVoltage = ADCvin * 0.025; //25mV resolution

Wire.beginTransmission(LTCADDR);//get ADC Input 2V max
Wire.write(0x28);
Wire.endTransmission(false);
Wire.requestFrom(LTCADDR, 2, true);
delay(1);
AinVMSB = Wire.read();
AinVLSB = Wire.read();
AinV = ((unsigned int)(AinVMSB) << 4) + ((AinVLSB >> 4) & 0x0F);//12 bit format
ADCvoltage = AinV * 0.5E-3; //500uV resolution

Wire.beginTransmission(LTCADDR);//get sense current
Wire.write(0x14);
Wire.endTransmission(false);
Wire.requestFrom(LTCADDR, 2, true);
delay(1);
curSenseMSB = Wire.read();
curSenseLSB = Wire.read();
ADCcur = ((unsigned int)(curSenseMSB) << 4) + ((curSenseLSB >> 4) & 0x0F);//12 bit format
//gets voltage across, 25uV resolution, then this converts to voltage for each sense resistor
current10 = ADCcur * (25E-3) / 10.0; //10mA max, unit is mA
current1 = ADCcur * (25E-3) / 1.0; //100mA max, unit is mA
current0p1 = ADCcur * (25E-3) / 0.1; //1A max, unit is mA
current0p01 = ADCcur * (25E-6) / 0.01;//10A max, unit is A

//Print everything out
Serial.print("Vin:25mV/80V>");
Serial.print(inputVoltage, 2);
Serial.print("V 10ohm:2.5uA/10mA>");
Serial.print(current10, 3);
Serial.print("mA 1ohm:25uA/100mA>");
Serial.print(current1, 2);
Serial.print("mA 0.1ohm:250uA/1A>");
Serial.print(current0p1, 1);
Serial.print("mA 0.01ohm:2.5mA/10A>");
Serial.print(current0p01, 3);
Serial.print("A ADC:0.5mV/2V>");
Serial.print(ADCvoltage, 4);
Serial.println("V");

delay(1000);

}
``````

Return to “ARDUINO AND RASPBERRY PI”

### Links

In total there are 4 users online :: 1 registered, 0 hidden and 3 guests
Registered users: Majestic-12 [Bot]
Most users ever online was 156 on Sun Jun 17, 2018 7:42 am
Total posts 471
Total topics 355
Total members 69
Our newest member svetikvow
No birthdays today