Proximity Sensor + Pump Project - code responds to input, but is not outputting

I am new to Arduino and coding in general. I have done a few tutorials and easy projects and I am now starting something of my own.

Trying to achieve a proximity sensor that will detect when someone’s glass is close, then trigger a pump to fill the glass.

Main parts used:

  • Arduino Uno
  • Sparkfun APDS 9960
  • TIP 125 PNP Transistor
  • Perialistic Pump
#include <Arduino_APDS9960.h>
#include <Adafruit_APDS9960.h>
#include <Wire.h>
#include <SparkFun_APDS9960.h>

// Constants won't change:
const int sensorData = 2;     //APDS Sensor input
const int pumpControl = 9;    // the pin that the pump is attached to

// Variables will change:
int proximityValue = 255;  // Proximity data between 0 and 255

void setup() {
  // initialize the button pin as a input:
  pinMode(sensorData, INPUT_PULLUP);
  // initialize the LED as an output:
  // initialize serial communication:
  pinMode(pumpControl, OUTPUT);

  // Initialize Serial port
  Serial.println(F("SparkFun APDS-9960 - Proximity Pump"));


void loop() {
  // read the sensor data input pin:
  if (APDS.proximityAvailable()) {
    // read the proximity
    // - 0   => close
    // - 255 => far
    // - -1  => error
    int proximityValue = APDS.readProximity();

    // print value to the Serial Monitor

  // compare the buttonState to its previous state
  if (proximityValue <= 100) {
    // if the sensor reads something close
    (pumpControl == HIGH); 
      // if the current state is HIGH then the pump turns on
    else {
      // if the current state is LOW then the pump stays off
      (pumpControl == LOW);

  // wait a bit before reading again

My code is responding the way I want it to. It detects when my hand is close, and signals whether the pump should be “off” or “on” based on the proximity. The issue I am having is that the pump is not actually turning on or off. I used a voltmeter on Pin 9 to see if there were any changes between when the pin is supposed to be “HIGH” or “LOW”, but my meter does not detect any change.

Is this an issue with my code, my wiring, or both? Any guidance is appreciated.

Thank you for your time.

You write You use 12 Volt AC, That can't be good. Using 12 volt and a PNP transistor will put Your controller ingreat danger if it doesn't burn up.

Use NPN transistor, or better a logic MOSFET connected to the negative side of the motor.

Gotcha, thank you. Is there a specific one you would recommend? Maybe the TIP 120 instead?

The TIP 120 serie is very old, are Darlington transistors loosing 2 volt at least between C and E. The also call one volt higher base voltage. Google for logic MOSFET, look for at least 20 volt and Amps enough for Your pump.

From what I can tell from that Fritzy, you have collector and emitter reversed, post a drawing showing terminal identification. EDIT: Do NOT connect emitter to 12V and base to Arduino pin, you might damage the Arduino.