What is the best and most reliable way to detect if a book is pulled out of a book case?

I have a book case which I want to mount sensors to so that I can detect when certain books are pulled out, I don't need to know how much, all I need is a boolean trigger if the book has been pulled out 2+ cm or so (works with lower too). I would preferably also want to know when they have been replaced but that is just a bonus.

The goal of the project is to move a servo which may or may not open a secret door when 3 books are pulled out in a certain order.

The sensors need to be able to work continuously 24/7 for years.

Here is a masterfully drawn picture to explain it even better.

enter image description here

So far I have been thinking of mechanical switches, Ultrasonic Sensor (HC-SR04), or possibly some sort of infrared light and sensor that can detect a change in intensity (where a lower intensity is book being pulled out).

The mechanical switch I could easily do, but I would prefer something that is less obvious, and less "clicky" when it's triggered. I don't want to give away that there is something special with a book if someone picks it up on accident.

Any ideas on how it can be done? Would love tips for specific components as I'm not native to the arduino world and have a hard time finding exactly what I'm looking for.

  • 2
    IR proximity is probably the most discrete - the kind of thing that's built into your phone to detect if a case closes or opens.
    – Majenko
    Commented Sep 30, 2020 at 19:30
  • 2
    Great idea for an Arduino project by the way :)
    – chrisl
    Commented Sep 30, 2020 at 19:52
  • 1
    best way would be multiple cameras connected to a CV system ... seriously, best is meaningless .... specify some parameters, such as cost, speed, need for expandability, etc.
    – jsotola
    Commented Sep 30, 2020 at 20:08
  • I'd suggest a Photo Reflective Sensor.
    – Gerben
    Commented Oct 1, 2020 at 14:47

4 Answers 4


As Majenko stated in the comments, an easy and discrete way would be using IR proximity sensors behind each book. The IR light from them is invisible to the eye, they are easy to read with an Arduino and often the casing of the IR LED and IR sensor are black, so that you could easily hide them in a black backplate of your book case.

The IR sensor will output one pin state (HIGH or LOW depending on the sensor), when something (the book) is near it (on most sensor modules you can change to threshold to your liking), and the other, if nothing is near it (empty place in the book case)

Searching "ir proximity sensor" at amazon gives multiple good looking results for ready to use sensor boards.

Another - more hacky - way would be to build your own switches at the top of the book case. As a switch is nothing more than 2 electrical contacts with some mechanic suroundings, you could add a small piece of cardboard above each book, which falls down a bit, when the book is removed, but not enough, that it is easily spotted (a few millimeters should be enough). At the top of the case and on the cardboard piece you put some piece of tinfoil or aluminum tape. When the book is put in the box, the tinfoil pieces get pressed together by the book, thus make contact. Wire one piece to ground, the other to an Arduino pin.

I find the IR sensor solution better, but I wanted to include a solution, where you don't need to buy extra sensor modules.


If you want the book and shelf to look normal, then use tiny magnets in the books and either reed switches or hall magnetic sensors embedded in the bookshelf. You can even discriminate two books by minding the magnet's polarity.

  • Simple and reliable, this would be my solution.
    – StarCat
    Commented Sep 30, 2020 at 20:39
  • The range of magnets isn't great, so the books have to always be precisely aligned. I'd advice against this.
    – Gerben
    Commented Oct 1, 2020 at 14:45

I assume all these solutions need to know exactly what book is where (positioned).

A solution could be a long LED strip (or other light) above the books, and at the bottom a strip of photo resistors (LDR), placed at every 2 cm. Place this photo resistors far enough backwards to cover the end of the shortest book (unless you do never change the order of the books you can place them exactly at the width of the book minus a cm or so).

  • My original plan was to place thicker books that are easy to detect in certain spots and drill holes as needed for the sensors behind them.
    – JensB
    Commented Sep 30, 2020 at 19:37
  • 1
    In the solution with LDRs, it's better to have the LDR under the books, or place the LDR directly behind each book, but then the LDR should (almost) has to touch the book to prevent light getting on the LDR. Commented Sep 30, 2020 at 19:41

Why not use RFID tags and sensor. You can do an inventory any time you want. The RFID tags are inexpensive and the sensor is not that much and available for the Arduino. Nothing shows if you put the tag in the spine of the book.

  • 1
    a tag in the spine would be perpendicular to an under-shelf RFID sensor, which won't scan. Also, you only have about 2cm of range with a tag, so you would need 3 such sensors for three books, and a tag in the spine is probably out of the question due to limited range. Neat idea though, and if you can get them to scan, this is the only way to have different combos do different things...
    – dandavis
    Commented Sep 30, 2020 at 20:37
  • 1
    Depends on the sensor and tag. Using a system in the 865 - 960 MHz – Ultra High Frequency (UHF) – A short, high-energy wavelength of about a one meter which translates to long read range. Passive UHF tags can be read from an average distance of about 5 - 6 meters, but larger UHF tags can achieve up to 30+ meters of read range in ideal conditions. If he goes to active tags the distance is much greater. If that is to far you can adjust the sensitivity down.
    – Gil
    Commented Sep 30, 2020 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.