Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <SharpIR.h>
#include <math.h>


//Deep Dive for Trashcan 1

//People counter -> IR Distance sensor
const int IR = A5;
float value = 0.0;
bool seeingPerson = false;

long lastCount = millis();

int passCount = 0;


//Person maintenance request -> button
int button = D4;
int buttonCount = 0;
long lastPress = millis();

//Trash maintenance request -> ir sensor for trash can
const int trashDown = A3; // IR distance apart sensor
const int trashSide = D8; // IR pull apart sensor
const int trashLED = D6; //LED on box
bool trashType = true;
int currBeamState = 0;
int beamOn = 0;

//Animal Repellent -> piezo (aka speaker)
int speaker = D2;

void setup() {
    //counter
    pinMode(IR, INPUT);
    
    //button
    pinMode(button, INPUT);

    //trashcan sensor
    pinMode(trashDown, INPUT_PULLUP);
    pinMode(trashSide, INPUT_PULLUP);
    pinMode(trashType, INPUT);
    pinMode(trashLED, OUTPUT);
    
    
    //sound
    pinMode(speaker, OUTPUT);
    tone(speaker, 3500, 0);
}

void loop() {
    //button
    if (digitalRead(button)){
        Particle.publishVitals();
        Particle.publish("button", "p", PUBLIC);
        if (millis() - lastPress > 60){
            lastPress = millis();
            buttonCount++;
            if (buttonCount > 10){
                //send email using IFTTT
                Particle.publish("button_pressed", "pressed", PUBLIC);
                buttonCount = 0;
            }
        }
    }
    
    //trashcan sensor for trashSide
    if (trashType){
        currBeamState = digitalRead(trashSide);
        if(!currBeamState && !beamOn) {
            digitalWrite(trashLED, HIGH);
            beamOn = currBeamState;
            Particle.publish("trashFull", "trash1", PUBLIC);
        }
        else{
            beamOn = false;
            digitalWrite(trashLED, LOW);
            Particle.publish("trashEmpty", "trash1", PUBLIC);
        }
    }
    
    //trashcan sensor for trashDown USES IR SENSOR
    if (!trashType){
        float volts = float(analogRead(IR))*0.0048828125;  
        int distance = 13 * pow(volts, -1); 
        value = (value * 0.7) + (distance * 0.3);
        //HAVE TO CHANGE VAL w/ FURTHER TESTING
        if (value <= 2){
            Particle.publish("trashFull", "trash1", PUBLIC);
            //Serial.println(int(value));  
        }
        else{
            Particle.publish("trashEmpty", "trash1", PUBLIC);
        }
    }
    
        //counter (will paste in based on final model. idk what to look for yet)
    
    //USES IR SENSOR
    float volts = float(analogRead(IR))*0.0048828125;  
    int distance = 13 * pow(volts, -1); 
    value = (value * 0.7) + (distance * 0.3);
    if (value <= 2){
        if(!seeingPerson && (millis() - lastCount > 2000)){
            lastCount = millis();
            if (passCount < 50) {
                passCount++;
                Particle.publish("counter", "1", PUBLIC);
            }
            if (passCount > 50 && passCount < 100){
                passCount++;
                Particle.publish("counter", "2", PUBLIC);
            }
            else{
                Particle.publish("counter", "3", PUBLIC);
                passCount = 0;
            }
            //Serial.println(int(passCount));
            seeingPerson = true;
        }
        //Serial.println(int(value));  
    }
    
    else{
        seeingPerson = false;
    }

    
}
Click to Expand

Content Rating

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

0