Back to Parent

#include <Arduino_APDS9960.h>
int relayPin = D2;

void setup() {

  pinMode(relayPin, OUTPUT);
    Serial.begin(9600);
  while (!Serial);

  if (!APDS.begin()) {
    Serial.println("Error initializing APDS-9960 sensor!");
  }
}

void loop() {

  if (APDS.proximityAvailable()) {
    int proximity = APDS.readProximity();
    if (proximity<50){
      digitalWrite(LEDB, HIGH);
      digitalWrite(relayPin, HIGH);
      }
    else if (proximity<150 && proximity>= 50){
      digitalWrite(LEDB, LOW);
      delay(200);
      digitalWrite(LEDB, HIGH);

      digitalWrite(relayPin, LOW);
      delay(200);
      digitalWrite(relayPin, HIGH);
      delay(200);      
    }
    else if (proximity<210 && proximity>= 150){
      digitalWrite(LEDB, LOW);
      delay(600);
      digitalWrite(LEDB, HIGH);
      delay(800);

      digitalWrite(relayPin, LOW);
      delay(399);
      digitalWrite(relayPin, HIGH);
      delay(399);      
    }
    else if (proximity<230 && proximity >= 210){
      digitalWrite(LEDB, LOW);
      delay(800);
      digitalWrite(LEDB, HIGH);
      
      digitalWrite(relayPin, LOW);
      delay(800);
      digitalWrite(relayPin, HIGH);
      delay(800);
    }
    else if (proximity>230){
      digitalWrite(relayPin, LOW);
      digitalWrite(LEDB, LOW);
    }

    Serial.println(proximity);
  }



}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0