I’ve got a large wall with 1” holes scattered about. I’ve got some wooden pegs that fit perfectly into these holes. Now I’m thinking of creating a light installation based on the pegs, but i’m Struggling to find a way of detecting when a peg has been inserted into any hole.

What’s the best method of detecting them? I was thinking a stop switch that’s just placed on the edge of the hole to the peg activates it, but i’m Not sure how well that can be detected or if it would bend with use

  • 2
    Maybe photo interrupters, reflective photo interrupters or even switches
    – KIIV
    May 10, 2018 at 8:56
  • I prefer not using switches. Moving part will wear out over time.
    – Gerben
    May 10, 2018 at 15:49
  • 1
    do an image search for microswitch .... some are rated for more than 10 million operations
    – jsotola
    May 10, 2018 at 22:10
  • Thats the term – stop switch is just what it's used for the 3D printer here. I think it's the most analog way of detecting it, which means it's the less complex of all the options May 11, 2018 at 11:34

1 Answer 1


We can't tell you the "best" method. It depends on too many details we don't have.

Here are some options:

  • A reed switch at the bottom of the hole and a magnet on the peg.
  • A photo sensor at the back of the hole -- the peg blocks the light.
  • As you suggest, a switch at the side of hole.
  • Use contrasting colors on the wall and the pegs and detect the pegs using a camera and some sort of image processing (not an Arduino solution)

I think you are going to need to build some prototypes and experiment to find the best option for you.

  • Reed switch might be an option, have to think of how this is mounted and how the peg has a magnet integrated, or maybe a line detector sensor and paint the pegs black in a similar vein to the colour detection? May 10, 2018 at 15:27
  • 1
    Alternative for the reed-switch would be a hall-effect sensor. Alternative for the photo-sensor on both sides of the hole, would be to measure reflected light instead using e.g. a TCRT5000.
    – Gerben
    May 10, 2018 at 15:47

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