Flap position sensor

To determine whether the cat is in or went out, the recognition of the chip on the outside of the cat flap is not enough. That's why I attached a potentiometer to the axis of rotation of the flap. It is connected to an analog input of the MCU. Since there is no free analog input pin on the PCB of the flap i had to slightly modify the PCB.

Mechanics & potentiometer
I used an old East German RFT 10K1 potentiometer (linear). The 4mm shaft fits into the hole on the side of the plexiglass door and sitting there pretty solid. As can be seen in the picture below, the housing must be worked out on the side on which the potentiometer is built. When assembling the potentiometer to the plexiglass door make sure that it is in the middle position (ie 2.5V supplied to the microcontroller) when the flap is in the rest position. The potentiometer is fixed with a little bit of hot glue to the flap enclosure, so it does not rotate with the door.


The potentiometer is attached that way that it supplies a voltage between 0V and 5V on the on sliding contact pin depending on the position. See the picture below.


The sliding contact pin must then be connected to an analog input on the microcontroller. Because the board has no more free analog inputs, it has to be modified. The operational amplifier on the RFID receiver board can be turned on and off (for power saving purposes?) by the MCU. Therefore it's supplied with power from pin RB3 (24). As it happens to be this pin can be used as an analog input, so i connected the operational amplifier directly to the power supply and severed the connection to pin RB3 (24). Then I connected the sliding contact pin of the potentiometer to this pin.

To accomplish this i did the following steps:

  • Desoldered the SMD resistor R25
  • Soldered a connector for the sliding contact pin of the potentiometer to the left pad of the resistor R25 (which is connected to the microcontroller)
  • Soldered the power supply of the operational amplifier on the RFID board via a 330-ohm resistor to +5 V (pin 1 of JP5) (see second picture)


In the potentiometer version of the firmware is assumed that the flap is at rest, if 2.5V are applied to pin RB3 (24) of the microcontroller. The function GetFlapPosition() then returns 0. Upon opening of the flap in one direction, this value then goes from 1 to 127 (maximum opening of the flap) and in the opposite direction from -1 to -127. With this the direction of the flap actuation is determined. To prevent that the serial port flooded with reports of movements of the flap, the firmware only sends the message "EVT - opened flap: <value> " if a value specified in the configuration (default 50) is exceeded positively or negatively. Logically,the message "EVT - flap closed: <value>" is sent when the flap is at rest for more than two seconds. (See also serial communication).

Last modified 2 years ago Last modified on Oct 18, 2014, 12:42:10 AM