Introduction: Getting Started With the Internet Button Using the Particle Photon

IoT is the current trend in electronics with devices raising in the scale of billions of devices, so I decided to create an instructables account dedicated to IoT related technologies and projects. To start of with I am going to show you how to get started with the internet button using the particle photon. The Particle Photon is one of my favorite WiFi enabled micro-controllers, it is easy to use and has an arduino style programming environment and the best part is all the code is uploaded via OTA, so no extra cables and wires needed. I can enclose the photon in a case and upload new code to it as long as it has power and is connected to he internet.

The internet button is a shield for the photon, it provides 11 RGB LEDs, a 3 axis accelerometer, 4 buttons and a buzzer on board (No buzzer if you are using the first version of the internet button). This shield bring cool features to the photon which enables various IoT projects.

I wont jump in right away to IoT, in this instructables I will show you how to get started with the internet button and create a cool looking rainbow pattern using the 11 on board RGB LEDs.

Step 1: Components

Here is what you will need to start of with this project.

The three major components come in the same box if you order the internet button, it also includes the photon so you do not have to make an extra purchase (or you could if you want to build more projects related to the photon).

Step 2: Configuring WiFi

Before we can upload the code or do anything with the photon we need to connect it to the WiFi, the easiest way to this would be via the android application or IOS application. Download the particle photon application from the play store or apple store and install it.

Create a particle account (this account gives access to the web based IDE and keeps all your devices in one place).

After creating and logging in to your account, click the plus icon on the screen to add a new photon, all you need to do after this is power on your photon and follow the on screen instructions.

Next, lets proceed with programming the photon.

Step 3: Blink

There would not be a beginners tutorial if there were no blink program, so there are 11 LEDs to chose from to blink, first lets start with one and then go on blinking all the LEDs.

Copy the below program and paste it in the web based IDE, then select the right photon if you have more than one device and hit flash make sure that your devices is powered on and still connected to the internet.

#include "InternetButton.h"

// Create a Button named b. It will be your friend, and you two will spend lots of time together. // You may be wondering about those two slashes and this gray text- they're called comments, and // don't affect the code. Think of this as the voice of the narrator. InternetButton b = InternetButton();

// The code in setup() runs once when the device is powered on or reset. Used for setting up states, modes, etc void setup() { // Tell b to get everything ready to go // Use b.begin(1); if you have the original SparkButton, which does not have a buzzer or a plastic enclosure // to use, just add a '1' between the parentheses in the code below. b.begin(); }

/* loop(), in contrast to setup(), runs all the time. Over and over again. Remember this particularly if there are things you DON'T want to run a lot. Like Particle.publish() */ void loop() { // Let's turn an LED on. How about #6, which is at the 6 o'clock position? Let's make it blue and bright. b.ledOn(6, 0, 0, 255); // The format here is (LED, red, green, blue), so we're making a color with no red or green, but ALL the blue // You should know that the range of brightness here is 0-255, so 0 is off and 255 is the most possible. // After you use this code, try making the LED white- all the red, green, and blue.

// Since the LED is now on, let's have it stay that way for one second // Delay pauses the code for the amount of time given, in milliseconds- so 1000 millis is one whole second delay(1000);

// And to blink the LED, we'll need to turn it back off and then pause for another second b.ledOff(6); delay(1000);

// Now you're blinking! Play with which LED is blinking (1-11), the delays between, and the color. }

If everything goes fine you should see the photons on board led blink pink indicating that the firmware is being written.

And now try the below code to make all the LEDs blink

#include "InternetButton.h"

/* This InternetButton library has some useful functions. Here we blink ALL the LEDs instead of just one.*/

InternetButton b = InternetButton();

void setup() { // Use b.begin(1); if you have the original SparkButton, which does not have a buzzer or a plastic enclosure // to use, just add a '1' between the parentheses in the code below. // Tell b to get everything ready to go b.begin(); }

void loop(){ b.allLedsOn(0,20,20); delay(1000); b.allLedsOff(); delay(1000);

// Notice that I made them much dimmer, so it's a bit less painful }

Step 4: Rainbow

Now use the RGB property of the LEDs and make it do patterns, rather than just blink a single color. The below code lets you create a rainbow link pattern, which would be really cool to look at.

#include "InternetButton.h"

/* Here's a nice combination of features that I like to use. Note the use of the allButtons function. */

InternetButton b = InternetButton();

bool rainbow_mode = false;

void setup() { // Tell b to get everything ready to go // Use b.begin(1); if you have the original SparkButton, which does not have a buzzer or a plastic enclosure // to use, just add a '1' between the parentheses in the code above. b.begin(); }

void loop(){

// If this calls for a full spectrum situation, let's go rainbow! if(b.allButtonsOn()) { // Publish the event "allbuttons" for other services like IFTTT to use Particle.publish("allbuttons",NULL, 60, PRIVATE); b.rainbow(5); rainbow_mode = true;

// If all buttons are on, don't try to process // the individual button responses below. Just return. return; }

// If we are not in rainbow mode anymore, turn the LEDs off if (rainbow_mode == true) { b.allLedsOff(); rainbow_mode = false; }

// Process individual buttons and LED response if (b.buttonOn(1)) { b.ledOn(12, 255, 0, 0); // Red // Publish the event "button1" for other services like IFTTT to use Particle.publish("button1",NULL, 60, PRIVATE); delay(500); } else { b.ledOn(12, 0, 0, 0); }

if (b.buttonOn(2)) { b.ledOn(3, 0, 255, 0); // Green // Publish the event "button2" for other services like IFTTT to use Particle.publish("button2",NULL, 60, PRIVATE); delay(500); } else { b.ledOn(3, 0, 0, 0); }

if (b.buttonOn(3)) { b.ledOn(6, 0, 0, 255); // Blue // Publish the event "button3" for other services like IFTTT to use Particle.publish("button3",NULL, 60, PRIVATE); delay(500); } else { b.ledOn(6, 0, 0, 0); }

if (b.buttonOn(4)) { b.ledOn(9, 255, 0, 255); // Magenta // Publish the event "button4" for other services like IFTTT to use Particle.publish("button4",NULL, 60, PRIVATE); delay(500); } else { b.ledOn(9, 0, 0, 0); }

if(b.allButtonsOff()) { // Do something here when all buttons are off } }

Comments

author
Swansong made it!(author)2017-06-23

Great clear photos and explanations, thanks for sharing :)

About This Instructable

962views

21favorites

License:

Bio: IoT Related Projects
More by tinkerproject:Raspberry Pi - Plex Media Server Arduino - Relays (Control AC Appliances)Getting Started With the Internet Button Using the Particle Photon
Add instructable to: