Let me take a moment to thank you for posting on the HP Support Forums.
I understand that you have an HP ENVY 5540 All-in-One Printer and it is not working correctly. I read that sometimes the printer stays connected and sometimes not. Not to worry, I'll do my best to help you.
To provide an accurate resolution, I need a few more details:
Is the printer connected via USB or wirelessly?
Do you receive an error message? If yes, then what is it?
Have you restarted the printer and checked if it helps?
Meanwhile, I recommend you to perform the following steps to isolate the issue and arrive at a fix: