• The IR proximity sensors have a very 'switchy' behavior: on or off... You may be more successful with a ultrasonic sensor. Size of the magazine and the fact that it is a 'closed environment' (with lots of wall reflections) may pose extra challenges. Other measurements could be implemented by placing a 'resistor-band' (heavy computer magnet tape) inside the magazin body and a wiper to the moving part. Placing the ends to 3.6 and 0 V and reading the wiper's voltage with an analog read will do a good job. A cross cut could look like this:

    .----------------------------.
    | .------------------------. |
    | |                        | |
    | |                        | | spring pushed part
    | |                        | |
    | |                        | |
    |  -----------|------------- | wiper on the spring pushed plunger
    | -------     W    -------   | regular tape taping...       
    |     ----------------       | ...resistive tape to case side
    .____________________________.
    

    You can use the spring as the 'wire' from the wiper to the wire you connect to the analog input to avoid having moving wires in the box interferring with the spring: solder the wiper to the moving end of the spring and the wire to the fixed one at the bottom of the clip. The regular tape works also as an insulator and distancer so that only the wiper touches the resistor tape and not the metallic - conducting - spring. You may anyway have a tight situation with the tapes taking up some space as well.

About

Avatar for allObjects @allObjects started