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);
Serial.begin(9600);
// Initialize Serial port
Serial.begin(9600);
Serial.println();
Serial.println(F("---------------------------------------"));
Serial.println(F("SparkFun APDS-9960 - Proximity Pump"));
Serial.println(F("---------------------------------------"));
APDS.begin();
}
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
Serial.println(proximityValue);
// 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
Serial.println("on");
}
else {
// if the current state is LOW then the pump stays off
(pumpControl == LOW);
Serial.println("off");
}
}
// wait a bit before reading again
delay(200);
}
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.
