#include <Arduino_APDS9960.h>
int relayPin = D2;
int s = 0;
void setup() {
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
while (!Serial);
if (!APDS.begin()) {
Serial.println("Error initializing APDS-9960 sensor!");
}
}
void loop() {
int proximity = APDS.readProximity();
while (s <= 1500) {
//Serial.println("true"); // Switch Relay On (NO)
digitalWrite( relayPin, LOW );
if (APDS.proximityAvailable()) {
proximity = APDS.readProximity();
//Serial.println(proximity); // print value to the Serial Monitor
}
while (proximity >= 240) {
//Serial.println("false");// Switch Relay Off (NC)
Serial.println(proximity);
digitalWrite( relayPin, HIGH );
delay (250);
//Serial.println("true"); // Switch Relay On (NO)
digitalWrite( relayPin, LOW );
delay (250);
if (APDS.proximityAvailable()) {
proximity = APDS.readProximity();
}
}
delay(1000);
s = s+1;
}
Serial.println("false"); // Switch Relay Off (NC)
digitalWrite( relayPin, HIGH );
delay (300000);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .