In the last week I’ve been working on a device, which uses an electronic compass. I chose HMC5983, so no rocket science happening – I used the recommended layout, made a prototype PCB, populated it and wrote the firmware. Everything went smoothly on the first try.
Then I adjusted position of the components on the board, repositioned few wires and made a batch of 6 new PCB. After I populated them, the compass stopped working – the X axis showed fixed value, the other one were working properly. Strange, right? If it was one board, I would thought about damaged component. But all 6 boards featured the same behavior. After two hours I finally localized the cause of the troubles – a piezo buzzer. At least I thought it was a piezo buzzer.
My board uses a pizeo to notify the user via beeping. I used the standard 12 mm piezo in a plastic housing:
However the piezos I used weren’t piezos – they were actually a small speakers with a magnet inside, as I found out after I crack opened one. It is impossible to tell the difference between piezo and a speaker in the same package. In the first revision, the piezo buzzer was concentric with the HMC5983, so only Z axis, which a I didn’t plan to use, was I affected. However in the second iteration I moved the piezo a little bit – assuming it has no significant magnetic field. But the parts I used, actually had a quite strong magnetic field.
Luckily, the magnetic field from the speaker didn’t saturated the sensor, so a software compensation was possible.
I learned a lesson – inspect the parts before using them in your project.