Current Sensor INA219

I am using several devices that use i2c to measure analog current and voltage from a pressure sensor(connected to ADS1015), position sensor (connected to ina219(0x41)), and to detect resistance on a gear motor (ina219(0x40)). All components have worked before many times, but now the current sensor that is connected to the position sensor is outputting "inf"" into the serial monitor. I have checked with a DMM that the position sensor and all current sensors are working normally. My code for my project is given below:

#include <Wire.h>
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1015 ads10;
//Adafruit_ADS1115 ads15;
#include <Adafruit_INA219.h>
Adafruit_INA219 ina1(0x41);
Adafruit_INA219 ina2;
#define SolPin 2
#define OFF_PIN1 10
#define ON_PIN1 11
#define LED_PIN1 12
#define FWDPin 4
#define BWDPin 3
#define ClosePin 7
#define OpenPin 8
#define LED_PIN2 9
#define PWMPIN 6
#define PosPin 5
float Value;
int x = 1;
float Pressure;
float Volts1;
float y;
float current1 = -1 * (ina1.getCurrent_mA());
float current2 = ina2.getCurrent_mA();
float Pressure1;
int PartNum = 1000;
float adc1;
float Displacement;
void setup() {
  Serial.begin(9600);
  pinMode(PWMPIN, OUTPUT);
  pinMode(ON_PIN1, INPUT_PULLUP);
  pinMode(OFF_PIN1, INPUT_PULLUP);
  pinMode(LED_PIN1, OUTPUT);
  pinMode(SolPin, OUTPUT);
  pinMode(OpenPin, INPUT_PULLUP);
  pinMode(ClosePin, INPUT_PULLUP);
  pinMode(LED_PIN2, OUTPUT);
  pinMode(BWDPin, OUTPUT);
  pinMode(FWDPin, OUTPUT);
  pinMode(PosPin, OUTPUT);
  uint16_t currentFrequency;
  ina1.begin();
  ina2.begin();
  ads10.begin();
}

void loop() {
  adc1 = ads10.readADC_SingleEnded(1);
  Volts1 = ads10.computeVolts(adc1);
  Pressure1 = (((Volts1 - 0.5) / 4) * 150) + 15;
  Displacement = (((ina2.getCurrent_mA() - 4) / 16) * -50);
  while (PartNum > 999) {
    digitalWrite(LED_PIN2, HIGH);
    if (x == 1)  {
      current1 = -1 * (ina1.getCurrent_mA());
      Serial.println("Initializing Test . . .");
      Serial.println(". . . ");
      Serial.println("Closing Hydraulic");
      Serial.println(". . . ");
      digitalWrite(FWDPin, HIGH);
      digitalWrite(BWDPin, LOW);
      if (current1 > 500) {
        Serial.println("Hydraulic Valve is Closed");
        Serial.println(". . . ");
        digitalWrite(BWDPin, LOW);
        digitalWrite(FWDPin, LOW);
        delay(2000);
        x = 2;
      }
    }
    if (x == 2) {
      Pressure = 65;
      y = ((Pressure / 130) * 255);
      Value = y;
      delay(1000);
      if (Value > 0) {
        analogWrite(PWMPIN, Value);
      }
      Serial.print("Air Pressure: "); Serial.println(Pressure);
      Serial.println(". . . ");
      Serial.println("Opening Air");
      Serial.println(". . . ");
      digitalWrite(LED_PIN1, HIGH);
      digitalWrite(SolPin, HIGH);
      Serial.println("Holding for 1 minute");
      Serial.println(". . . ");
      delay(10000);
      x = 3;
    }
    if (x == 3) {
      current1 = -1 * (ina1.getCurrent_mA());
      Serial.print(current1, 4);
      digitalWrite(LED_PIN2, HIGH);
      Serial.println("Opening Hydraulic");
      Serial.println(". . . ");
      digitalWrite(FWDPin, LOW);
      digitalWrite(BWDPin, HIGH);
      if (current1 > 1000) {
        Serial.println("Hydraulic Valve is Opened");
        Serial.println(". . . ");
        digitalWrite(BWDPin, LOW);
        digitalWrite(FWDPin, LOW);
        delay(2000);
        x = 4;
      }
    }
    if (x == 4) {
      Pressure = 1;
      Serial.print("Air Pressure: "); Serial.println(Pressure1);
      Serial.println(". . . ");
      y = ((Pressure / 137.5) * 255);
      Value = y;
      delay(1000);
      if (Value > 0) {
        analogWrite(PWMPIN, Value);
        Serial.println("Release Air Pressure");
        Serial.println(". . . ");
        Serial.println("Closing Air");
        Serial.println(". . . ");
        delay(30000);
        digitalWrite(LED_PIN1, LOW);
        digitalWrite(SolPin, LOW);
        Serial.println("Test has Concluded");
        Serial.println(". . . ");
        Serial.println("Measuring Displacemnent");
        Serial.println(". . . ");
        x = 5;
      }
    }
    if (x == 5) {
      //Serial.print("Displacement: "); Serial.println(Displacement);
      Serial.print("Current: "); Serial.println(current2);
      Serial.println(". . . ");
    }
  }
}

I do not understand as to why the ina219 sensor is not responding to the position sensor. Any help tp troubleshoot is appreciated.

Neither do we. Try posting schematics. Words are never the same good.

Please provide schematics. That colourful bird nest might interest the police investigating a mysterious murder but it will not be taken on by any helper I think.

1 Like
  • Could be a software "interaction"
  • Dupont jumpers are often subject to going open/hi-res
  • Prototyping boards sometimes causes bad connections via ambient temp expansion-contraction
1 Like


is this any better for a diagram. I know it is still a mess

Getting there , but don’t understand the relay wiring .
I would have powered the I2C sensors from the 5v line , have you set different addresses for each of them ?

Anything inductive needs a fly back diode.

Hope that’s not a mains connection on the left side of the power supply .

All the relay connections looks strange, very strange. D3 looks like shorted to D4, connected how, where?

No Arduino can supply coil current.

Neither can a prototype board supply significant power

the relays are powered by a 5V converter and the arduino pins activate the switch. The only devices that the arduino powers are the current sensors and the ADS1015.

Ive also set addresses for all the devices

The 24V power supply has no connection with the longer breadboard. Only 5V is connected to the smaller breadboard.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.