Ca urmare a unui incident, sursa mea de tensiune liniara a avut nevoie de o reparație, astfel am decis să-i montez senzorul de tensiune și curent INA219 pe care l-am testat într-un mini proiect din octombrie. Tensiunea afișată este pentru al doilea rând de conectori (-/+) de la stânga la dreapta(vezi în imaginea de mai jos). Primi doi conectori (-/+) (tot de la stânga la dreapta) îmi dau 9 V, următorii doi 0 – 12 V, apoi iar 9 V și ultimii 0 – 18 V.
Codul sursă adaptat pentru un afișor 16×2:
#include "Wire.h"
// include the library code:
#include "LiquidCrystal.h"
#include "Adafruit_INA219.h"
Adafruit_INA219 ina219;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif
void setup(void)
{
#ifndef ESP8266
while (!Serial); // will pause Zero, Leonardo, etc until serial console opens
#endif
uint32_t currentFrequency;
Serial.begin(9600);
Serial.println("Hello!");
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Voltmetru");
// Initialize the INA219.
// By default the initialization will use the largest range (32V, 2A). However
// you can call a setCalibration function to change this range (see comments).
ina219.begin();
// To use a slightly lower 32V, 1A range (higher precision on amps):
ina219.setCalibration_32V_1A();
// Or to use a lower 16V, 400mA range (higher precision on volts and amps):
//ina219.setCalibration_16V_400mA();
lcd.print("Measuring voltage and current with INA219 ...");
}
void loop(void)
{
String lcd_buffer;
float shuntvoltage = 0.0f;
float busvoltage = 0.0f;
float current_mA = 0.0f;
float current_A = 0.0f;
float power = 0.0f;
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
current_A = ina219.getCurrent_mA()/1000.0;
power = busvoltage * (current_mA/1000.0); // Calculate the Power
lcd.setCursor(0, 0);
lcd.print("Volts:");
lcd.print(busvoltage,1);
lcd.print("V ");
lcd.setCursor(0, 1);
lcd.print("C:");
lcd.print(current_A,1);
lcd.print("A");
lcd.print(" P:");
lcd.print(power,1);
lcd.print("W ");
delay(1000);
}
Merge brici ! Weekend plăcut și Sărbători fericite !