Hi,
I am trying to turn on and off a fan using an Arduino Uno. As you can see in the figure I am using a Sparkfun fuel gauge (https://cdn.sparkfun.com/datasheets/Prototyping/bq27441-g1.pdf) to sense current drawing by the fan. I am turning the fan on for 1000ms and then turning it off for 1000ms. And after 100ms delay the turn on and off will go on continuously. Now the problem I am having is when I am measuring the current from the fuel gauge register I am not getting on-off current at a regular interval. From the datasheet of the fuel gauge, I attached say that (Table 8.10, page 7) the ADC conversion takes 1s to give every current measurement. Can anyone please suggest how should I calculate the delays (Or something else) in my code so I get a regular interval on-off load current? I am adding my code and circuit connection diagram (Please consider the picture quality) to make things clear. I really appreciate any suggestions.
**the load current diagram I added is for a LED but the ultimate target is connecting a FAN
Thanks a lot for your time!
#include <SparkFunBQ27441.h>
// Set BATTERY_CAPACITY to the design capacity of your battery.
const unsigned int BATTERY_CAPACITY = 500; // e.g. 500mAh battery
int Fan = 3;
void setupBQ27441(void)
{
// Use lipo.begin() to initialize the BQ27441-G1A and confirm that it's
// connected and communicating.
if (!lipo.begin()) // begin() will return true if communication is successful
{
// If communication fails, print an error message and loop forever.
Serial.println("Error: Unable to communicate with BQ27441.");
Serial.println(" Check wiring and try again.");
Serial.println(" (Battery must be plugged into Battery Babysitter!)");
while (1) ;
}
Serial.println("Connected to BQ27441!");
// Uset lipo.setCapacity(BATTERY_CAPACITY) to set the design capacity
// of your battery.
lipo.setCapacity(BATTERY_CAPACITY);
}
void printBatteryStats()
{
digitalWrite(Fan , HIGH);
int current = lipo.current(AVG); // Read average current (mA)
String toPrint = String(current) + " mA | ";
Serial.println(toPrint);
delay(1000);
digitalWrite(Fan, LOW);
current = lipo.current(AVG);
toPrint = String(current) + " mA | ";
Serial.println(toPrint);
delay(1000);
}
void setup()
{
Serial.begin(115200);
setupBQ27441();
pinMode(Fan, OUTPUT);
}
void loop()
{
printBatteryStats();
delay(100);
}

