Serial Monitor Displays "�"

I have no idea why this happened but when I try to use the serial monitor, it just displays a weird symbol with this code:

void Foward() {
digitalWrite(6, true);
digitalWrite(5, true);
digitalWrite(7, false);
digitalWrite(4, false);
}
void Stop() {
digitalWrite(7, false);
digitalWrite(6, false);
digitalWrite(5, false);
digitalWrite(4, false);
}
void Right() {
digitalWrite(7, true);
digitalWrite(6, false);
digitalWrite(5, true);
digitalWrite(4, false);
}
void Left() {
digitalWrite(7, false);
digitalWrite(6, true);
digitalWrite(5, false);
digitalWrite(4, true);
}
void Backward() {
digitalWrite(7, true);
digitalWrite(6, false);
digitalWrite(5, false);
digitalWrite(4, true);
}
void Rest() {
  Stop();
  delay(0.25*1000);
}

void setup() {
//right motor A IN1
pinMode(7, OUTPUT);
//right motor B IN2
pinMode(6, OUTPUT);
//right motor PWM
pinMode(11, OUTPUT);
//left motor A IN3
pinMode(5, OUTPUT);
//left motor B IN4
pinMode(4, OUTPUT);
//left motor PWM
pinMode(10, OUTPUT);
//servo motor PWM
pinMode(3, OUTPUT);
//left IR Sensor
pinMode(8, INPUT);
//right IR Sensor
pinMode(9, INPUT);
Serial.begin(9600);

}

void loop() {
  Serial.print("Hello");
}

(I'm trying to make a line following robot by the way)

But it works totally fine when I use this simple code:

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

void loop() {
  Serial.print("Hello, World!");
}

Can anyone help me out?

The setup() in the bad code neglects to call the begin() method for the Serial object.

Oh, wait, it does. Never mind.

a7

What's the baud rate setting for Serial Monitor?

The baud rate is 9600.

To be clear, not in your code, but in Serial Monitor?

Yes the baud rate is 9600 in the serial monitor and the code.

Okay. How are you physically connected - via USB, or wires to TX, RX? IF the latter, have you connected GND?

Does the first sketch work if you disconnect the stuff it looks like you hanging on the Arduino?

Just the Arduino board, the code, but nothing connected to the i/o pins.

a7

The Arduino is connected to my computer via USB, nothing is connected to TX or RX.

1 Like

Okay, then result of post#9? Likely, you're overloading the Arduino.

Is there anything I can do to make it not overloaded? Everything that is currently in use is necessary.

Start here:

We need a schematic, to see what you're doing. Crystal balls are in short supply.

Okay I will work on making one.

pencil sketch on piece of paper, take a picture. All that's needed. Add descriptive labels.

Here's a schematic for the code. Let me know if you need anything explained more. (Sorry if the wires are a little messy or hard to follow.)

Okay. So. Several comments.

  1. 9V battery to Vin - will last a few hours, IF you remove all other loads...
  2. Servo must not be powered from 5V output,
  3. 9V battery to Motor driver, again will only last a short while unless the motors are puny

In general, I would suggest:
Get yourself a 5V, 2A DC power supply.
Power the Arduino(only) from your 9V battery
Power the Servo, the IR, and the motor driver from the 5V supply.
Remember to connect the GND of the 5V supply to the GND of the Arduino, the signals to servo and motor driver need that connection.

I totally agree with this, however, this is for a autonomous, line-following robot. I'm not sure if a power supply would work too well because of the size and the robot might be effected by a cord dragging across the ground. Unless you mean a battery, and not the kind of power supply I'm thinking about.

Do you have any recommendations for a power setup to power the servo, IR sensors, and the 5v input for the motor driver?

My approach would be different - get the code working while tethered with a power supply; get the programming sorted where you don't have to worry about the power considerations; then, get a device that has working code working on a battery. That's "divide and conquer", and it's always served me well.

As for powering by battery, I've not done it, but I'd look at a battery bank(LiPo, maybe, or other; something around 6V) and a buck converter to give you stable 5v for devices. Quite likely the battery would power the motor and servo directly, though you need to watch the voltage range for the servo, and the detectors and Arduino would be run off the buck converter.
I think there's literally thousands of such arrangements littered around the web, but sorting wheat from chaff is tough if you don't know electronics.
Good luck

Thank you so, so much for your help! It has been such a time saver, and I really appreciate it!
Thanks,
YELL0W01