Can someone help me with almost the same thing, I got an Arduino nano every and three of the ina219 sensors, i use them to measure the current of an illumination system, I turn on the lamps with the swiches and then measure the current to check if they are okay. My problem is only the value uf sensor one is showing corectly the other sensors are showing almost the same value as sensor one.
I soldert the adrespins to change the adress.
` //digital pins for checking the status of the swich
const int pinD2 = 2; // Digital pin 2 (swich wich turns on the measurement of the Rückfahrlicht links)
const int pinD3 = 3; //Digital pin 3 (swich wich turns on the measurement of the Bremslicht links )
const int pinD4 = 4; //Digital pin 4 (swich wich turns ont the measurment of the Tagfahrlicht links)
//digital pins for turing the laps on and off
const int pinD5 = 5; //Digital pin 6 (turns the relais on wich controls the Rückfahrlicht links)
const int pinD6 = 6; //Digital pin 7 (turns the relais on wich controlls the Bremslicht links)
const int pinD7 = 7; //Digital pin 8 (turns the relasi on wich controlls the Tagfahrlicht links)
//digital pins for indicating that the lamps are working
const int pinD8 = 8; //Digital pin 9 (Indicatorlight Rückfahrlicht links is working (green))
const int pinD9 = 9; //Digital pin 9 (Indicatorlight Bremslicht links is working (green))
const int pinD10 = 10; //Digital pin 10 (Indicatorlight Tagfahrlicht links is working (green))
//digital pins for indication that the lamps aren't working
const int pinD11 = 11; // Digital pin 11 (Indicatorlight Rückfahrlicht links isn't working (red))
const int pinD12 = 12; // Digital pin 12 (Indicatorlight Bremslicht links isn't working (red))
const int pinD13 = 13; // Digital pin 13 (Indicatorlight Tagfahrlicht links isn't working (red))
//include the libarys in to the program and initalizing the sensors
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219_1;
Adafruit_INA219 ina219_2;
Adafruit_INA219 ina219_3;
void setup() {
//declaring that as output and imput in the setup so tey stay in that state
pinMode(pinD2, INPUT);
pinMode(pinD3, INPUT);
pinMode(pinD4, INPUT);
pinMode(pinD5, OUTPUT);
pinMode(pinD6, OUTPUT);
pinMode(pinD7, OUTPUT);
pinMode(pinD8, OUTPUT);
pinMode(pinD9, OUTPUT);
pinMode(pinD10, OUTPUT);
pinMode(pinD11, OUTPUT);
pinMode(pinD12, OUTPUT);
pinMode(pinD13, OUTPUT);
digitalWrite(pinD8, HIGH);
digitalWrite(pinD9, HIGH);
digitalWrite(pinD10, HIGH);
digitalWrite(pinD11, HIGH);
digitalWrite(pinD12, HIGH);
digitalWrite(pinD13, HIGH);
Serial.begin(9600); // Initialize serial communication
Serial.println("Measuring current with INA219...");
if (!ina219_1.begin()) {
Serial.println("Failed to find INA219 chip 1");
while (1) { delay(100); }
}
ina219_1.setCalibration_16V_400mA(); // Adjust calibration based on your sensor specs
if (!ina219_2.begin()) {
Serial.println("Failed to find INA219 chip 2");
while (1) { delay(100); }
}
ina219_2.setCalibration_16V_400mA(); // Adjust calibration based on your sensor specs
if (!ina219_3.begin()) {
Serial.println("Failed to find INA219 chip 3");
while (1) {delay(100); }
}
ina219_3.setCalibration_16V_400mA(); //Adjust calibration based on your sensor specs
}
void loop() {
float current_mA_1 = 0;
float current_mA_2 = 0;
float current_mA_3 = 0;
// Read current from each sensor
current_mA_1 = ina219_1.getCurrent_mA();
current_mA_2 = ina219_2.getCurrent_mA();
current_mA_3 = ina219_3.getCurrent_mA();
// Print current readings to serial monitor
Serial.println("Current readings:");
Serial.print("Sensor 1: "); Serial.print(current_mA_1); Serial.println(" mA");
Serial.print("Sensor 2: "); Serial.print(current_mA_2); Serial.println(" mA");
Serial.print("Sensor 3: "); Serial.print(current_mA_3); Serial.println(" mA");
delay(100);
//Turn The LED on and giv response to the satus of the LED via RGB LED
//Evaluation of the Rückfahrlicht
int stateD2 = digitalRead(pinD2); //Gething the checking of the digital imput
if(stateD2 == HIGH) {
digitalWrite(pinD5, LOW);
if(5 <= current_mA_1) {
digitalWrite(pinD8, HIGH);
digitalWrite(pinD11, LOW);
}
else
{
digitalWrite(pinD11, HIGH);
digitalWrite(pinD8, LOW);
}
}
else if (stateD2 == LOW ) {
digitalWrite(pinD5, HIGH);
digitalWrite(pinD8, HIGH);
digitalWrite(pinD11, HIGH);
}
else {
digitalWrite(pinD11, HIGH);
}
//end of the evaluation of the rückfahrlicht
//evaluation of the Bremslicht
int stateD3 = digitalRead(pinD3);
if(stateD3 == HIGH){
digitalWrite(pinD6, LOW);
if(10 <= current_mA_2) {
digitalWrite(pinD9, HIGH);
digitalWrite(pinD12, LOW);
}
else
{
digitalWrite(pinD12, HIGH);
digitalWrite(pinD9, LOW);
}
}
else if (stateD3 == LOW ) {
digitalWrite(pinD6, HIGH);
digitalWrite(pinD9, HIGH);
digitalWrite(pinD12, HIGH);
}
else {
digitalWrite(pinD12, HIGH);
}
//end of the evaluation of the Bremslicht
//evaluation of the Tagfahrlicht
int stateD4 = digitalRead(pinD4);
if(stateD4 == HIGH) {
digitalWrite(pinD7, LOW);
if(90 <= current_mA_3) {
digitalWrite(pinD10, HIGH);
digitalWrite(pinD13, LOW);
}
else
{
digitalWrite(pinD13, HIGH);
digitalWrite(pinD10, LOW);
}
}
else if (stateD4 == LOW ) {
digitalWrite(pinD7, HIGH);
digitalWrite(pinD10, HIGH);
digitalWrite(pinD13, HIGH);
}
else {
digitalWrite(pinD13, HIGH);
}
//end of the evaluation of the Tagfahrlicht
delay(100); // Adjust the delay as per your requirement
}