Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The INA3221 is a 3 channel current sensor with I2C interface. Here's an example code in Arduino that reads the current from the sensor:
- Note: This code assumes that the INA3221 sensor is connected to the I2C bus of the Arduino board. If you're using a different interface, you'll need to modify the Wire library calls accordingly. Also, the calibration values used in the code are for the default configuration of the INA3221, which has a maximum voltage of 32V and maximum current of 2A. If you're using a different configuration, you'll need to set the calibration values accordingly using the appropriate setCalibration method. Finally, note that the INA3221 has a maximum input voltage of 36V, so be sure to use appropriate voltage dividers or other means to ensure that the voltage applied to the sensor does not exceed this limit.
- */
- #include <Wire.h>
- #include <Adafruit_INA3221.h>
- Adafruit_INA3221 ina3221;
- void setup() {
- Serial.begin(9600);
- if (!ina3221.begin()) { // initialize the sensor
- Serial.println("Could not find INA3221 sensor!");
- while (1);
- }
- ina3221.setCalibration_32V_2A(); // set the calibration values for the sensor
- }
- void loop() {
- // read the current from each channel of the sensor
- float channel1_current = ina3221.getCurrent_mA(1);
- float channel2_current = ina3221.getCurrent_mA(2);
- float channel3_current = ina3221.getCurrent_mA(3);
- // print the current for each channel
- Serial.print("Channel 1 Current: ");
- Serial.print(channel1_current);
- Serial.println(" mA");
- Serial.print("Channel 2 Current: ");
- Serial.print(channel2_current);
- Serial.println(" mA");
- Serial.print("Channel 3 Current: ");
- Serial.print(channel3_current);
- Serial.println(" mA");
- // delay before reading from the sensor again
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement