I created a gadget using Arduino. I used libraries which are under GPL licence. I want to know about is, can I get a patent for my invention? Can I use this gadget for a commercial purpose?
Based on what you've told us in the question, no one tell you whether your gadget is patentable. This is understandable since you can't divulge your invention publicly before you file for a patent. You really should consider two questions. Freedom to operate and patentability. Freedom to operate means that no one else's intellectual property precludes you from selling your product. You need to perform a patent search. This answer describes how I approach this challenge, but having a profession do a search can be very helpful. If you have freedom to operate, you can then market your product, but it doesn't necessarily mean you can obtain a patent. In order to get a patent, you need to show that your gadget is novel (no one has thought of it before), useful (it performs a function) and non-obvious (to someone of ordinary skill in the field).
Lets consider a hypothetical situation. Lets say someone invents an entirely new type of electronic image sensor. The implementation of this sensor utilizes some open source image processing software. She has performed a through patent search and found all the relevant patents on electronic image sensors. She consults with a patent attorney who confirms that none of the claims in those patents covers the new design. I'm suggesting that the patent attorney is important because reading and interpreting claims requires skill and a knowledge of the law is useful. At this point, the attorney may provide an opinion that there is freedom to operate.
The patent attorney also can provide an opinion of patentability. This is related to freedom to operate but not the same thing. Lets say there was one patent that did cover the new invention, but it had expired. The new image sensor would not then be considered novel, but because the patent expired the person could still sell it. Assuming there is patentability, the inventor could then file for a patent. Although there is no legal requirement that you use a lawyer to draft the patent application, my experience suggests it is important to do so. Just because you might get a patent doesn't mean it is a good one that truly protects your invention. There is a lot of legal knowledge necessary to write a strong patent and the laws can differ depending on the country you are applying to. A strong patent means it covers the broadest embodiments of your invention so that it isn't easily designed around. In addition, the process of obtaining a patent generally requires some back and forth negotiation with the patent office and a patent attorney understands how to do this. This question and answer provides a good overview of the patenting process.
I didn't speak to your use of GPL software libraries. Of course you can't patent those. But neither do they preclude your from patenting your gadget. You can only patent what is novel. If this is a circuit, then the circuit may be patented even if you need code to use it. If you have some software which you believe is patentable, then you can patent that, but you wouldn't be patenting source code, you would be patenting the algorithm as applied to solving a problem. Software patents are particularly tricky so you need to consult with an attorney.