BusAlert

Made by qichengy

Found in DioT 2019: Augmented Objects

BusAlert is an IoT device that will tell you how far away your bus is by signaling different lights

0

Intention

My roommates and I both commute to school by bus every day especially in winter. When we missed a bus, we got frustrated because we would need to wait for the next one or walk to school. Normally I use the app Transit to check the real-time bus schedule, but my eyes need to fixate on the screen the whole time when I  am eating breakfast and getting ready for school. Therefore, I wanted to create a light IoT device to help me plan my morning more smoothly. 

0

Goal

My IoT device, BusAlert, has one knock sensor and 3 LED with different colors. Once the sensor is triggered, the light will lit up according to the estimated arrival time of a certain bus - in my case, it's the number 54 bus. For example, if the bus is more than 10 minutes away, the Green LED will light up; if less than 10 minutes but more than 5, the Blue will light up; if less than 5 minutes but more than 3 minutes, the Red; if less than 3 minutes, the Red will blink. 

0

Process

1. Brainstorm

2. Build a Simple LED Circut

3. Test the Knock Sensor 

4. Create for Port Authority Webhook

5. Embed Code

6. Test Retrieved Data with Publish Variable

7. Connect Sensor 

0
int ledPinRed = D3;
int ledPinGreen = D4;
int ledPinYellow = D2;
int knockSensor = A0;
bool state = false;

int timeToBus = 0;


void setup() {
    //initial state of all 3 pins

    pinMode(ledPinRed, OUTPUT);
    digitalWrite(ledPinRed, LOW);
    
    pinMode(ledPinGreen, OUTPUT);
    digitalWrite(ledPinGreen, LOW);
    
    pinMode(ledPinYellow, OUTPUT);
    digitalWrite(ledPinYellow, LOW);
    
    //Port Authority webhook

    Particle.subscribe("hook-response/bustime", myBusTimeHandler, MY_DEVICES);
    
    //view variable value in console

    Particle.variable("timeToBus", timeToBus);
}

void loop() {
    //read sensor

    int sensorReading = analogRead(knockSensor);
  
    //change state when sensor is pressed

    if (sensorReading > 100){
        state = !state;
    }
    
    //if sensor is pressed, lights respond to the bus time

     if( state == true )
     {
            Particle.publish( "bustime" );
            delay( 1000 );
            if(timeToBus > 10) 
            {
                digitalWrite(ledPinGreen, HIGH);
                digitalWrite(ledPinRed, LOW);
                digitalWrite(ledPinYellow, LOW);
            }
            else if(timeToBus <= 10 && timeToBus > 5) 
            {
                digitalWrite(ledPinYellow, HIGH);
                digitalWrite(ledPinRed, LOW);
                digitalWrite(ledPinGreen, LOW);
            } 
            else if(timeToBus <= 5 && timeToBus > 3) 
            {
                digitalWrite(ledPinRed, HIGH);
                digitalWrite(ledPinYellow, LOW);
                digitalWrite(ledPinGreen, LOW);
            } 
            else if(timeToBus <= 3) 
            {
                digitalWrite(ledPinRed, HIGH);
                delay(100);
                digitalWrite(ledPinRed, LOW);
                delay(100);
            }
     }
    else //if sensor is pressed again, state changes to false, lights turn off

    {
        digitalWrite(ledPinYellow, LOW);
        digitalWrite(ledPinRed, LOW);
        digitalWrite(ledPinGreen, LOW);
    }
     
}


//method for Port Authority webhook

void myBusTimeHandler(const char *event, const char *data) {
    
    // Handle the integration respo

    String busPrediction = String( data );
    
    if( busPrediction.equals( "DUE" ) ){
        timeToBus = 0;
    }else{
        timeToBus = busPrediction.toInt();
    }
}
Click to Expand
0

Outcome

0
0

Next Steps

What would you do if you took this project forward and why? 

0

Feedback

Reflect on the challenges you encountered and the process as a whole. Did you get where you wanted to? If so, great. If not, why not? What do you need to get there, etc?

x
Share this Project

Courses

49713 Designing for the Internet of Things

· 18 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

BusAlert is an IoT device that will tell you how far away your bus is by signaling different lights

Created

January 31st, 2019