Always comes with one extra zero as an output in Available command

can somebody helps me to find the error why i am getting it like this. i input 3 but getting the zero afterwards.?

likely because what we don't see in the picture - you are sending a CR or LF or both as line ending in the serial monitor.

parseInt() won't read this and will stop leaving - say CR - in the Serial input buffer and so the next time you arrive there you have stuff to read so proceed through the while() but no number to read and when it has nothing to read parseInt() returns 0

try not sending anything as the end of line in the serial monitor. ParseInt() will then timeout after 1s and the code would work if you don't type too fast.

I would suggest to study Serial Input Basics to better handle serial input


please, please never ever again post pictures of text... Not only they are not readable nor usable directly for copy&paste but they use up lots of storage and internet bandwidth which contributes to polluting the planet.

➜ do your part and do yourself a favour and please read How to get the best out of this forum

Help us help you.

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