Hi, i just bought an arduino uno r3, it was included in a starter kit.
I don't know if my unit is broken or i just don't understand something...
If i run this simple script
void setup() {
Serial.begin(9600);
}
int num = 0;
void loop() {
delay(125);
num++;
Serial.println(num);
}
It starts counting as expected, until it reaches 1500 +- iteratinos. After that it ignores the delay function and prints out rapidly still counting up. It goes until 4000+- and after that it restarts from 0 with the delay working again.
If i wait like 2-3 times this whole process, it does not restart anymore, it is just frozen and doing nothing. Sometimes it prints out garbage in the serial monitor before freezes like these: ⸮⸮ and other characters i have never seen...
If i connect an LCD, it does the same thing but it requires like 20 iterations instead
I tried to connect a humidity sensor and print it to the serial console. It works, again for a few loop cycles, than it resets or reads garbage and freezes.
The arduino is powered from the USB port not from batteries
Edit: Just tried with batteries. It does the same thing, it resets after 150 cycles or prints garbage across the whole LCD...
My test code with batteries:
Something really strange must be happening in your Arduino UNO. Without the delay, my UNO counts about 160 times a second. With the delay, it counts a little under 8 times a second and counted well past 5400 without noticeably changing speed.
void setup() {
Serial.begin(9600);
}
int num = 0;
void loop() {
num = millis();
Serial.println(num);
}
My serial monitor shows an interesting thing.
It starts at 0, goes up to 70, and after that it prints the same 70 over and over again, and freezes
Edit: after multiple runs, it goes up to a random number, some times only to 1, and prints it over and over again. If i turn on timestamps it shows between start and freeze was between
17 - 35 seconds
Garbage i was talking abaout:
⸮T⸮⸮_⸮⸮~⸮⸮⸮⸮⸮⸮⸮}⸮⸮⸮⸮⸮⸮߾⸮⸮⸮⸮W⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮r⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮?⸮C?⸮=⸮X⸮>⸮⸮U⸮
⸮K;⸮⸮⸮|⸮⸮⸮x⸮⸮⸮⸮'⸮⸮t⸮⸮W⸮߿⸮⸮^⸮⸮/⸮⸮⸮⸮mt⸮⸮s⸮⸮zc߯
On my Arduino UNO it counts up about every 7 or 8 milliseconds and when it goes past 32767 it rolls over to -32768 (as expected) and counts up from there.
Sounds like your PC is having trouble keeping up with the input. If I increase the baud rate to 115200 (12 times faster) the Serial Monitor eventually starts to get bursty (pauses between bursts of output) and eventually crashes due to Java running out of memory. If put in a 500 millisecond delay, the number just keeps counting (overflowing every 32.767 seconds).
Try adding more delay until the problem goes away. That will give you a rough idea of how much data your PC can handle.
Time to buy a new PC. It sounds like your Serial Monitor can't keep up. Your original sketch was sending 5 characters ("1500\n") every 125 milliseconds. That's only about 40 characters per second (about 400 baud). A modern PC should be able to handle 9600 baud easily.
I have a Lenovo legion 5 pro (Ryzen 5800H / RTX 3070) so it is not my PC's fault for sure
It does the same thing on batteries, if i connect an lcd and count up from 0 with 1000ms delay, it will ignore the delay the same way