Serial Monitor read question

Hello all,
I have an Arduino Due that controls a motor that outputs a signal in frequency. I also have two adafruit INA260 power sensor connected that reads the input and output voltage, current, and power of the system. This sensors are connected via I2C to the Arduino Due. I checked the wiring to make sure everything was wired properly and that I was not overlooking anything hardware wise. Now I am confused on why my Serial Monitor stops reading the correct voltage when I start the motor. And this error does not start the exact moment I start the motor. It takes a couple seconds of reading and then it changes. Has anyone come across something similar? The code and screenshots of the monitor is below. There are other declared variables in the code but I did not use them. I would also like to add that having some of these pinmode's declared also caused a strange reading as well.


#include <Wire.h>
#include <Adafruit_INA260.h>

// POWER ANALYZERS
Adafruit_INA260 inPwr = Adafruit_INA260();

int startButton = 24;
int decibelMeter = A0;

float inVoltage = 0;
float inCurrent = 0;
float inWatts = 0;
float decibelLevel;

int startRelays = 30;
int heater = 31;
int fan = 9;
int motorFwd = 32;
int motorRev = 33;
int startFanRelay = 34;

void setup(){
  inPwr.begin(0x40);
  
  Serial.begin(9600);

  //INPUTS
  pinMode(startButton, INPUT);
  pinMode(decibelMeter, INPUT);
  
  //OUTPUTS
  pinMode(startRelays, OUTPUT);
  pinMode(heater, OUTPUT);
  pinMode(fan, OUTPUT);
  pinMode(motorFwd, OUTPUT);
  pinMode(motorRev, OUTPUT);
  pinMode(startFanRelay, OUTPUT);
}

void loop(){

  // NOISE LEVEL
   decibelLevel = analogRead(decibelMeter);
   decibelLevel = (decibelLevel/1023) * 50;

  // START RELAYS
  if(digitalRead(startButton) == 1){
      digitalWrite(startRelays, HIGH);
      digitalWrite(heater, HIGH);
      analogWrite(fan, 100);
      digitalWrite(motorFwd, HIGH);
      digitalWrite(motorRev, LOW);
      digitalWrite(startFanRelay, HIGH);
    }
    
  else{
      digitalWrite(startRelays, LOW);
      digitalWrite(heater, LOW);
      digitalWrite(fan, HIGH);
      digitalWrite(motorRev, HIGH);
      digitalWrite(motorFwd, LOW);
      digitalWrite(startFanRelay, LOW);
    }

   // INPUT POWER
  inVoltage = inPwr.readBusVoltage()/1000;// V
  inCurrent = inPwr.readCurrent()/1000;// A
  inWatts = (inVoltage * inCurrent);// W
  
  Serial.print("Voltage In: ");
  Serial.print(inVoltage);
  Serial.println("V");
  Serial.print("Current In: ");
  Serial.print(inCurrent);
  Serial.println("A");
  Serial.print("Power In: ");
  Serial.print(inWatts);
  Serial.println("W"); 
  Serial.println();
}

These are the screenshots I took of the monitor.

CORRECT

INCORRECT

It’s not your problem, but this just a bit untidy…
You should test for the change of button state, not while the button is pressed. this current method will pass any contact bounce through to the outputs.

1 Like

sounds like you may have a power supply problem - how do you power the motor?
upload a schematic of the system showing how components are interconnected

It looks like the problem happens as the voltage drops below about 10V. At that time the current drops to near zero.

Is there some kind of cutout in the power source? For example, a 4S LiPo battery might have a low voltage cutoff when the cells got down to 2.5V each.

my desktop power supply in addition to the output voltage setting has a cut off which I can set to the maximum output current. When the level is exceeded it reduces the output voltage to 0V.
This may be you problem.
Also when the motor switches ON you may get spikes or dips on the power supply line which could cause problems with the microcontroller and/or sensors. You may also need to use shielded cables for the motor leads.
Upload a schematic ouf your circuit with details of the power supplies.

I don't have a rough schematic of my general system currently. I can work on getting one. But for now I am using a 12 Volt mower battery as the power supply. I thought it could be a cut off but none of my sensors have that ability to cut off at a certain voltage lower than normal. Another thing I found out with experimenting the other day was that the serial monitor returns to reading normal if I just close it and open it again. Do you think its some sort of communication issue w/I2C of the arduino due.

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