Hand sanitizer with proximity sensor and pump

I was trying to make hand sanitizer with IR sensor, TIP42C and pump but its not working for me.

Im using 9V battery.

The DC pump is always in running mode for me.
The only observation I could make was that the speed of pump is slow when connected in this circuit as compared to when I connect the pump directly to the 9V battery.

But still Im not able to understand why the pump is always in running mode (EVEN when the proximity sensor isnt activated) , I followed the circuit exactly as is shown.

The TIP42C is a transistor, not a Darlington pair, so requires substantial base current to switch
high current loads. Try 150 ohm resistor instead of the 1k base resistor. This probably
explains the slow running.

Is the sensor active low? It needs to be active low if driving a PNP transistor like the TIP42

Inductive loads like motors need free-wheel diodes across them to protect from inductive
voltage spikes.

Also, if that proximity sensor is putting out somewhat less than 9 volts (say it has an on board voltage regulator), it will not be able to bring the base of the PNP transistor high enough to switch it off.

Edit. If it is this one. then it has an open collector output so it should supply 9 volts (with built in pull up resistor), but observe the allowed voltage range.

MarkT:
The TIP42C is a transistor, not a Darlington pair, so requires substantial base current to switch
high current loads. Try 150 ohm resistor instead of the 1k base resistor. This probably
explains the slow running.

Is the sensor active low? It needs to be active low if driving a PNP transistor like the TIP42

Inductive loads like motors need free-wheel diodes across them to protect from inductive
voltage spikes.

Thanks Mark. Its running at 5V now, but its working "opposite way". The pump is running when no obstacle is there. But when I place my hand near proximity sensor, pump slows down to very low speed (again this is an issue as to why its not stopping completely) . What could be issue

The PNP will only stop if its base and emitter voltages are within 0.4V of each other, presumably this
isn't happening. The multimeter is the tool you need all the time to see what's happening in circuits,
I'd recommend checking all the voltages are what you'd expect for each condition. Perhaps the sensor
doesn't behave like you assumed?

MarkT:
The PNP will only stop if its base and emitter voltages are within 0.4V of each other, presumably this
isn't happening. The multimeter is the tool you need all the time to see what's happening in circuits,
I'd recommend checking all the voltages are what you'd expect for each condition. Perhaps the sensor
doesn't behave like you assumed?

Hi Mark,
This is my IR sensor which I'm using

Also someone told me this which I really couldn't understand at all being a noob
"you might need low side switch (NPN) to switch ground to the pump. And as there are usualy comparators (that can sink few milliamps curent but source capability is in microampers) you might need stronger pull up or small current PNP."

It can be very confusing trying to work out how those small modules behave, unless you can find a schematic diagram. The descriptions are often misleading.

Yours makes this claim:

The sensor outputs a logic one (+3.5V) at the digital output when an object is placed in front of the sensor and logic zero (0V), when there is no object in front of the sensor.

In that case you want an NPN transistor (or an N channel logic level mosfet). The circuit has to be configured as a low side switch. See the left hand image below. Since it is not clear how much current that sensor can source or sink (I see what could be a comparator and 10k pull up resistor on that board), an N-Channel mosfet is a safer choice (the image third from left below)

This may help: https://www.baldengineer.com/low-side-vs-high-side-transistor-switch.html

What is the power rating of that pump ?