Arduino IDE is displaying unusual output in the serial monitor. I am getting the same output in every code even without connecting anything. Pls help i am a newbie.
Make sure you use
Serial.begin(9600);
So it matches the baud rate setup in your monitor
When I'm having trouble with serial output, I like to do a quick check with the most simple possible sketch. If this works, then I know the problem has something to do with my real sketch. If it doesn't work, then I know the problem is not related to my sketch code. It seems maybe a little silly, but it allows me to be sure I'm focusing my troubleshooting efforts in the right direction.
Try uploading this sketch to your Arduino board:
-
Copy and paste this code as a new sketch in Arduino IDE:
void setup() { Serial.begin(9600); } void loop() { Serial.println("hello"); delay(1000); } -
Upload the sketch to your Arduino board.
-
Wait for the upload to finish successfully.
If it does not finish successfully, add a reply here on the forum thread to inform us of the failure and we'll investigate further. -
Select Tools > Serial Monitor from the Arduino IDE menus to open the Serial Monitor view if it is not already open.
-
Make sure the baud rate menu at the top right corner of the Serial Monitor panel is set to "9600".
Do you now see the word "hello" being printed in the Serial Monitor's output field once a second?
What do you mean by "without connecting anything"?
Do you mean that you don't have the Arduino board connected to your computer with a USB cable?
Or are you saying that your sketch is intended to read data from some external component connected to your Arduino board and that component is not connected to the board?
it means without connecting any components or wires to the arduino
Depending on your sketch code, it could still produce Serial output even if no components are connected to the board. So this is not necessarily odd.
Please post your full sketch.
I'll provide instructions you can follow to do that:
- Select Tools > Auto Format from the Arduino IDE menus.
ⓘ This is done to make the code easier for us to read. - Select Edit > Copy for Forum (Markdown) from the Arduino IDE menus.
- In a forum reply here, click on the post composer field.
- Press the Ctrl+V keyboard shortcut.
This will paste the sketch to the post composer. - Move the cursor outside of the code block markup before you add any additional text to your reply.
- Repeat the above process if your sketch has multiple tabs.
- Click the "Reply" button to post your reply.
When your code requires a library that's not pre-installed in "Arduino Cloud Editor", please post a link to where you downloaded that library from.
i am getting same output as previous and not hello
#define trigPin 5
#define echoPin 4
#define ledPin 13 // Optional, for testing
long duration;
int distance;
boolean previousState = LOW; // Keeps track of the previous light state (off)
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT); // Optional, for testing
}
void loop() {
// Trigger ultrasonic sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read echo pulse duration
duration = pulseIn(echoPin, HIGH);
// Calculate distance in cm
distance = duration * 0.034 / 2;
// Check if object is within range and toggle light state
if (distance < 50) {
previousState = !previousState; // Invert the previous state
digitalWrite(ledPin, previousState); // Optional, for testing
Serial.print(previousState);
}
delay(500); // Adjust delay between checks as needed
}
I've corrected the spelling mistake in 'unusual' in the title of your topic.
You have COM4 port selected. If you unplug your Arduino, does COM4 disappear from the menu and reappear when you plug the Arduino back in?
yup
pls give info on what has happened or what should be done to fix it
What project did you use this on previously? What do you have connected to pins 0 and 1? Show a photograph of your Arduino.
actually i was trying to use a ir remote when this happened
before this i made a mouse controller using joystick
Nothing was connected to pins 0 and 1 in the ir remote project
Would you test this and describe your observations?
i tested it twice and both times when i unplugged the arduino COM4 disappeared and appeared back when plugged in
Here is the latest code on which i was working when this happened with the picture
#include <IRremote.h>
const int RECV_PIN = 2; // Define the pin where the IR receiver is connected
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(9600); // Initialize serial communication
irrecv.enableIRIn(); // Start the IR receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX); // Print the received value in HEX format
irrecv.resume(); // Receive the next value
}
}
Open Device Manager. Unplug the Arduino and plug it in. Watch the Device Manager and note what new device appears. You might see FTDI or CH340.
I can see CH340


