What follows is my understanding of the issue:
It used to be that whoever came up with the invention first got the patent. There were several common things to try to keep records of when you had the idea. One was to write the details in a signed and dated notebook. Another was to write it down, mail it to yourself, and file the letter without opening it.
I have no idea how much either of these helped.
I think that we now have a "first to file". You could write it up and file. Note, however, that the patent filing has to describe the invention enough that anyone with an ordinary skill in the art could build the device from the description in the patent. If you need an engineer to come up with those details, then it's going to be difficult for you to be first to file if the engineer does it himself.
In any case, unless you have experience writing patent applications, you really need a patent attorney to help and they aren't cheap. I don't know what it would cost these days, but it wouldn't surprise me if it weren't $100,000 or more and it would surprise me if it were less than $50,000.
Without a patent attorney, you could easily end up with a patent that has no value because of your own mistakes.