49713 Designing for the Internet of Things
· 18 members
A hands-on introductory course exploring the Internet of Things and connected product experiences.
This integration enchants a bedside lamp to give a weather update when prompted.
Problem Statement:
The device is for my mom. I picked her because she spent most of her life caring for me and I wanted to build her something. She's a recent retiree who can finally indulge her night owl habits now that she doesn't have to report to a job every day. She loves to spend her evenings relaxing late into the night while reading, listening to the radio, keeping tabs on my dad, and tracking the weather.
Process:
I developed the prototype systemically, using the techniques we learned in class.
1. I sketched out in plain language what I wanted to accomplish with the solution.
2. I researched on adaFruit to find the right components and examples of code.
3. I explored the IoT station and selected a number of options for the sensor and the light.
4. I wired each of the components and coded them separately to make sure that they worked.
5. I built a webhook that would "GET" the temperature for my mother's zip code when called.
6. I integrated the components and their code a step at a time. This is the point at which I entered what I call, the "washing machine".
Despite days of googling and trying different code to effectively use the webhook, the microphone, and the neopixels, they would not work together. Layering a webhook on top of them stretched my meager coding skills to their limit.
Process (continued):
7. After many iterations that failed to work, I share my vision with Daragh and Taylor. As I stepped them through my approach, they were able to help me put the neopixel code where it belonged, create variables to store the sound and temperature data, and revised the webhook to work correctly by inserting the API code into the address.
Reflections:
In the end, the light was successfully triggered to turn on when activated by sound. It turned red or blue depending on the temperature of the town it pointed to. I learned that my approach was right and that with more experience I will need less help getting the code aligned properly. I am proud that I was able to deliver a prototype to my mom that met her expectations 100%.
o// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_COUNT 16
#define PIXEL_PIN D2
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
/****************************************
Example Sound Level Sketch for the
Adafruit Microphone Amplifier
****************************************/
int loudNoise = 1;
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
double temperature = 0;
void setup()
{
Serial.begin(9600);
strip.begin();
strip.show();
Particle.publish( "weather" );
Particle.subscribe("hook-response/weather", myHandler, MY_DEVICES);
}
void myHandler(const char *event, const char *data) {
// Handle the integration response
temperature = (double)(String( data ).toFloat());
}
void loop()
{
unsigned long startMillis= millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 4095;
// collect data for 50 mS
while (millis() - startMillis < sampleWindow)
{
sample = analogRead(0);
if (sample < 4095) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // save just the max levels
}
else if (sample < signalMin)
{
signalMin = sample; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
double volts = (peakToPeak * 5.0) / 4095; // convert to volts
if( volts > 0.07 ){
if( loudNoise < 1 ){
Particle.publish( "weather" );
}
loudNoise = 100;
}
if( loudNoise > 0){
//int color = map( loudNoise, 0, 100, 0, 255);
int t = (int)(temperature * 100);
int color = map( loudNoise, 0, 10000, 0, 255);
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
for(int i = 0 ; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, strip.Color(t,0,255-t)); // Blue.
}
strip.show(); // This sends the updated pixel color to the hardware.
loudNoise = loudNoise - 1;
}else{
for(int i = 0 ; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, strip.Color(0,0,0)); // Red.
}
strip.show(); // This sends the updated pixel color to the hardware.
}
delay( 50 );
// //code to turn on the light
// if (volts > .03)
// {
// // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
// strip.setPixelColor(0, strip.Color(0,0,255)); // Blue.
// strip.show(); // This sends the updated pixel color to the hardware.
// }
// else
// {
// strip.setPixelColor(0, strip.Color(255,0,0)); // Red.
// strip.show(); // This sends the updated pixel color to the hardware.
// }
Serial.println(loudNoise);
Serial.println(volts);
}
Click to Expand
References:
GitHub tutorial for NeoPixels:
https://github.com/technobly/Particle-NeoPixel
AdaFruit's tutorial for microphones
https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/measuring-sound-levels
A hands-on introductory course exploring the Internet of Things and connected product experiences.
This integration enchants a bedside lamp to give a weather update when prompted.
January 29th, 2019