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
}
}
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.
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
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.