49713 Designing for the Internet of Things
· 18 members
A hands-on introductory course exploring the Internet of Things and connected product experiences.
Bus Tracker Lamp is an IoT device that tells user how far the bus is, so user can plan when to leave home accordingly.
My roommate came from Shenzhen, a city located in the Southern part of China that is normally warm throughout the year. He was used to the good weather and could not get along with Pittsburgh's cold and gloomy days, becoming reluctant walking outside during the winter. Our apartment is quite far from the bus station, so every morning he has to plan his walk early so that he won't miss the bus and, at the same time, he can catch the bus at the perfect timing without waiting for the bus in the coldness for too long. Because my roommate has a constantly changing schedule (class doesn't start at the same time everyday, sometimes he has to leave early for a meeting, etc.), he has to pull out his phone every morning when he thinks it may be the good timing to leave and check whether the bus is coming, but he feels reluctant to do so.
IoT device is rather simple: it is connected to one photoresistor, as the switch to turn the device on, and one RGB LED light. My roommate often keeps the curtain in his room closed throughout the day. When he sleeps at night, the room is dark. When he wakes up and turn on the light, the device will turn on, check the estimated arrival time of 71D bus route. When he leaves and turn off light, the device would also turn off.
1. Interview
2. Problem and pain point identification
3. Brainstorming
4. Connect the photoresistor and one LED light
5. Test code
6. Unplug the LED light and connect the RGB LED light
7. Get API key from Port Authority and create Webhook integration on Particle Console
8. Use Neopixel library for Particle, adjust and test code
When the bus is more than 10 mins away, the RGB LED would light up in green, denoting that time is sufficient; when the bus is less than 10 mins but more than 5 mins away, the light would glow in yellow, letting the user know that he or she should get ready and leave; when it is less than 5 mins, the light would blink in red, meaning that he would not be able to catch the bus (our apartment is 5 mins walk away from the bus stop).
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
int photoCell = A0;
bool state = false;
int redValue = 255;
int greenValue = 255;
int blueValue = 255;
#define PIXEL_COUNT 1
#define PIXEL_PIN D6
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int timeToBus = 0;
const char *printData = 0;
int photoCellReading = 0;
int ledBrightness = 0;
void setup() {
strip.begin();
Particle.subscribe("hook-response/BusTime", myHandler, MY_DEVICES);
Particle.variable("timeToBus", timeToBus);
Particle.variable("light", &photoCellReading, INT);
}
void loop() {
int photoCellReading = analogRead(photoCell);
ledBrightness = map(photoCellReading, 0, 4095, 0, 255);
if (ledBrightness > 20){
state = true;
}
else {
state = false;
setRGBColor( 0,0,0);
}
if( state == true )
{
Particle.publish( "BusTime" );
delay( 5000 );
if(timeToBus > 10)
{
setRGBColor( 0,100,0 );
}
else if(timeToBus <= 10 && timeToBus > 5)
{
setRGBColor( 100,100,0 );
}
else if(timeToBus <= 5)
{
setRGBColor( 100,0,0 );
delay(300);
setRGBColor( 0,0,0 );
delay(300);
setRGBColor( 100,0,0 );
}
}
}
void setRGBColor( int r, int g, int b ){
redValue = r;
greenValue = g;
blueValue = b;
strip.setPixelColor(0, redValue, greenValue, blueValue);
strip.show();
}
void myHandler(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
A hands-on introductory course exploring the Internet of Things and connected product experiences.
Bus Tracker Lamp is an IoT device that tells user how far the bus is, so user can plan when to leave home accordingly.
January 31st, 2019