Simple way to integrate Twitter to your projects using Photon and IFTTT

The folks at Particle (erstwhile Spark) are awesome – they make great IoT products and are really super nice people. They gifted Omkar a Photon at the MakerFaire. His summer break just started and this was his priority #1.

Omkar wanted a way to know when someone mentions or follows @IoT4Kids. Particle makes this incredibly easy to do with just a few lines of code. You essentially can make any action happen (light up or move something and/or make some noise) based on Twitter activity using their Arduino compatible WiFi integrated micro-controller and their integration with IFTTT.

This simple example lights up an LED.

BTW, the display box is 3D printed using Printrbot Simple which is another awesome product for kids to get started with 3D printing.

This is all made so easy with the Particle Spark.Function() that is triggered ‘automagically’ 🙂 from IFTTT. All you need is the code below and create a recipe with Twitter trigger and Particle action.


int ledpin = D7;
void setup()
{
// register the cloud function
Spark.function("tweet", twittermessage);
pinMode(ledpin, OUTPUT);

}

void loop()
{
delay(5000);
digitalWrite(ledpin, LOW);
delay(5000);
}

// this function automagically gets called upon a tweet mention
int twittermessage(String ignore)
{
digitalWrite(ledpin, HIGH);
return(0);
}

Here is a more fun example of this by Brian Sherwin. He also has an example of making this with your own node.js application to make the action trigger immediately instead of the 15 min cycle on IFTTT.

So folks, if you liked this please follow or mention @IoT4Kids and light up Omkar’s day. :).

Neopixel Christmas Lights dancing to music with MSGEQ7 Spectrum Shield

Make your holiday lights dance to music!

NeopixelChristmasLightsThis uses a 300 LED Adafruit Neopixel strip driven by Sparkfun Spectrum Shield (make sure you buy the stackable headers with this) and Arduino Uno. The connections are fairly simple as shown in this pic. Apart from the ground and 5v you just need to connect one data pin to the Neopixel strip to control it (refer to Adafruit Neopixel Guide). There are two standard 1/8″ audio jacks on the Shield that you can connect input audio and pass through the other to your speaker.

The code was adapted from http://michaelteeuw.nl/post/84599343577/micro-disco. (Thanks Michael!).



#include <Adafruit_NeoPixel.h> // include the Adfruit Neopixel library
 
#define PIN_NEOPIXELS 8 // connect Neopixel strip to this pin
#define PIN_STROBE 4 // spectrum shield strobe pin
#define PIN_RESET 5 // spectrum shield reset pin
#define PIN_SOUND 1 //analog input pin spectrum shield - using only one/right channel
#define NUMLEDS 300 // LEDs in Neopixel strip
 
#define MINPOWER 128 // minimum amplitude value to be considered
#define MAXPOWER 1023 // max amplitude value
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLEDS, PIN_NEOPIXELS, NEO_GRB + NEO_KHZ800);
 
int soundvalue[7]; //band array to store amplitutde value for each band
 
void setup() 
{
 strip.begin(); //initialize neopixels
 strip.setBrightness(35);
 strip.show();
 //initialize spectrum shield graphic equalizer
 pinMode(PIN_RESET, OUTPUT); // reset
 pinMode(PIN_STROBE, OUTPUT); // strobe
 digitalWrite(PIN_RESET,LOW); // reset low
 digitalWrite(PIN_STROBE,HIGH); //pin 5 is RESET on the shield
}
 
void loop() {

 readMSGEQ7();
 int bColor = colorValue((soundvalue[0]+soundvalue[1])/2);
 int gColor = colorValue((soundvalue[2]+soundvalue[3]+soundvalue[4])/3);
 int rColor = colorValue((soundvalue[5]+soundvalue[6])/2);
 byte red = rColor; //convert to 0-255 byte value for Neopixel
 byte blue = bColor;
 byte green = gColor;
 
 for (int i = 0; i < NUMLEDS; i=i++) //show strip
 {
 if(i<=240) {strip.setPixelColor(i, (i<=rColor) ? red : 0,(i<=gColor) ? green : 0,(i<=bColor) ? blue : 0);}
 else {strip.setPixelColor(i, (i<=rColor) ? 255 : 0,(i<=gColor) ? 255 : 0,(i<=bColor) ? 255 : 0);} 
 } //you might have to play with this based on your setup. The if statement is to make the top LEDs show brighter
 strip.show();
 delay(5);
}
 
int colorValue(int powerValue) // calculate a a RGB color value from the sound bands
{
 return map(powerValue, MINPOWER, MAXPOWER, 0, NUMLEDS);
}
 
