There are proximity sensors that, among other things, detect whether the gear parts (misc. struts and hinges; doors) are in the correct positions that indicate down and locked, or open/closed, and so on. I.E. if a gear door is not within 2mm proximity of the sensor, that door is not "closed" safely.
Those send an output signal to the aircraft systems, which will then recognize dangerous conditions (gear not down and locked, door not closed) and issue warnings in the form of EICAS indications, flashing lights, and alarm sounds.
They are analogous to the proximity sensors in many home-security systems, which will sound the alarm if a sensor and magnet pair have been separated by someone opening a window or a door.
For a simpler and more obvious example - the radar altimeter is a form of proximity sensor. It measues proximity to the ground. If the aircraft systems receive signals that the aircraft is within, say, 500 feet of the ground - and the gear detectors are not indicating down and locked, a warning will sound: "Landing Gear! Landing Gear!"