Computer plugged and unplugged

I am using Arduino base system, where using button u can launch motor for couple of seconds and read rpm.

My intentions was to read rpm and depending on rpm value sign alarm light or not. So, my problem now is whenever i am using arduino system connected to pc and reading serial port, it works perfect but when i am disconnecting my pc from the system , it is random (alarm state).

For Arduino is there any difference on system work between usb connected / serial reading and not ?

I am using (controllino mini) for my system.

My code is long and messy, so I didn't attach it here. I can do it if is needed.

Thanks.

How are you powering the Arduino Without the USB from the PC? A schematic would really help.