Serial Monitor is stuck

I am new to Arduino. Therefore I try to do some testing on components before doing any actual project.I wanted to test my micro servo so I ran a code that I found online. Then I wanted to do other testing on other components but my serial monitor is stuck. It only displays previous code's outcome. I tried to uninstall arduino ide, delete its folders, use from another user but they did not seem to work. I start to think that the problem is in my arduino board by the way I use arduino uno. I have to do a project as a assignment and I don't know what to do now. (I use MacOS)

This is the code I found online

#include <Servo.h>

Servo servo_1; // servo controller (multiple can exist)

int servo_pin = 3; // PWM pin for servo control
int pos = 0;    // servo starting position

void setup() {
  servo_1.attach(servo_pin); // start servo control
  Serial.begin(9600); // start serial monitor
  servo_1.write(pos); // move servo to 0 degrees
  Serial.println("Positioned at 0 Degrees");
  Serial.println("Input Desired Angle and Press Enter");
}

void loop() {
  while (Serial.available()){
    String in_char = Serial.readStringUntil('\n'); // read until the newline
    Serial.print("Moving to: ");
    Serial.print(in_char);
    Serial.println(" Degrees");
    servo_1.write(in_char.toInt()); // convert angle and write servo
    delay(in_char.toFloat()*(10.0/6.0)); // delay for maximum speed
  }
}

This is how my serial monitor looks like.

The code displayed on the image (emo) is not the code in the code block (servo). Your servo code works (this link is a simulation).

Perhaps you need to click on the blue arrow to upload your emo sketch to your Arduino.

I tried to upload many codes on arduino after servo code but serial monitor still displays the same thing that i showed in the picture. It stuck no matter what code that has been uploaded.

The only code that you can upload to your arduino is the code that you see in the IDE (your picture).

To upload different code to your arduino, you must open that code with the IDE, then use UPLOAD button or SKETCH >> UPLOAD or CTRL-U.

Thank you for your respond. English is my second language so I think I couldn't explain my problem well. First I found this code online

Servo servo_1; // servo controller (multiple can exist)

int servo_pin = 3; // PWM pin for servo control
int pos = 0;    // servo starting position

void setup() {
  servo_1.attach(servo_pin); // start servo control
  Serial.begin(9600); // start serial monitor
  servo_1.write(pos); // move servo to 0 degrees
  Serial.println("Positioned at 0 Degrees");
  Serial.println("Input Desired Angle and Press Enter");
}

void loop() {
  while (Serial.available()){
    String in_char = Serial.readStringUntil('\n'); // read until the newline
    Serial.print("Moving to: ");
    Serial.print(in_char);
    Serial.println(" Degrees");
    servo_1.write(in_char.toInt()); // convert angle and write servo
    delay(in_char.toFloat()*(10.0/6.0)); // delay for maximum speed
  }
}

Then I uploaded it to my arduino board to test it then I detached my servo motor so I can use my arduino board for some other project. I write other codes after and uploaded it to my arduino. For example this code

void setup() {
Serial.begin (9600) ;
}
void loop() {
Serial.println("emo");
delay (3000);
}

The code I uploaded is not important because the serial monitor always displays following


I tried uploading other codes but the serial monitor always shows that.

To sum up, no matter the code I upload to my board it always displays the serve motor code's outcome.

I hope it clears some misunderstandings.

Do you get error messages after uploading fails ?
The first thing I would try is using 115200 baud both in the sketch and in the IDE...

I did click there but it does not work. Serial monitor acts like the old code is still running but i uploaded my new code.

I can upload any code I want so uploading does not fail. The IDE shows that my code is uploaded in arduino board but it does not work.

I use IDE 2.1.0 and it does not give any error messages when uploading. It uploads my code on arduino but I tried IDE 1.8.19 after writing my problem to this forum and it gives me verification error content mismatch.

Your board retains the uploaded program when power is off, as you show it keeps working whenever power is applied.

Is it possible that your usb cable is good enough to make the IDE happy and show output, but bad enough not to successfully upload... or could the logic on board not be functioning correctly during upload... or something else.

Try another cable, arduino, computer.

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