I'm working as a research assistant in a mechatronics lab. My research and work is largely based on designing circuits, robotics and programming. My PI also works on mechatronics. But I've also worked with two other professors. For one of them, I had to develop circuits for electrochemical studies and for the latter, I worked in a clean room for photolithography. But their fields ( chemistry and MEMS packaging respectively) are way different from the field I want to apply for ( mechatronics and robotics). Will it affect my application if I use a letter of recommendation from them, since their primary field of research is different from mine?
If your ability in developing circuits for electrochemical studies sheds light on how good you would be designing circuits for mechatronics (and I suspect it does), definitely get a letter from them.
If all the professor can say that addresses your ability in mechatronics is "he was smart, diligent, and careful," then that's certainly better than no letter, but you might be better off with a letter from somebody closer to your field, even if you haven't worked directly with them.
When I review an application's letters of recommendation, I look at what the letters say about the candidate first and who wrote the letters second. This means that a really quality letter from someone that knows your work is the number one goal here. If these "out of department" professors can give you a quality recommendation, I would not hesitate to ask them. They are still going to be familiar with what graduate programs overall are looking for and their disciplines are still somewhat related to your program choice.
Overall, you should perhaps have one letter from a professor in the field you are apply to. However, a quality letter of recommend is the #1 goal here.