Most of what you’re referring to are proximity sensors. There are two kinds of *these*: inductive/ capacitive.
Inductive sense ferrous metals (magnetic because they contain iron)
Capacitive sense everything
They both have oscillating circuits that are interrupted because of an electromagnetic presence or a capacitive presense.
Latest Answers