Selfmade hand sanitizer?
Others have mentioned options for the sensing.
A simple option for the dispensing would be the use of a peristaltic pump driven by a stepper motor.
Each half rotation of a peristaltic pump will give an amount of fluid which is largely consistent each time. The amount is related to the cross sectional area of the pumping tube, and the diameter of the pumping head.
The nice thing about these pumps is that they can work with gels as easily as fluids (I used one to pump epoxy potting compound at one point). Furthermore, when the pump is not spinning, you get no flow through the pump (as its effectively self sealing). You can also make one yourself relatively easily (its just a piece of tube, a cylinder and a rotating rubber head).
By using a stepper motor, you can perform a half rotation, or a full rotation if you want more. That will give you a certain number of units of measure. Then stop.