// Read the Analog sound data from 7 bands
void readMSGEQ7()
{
 digitalWrite(PIN_RESET, HIGH); //reset the data
 digitalWrite(PIN_RESET, LOW);
 for(int band=0; band < 7; band++) { //loop thru all 7 bands
 digitalWrite(PIN_STROBE,LOW); // go to the next band 
 delayMicroseconds(10); //gather some data
 soundvalue[band] = analogRead(PIN_SOUND); // store left band reading
 digitalWrite(PIN_STROBE,HIGH); // reset the strobe pin
 }
}

Interactive Neopixel Lamp (INL). LED Neopixel + Arduino Uno + Ultrasonic Ping Sensor

An interactive lamp that changes speed based on distance of objects in front of it. This uses the Arduino UNO a 60 LED Adafruit NeoPixel strip and an Ultrasonic Ping Sensor.

This also introduces the concept of functions in programming. The circuit is fairly straight forward as Om has tried to illustrate in this diagram! 🙂

Neopixel INL

Refer to Adafruit’s Neopixel Überguide and the Arduino Ping Sensor examples for detailed how to’s. (Note the ping sensor we used has a two separate pins for input and output rather than just one shown in the Arduino example.).

Here is the code.

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, 2);

int delaytime=30;
const int pingPin = 7;
const int echoPin = 8;

void setup() {
 strip.begin();
 strip.show();
 pinMode(pingPin, OUTPUT);
 pinMode(echoPin, INPUT);
}

void loop() {

 delaytime=pingyity();
 for(int i=0; i<60; i++){
 strip.setPixelColor(i, 255, 0, 0);
 strip.show();
 delay(delaytime);}

 delaytime=pingyity();
 for(int i=0; i<60; i++){
 strip.setPixelColor(i, 255, 255, 0);
 strip.show();
 delay(delaytime);}

 delaytime=pingyity();
 for(int i=0; i<60; i++){
 strip.setPixelColor(i, 0, 255, 255);
 strip.show();
 delay(delaytime);}

 delaytime=pingyity();
 for(int i=0; i<60; i++){
 strip.setPixelColor(i, 0, 255, 0);
 strip.show();
 delay(delaytime);}

 delaytime=pingyity();
 for(int i=0; i<60; i++){
 strip.setPixelColor(i, 0, 0, 255);
 strip.show();
 delay(delaytime);}

 delaytime=pingyity();
 for(int i=0; i<60; i++){
 strip.setPixelColor(i, 255, 0, 255);
 strip.show();
 delay(delaytime);
 }
}

int pingyity()
{
 //Send ping signal out
 long duration, inches;
 digitalWrite(pingPin, LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin, LOW);

 //read ping sensor signal input
 duration = pulseIn(echoPin, HIGH);
 // convert the time into a distance
 inches = duration / 74 / 2;

 //set light delay time based on sensor
 if(inches<=30) return(inches);
 else return(30);
}

Adafruit Neopixel LED strip on Spark Core Arduino

Getting start on the Adafruit Neopixel on the Spark Core. This shows a WS2812B 60 LED strip from Adafruit and uses the Neopixel port on Spark Core to run it.

It is quite easy to code thanks to the Adafruit library and a good way to get kids introduced to the for loop.

#include "neopixel/neopixel.h"
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, D2, WS2812B);

void setup() {
    strip.begin();
    strip.show();}

void loop() {
    for(int i=0; i<60; i++){
    strip.setPixelColor(i, 255, 0, 0);
    strip.show();
    delay(5);
    }
    for(int i=0; i<60; i++){
    strip.setPixelColor(i, 255, 255, 0);
    strip.show();
    delay(5);
    }
    for(int i=0; i<60; i++){
    strip.setPixelColor(i, 0, 255, 255);
    strip.show();
    delay(5);
    }
    for(int i=0; i<60; i++){
    strip.setPixelColor(i, 0, 255, 0);
    strip.show();
    delay(5);
    }
    for(int i=0; i<60; i++){
    strip.setPixelColor(i, 0, 0, 255);
    strip.show();
    delay(5);
    }
    for(int i=0; i<60; i++){
    strip.setPixelColor(i, 255, 0, 255);
    strip.show();
    delay(5);
    }
}

Arduino project for Mother’s day

This project uses a LED 8×8 dot matrix for the display, a piezoelectric buzzer for the music and a photo-resistor to play it when you open the box.

I’ve used these examples to put this together:

More details on how to will follow later.