I am trying to design a circuit to measure the angle (horizontal and vertical) to a wall and would like suggestions on the best way to do this. The design has to be low cost (ie, the components shouldn't cost more than $20 total). The device needs to be able to communicate the information in a way so I can read it with a microcontroller and send the data with I2C.
Currently, I have a design using AMR (magnetics that determine absolute position based on the earth's magnetic field), but it is too susceptible to magnetic interference from other devices. This solution doesn't actually determine an angle to the wall, but is acceptible because I can calibrate a reference angle of 0, and then it can automatically measure the change in angle.
I was thinking of maybe some way to use optics or ultrasound? Any suggestions would be appreciated. Thanks.