Serial Monitor

I wrote a program that would monitor a 12v battery and create a high output on a selected pin when voltage dropped to 10.6 volts. I did this by using serial monitor when Arduino was plugged into computer via USB. When unplugged from computer the process did not seem to work. Does serial monitor only work when plugged into a computer? When trying to monitor a battery voltage through a voltage divider can I use serial monitor commands to create the cutoff voltage or do I need to use some other type of command?

Hello!

Serial communication works using Rx and TX pins also, but if you're using Serial when Arduino is connected to your PC, it wont work once you unplug it.

I recommend you to upload your code so that me or a real master around can suggest you chages.

Serial monitor is a program that runs on the PC and communicates with the Arduino. So if you aren't connected to the PC it isn't going to do anything useful.

Post your program so we can see what it is that you're really trying to do.

Steve

Are you using an Arduino UNO? If not, what kind of Arduino are you using?

Was using a Nano. Here is the code.

int cutofflow = 7;

void setup() {
Serial.begin(9600);

pinMode(cutofflow, OUTPUT);

delay(12000);

}

void loop() {

int sensorValue = analogRead(A0);
int voltage = map(sensorValue,0,1023,0,500);
int cutofflow = 7;

Serial.println(voltage);
if (voltage < 211)
{
digitalWrite(cutofflow, HIGH);
}

delay(1000);

}

How do you power the Nano when it is not getting power via USB?

12 volt battery through a 5v voltage regulator

johnwasser:
How do you power the Nano when it is not getting power via USB?

Atmegaman224:
12 volt battery through a 5v voltage regulator

How is the 5V connected to the Nano?

Do you have the required capacitors on both sides of your 5V regulator?

yes although I do not think they are required. The pin that sensed the voltage was fed by a voltage divider to read analog values in the 5v range. What I would like to know is, is there a pin on the nano that could read voltages, perhaps as analog values, and what type of code or commands could I use to trigger an output on another pin. The serial monitor command worked but apparently that only works when the nano is plugged into a computer via usb. So is there a way to convert battery voltages to analog values without using serial monitor? What type of code could be used to achieve this?

You're already doing it. If you simply comment out the Serial.println() it will light the LED as required.

Of course your program never switches the LED off so once it's on it stays on for ever but that's a different problem easily solved with an else after the if.

Steve

Again:

johnwasser:
How is the 5V connected to the Nano?

For some reason I can’t see your wires from here.

If you want to do it without Serial:

const byte CutoffLowPin = 7;

// Check with a meter on the Aref pin
const float AnalogReferenceVoltage = 5.0;

void setup() 
{
  pinMode(CutoffLowPin, OUTPUT);
  digitalWrite(CutoffLowPin, LOW);
}

void loop() 
{
  float voltage = (analogRead(A0) * AnalogReferenceVoltage) / 1024.0;

  // Of course the read voltage is not the actual battery voltage
  // because you are using an unspecified voltage divider with
  // resistors of unknown value and tolerance.  Measure with a 
  // meter to get a conversion factor if you want to measure
  // actual battery voltage.
  
  if (voltage < 2.11)
  {
    digitalWrite(CutoffLowPin, HIGH);
  }
}

thank you I will try this in a bit