Skill Dev I: A Simple Internet Appliance

Made by kharsono

Objective: Get familiar with Particle & LED Connections

Created: October 28th, 2021

0

Outcome

The Particle & LED integration project portrayed how Particle can be used to remotely control different experiments on LED: Blinking, Multiple LED Testing & Use of Functions.

0

Process 

Process is divided into two major parts with three exercises each to exemplify a more advanced feature/functionality. These experiments are shown below:

0

Making an LED Blink

Exercise 1: Modify the program to Blink on and off every 3 seconds.

0
0

Exercise 2: Change the program to blink on and off 5 times then stop for 3 seconds. Each blink should be 0.5s (a half second)

0
0

Exercise 3: Program the LED’s to alternate blinks i.e. when LED 1 turns on, LED 2 turns off, then when LED 2 turns on, LED 1 turns off.

0
0
// Making an LED Blink

void setup() {
    
    pinMode(D2, OUTPUT);
    pinMode(D3, OUTPUT);
    
    digitalWrite(D2, LOW);
    digitalWrite(D3, HIGH);
    
}

void loop() {

    // // Excercise 1: On & off every 3 secs
    // digitalWrite(D2, HIGH);
    // delay(3000);
    // digitalWrite(D2, LOW);
    // delay(3000);
    
    // // Excercise 2: Blinking & stop
    // for (int i=0; i<5; i++) {
    //     digitalWrite(D2, HIGH);
    //     delay(500);
    //     digitalWrite(D2, LOW);
    //     delay(500);
    // }
    // delay(2500);
    
    // Excercise 3: On & off every 3 secs for 2 LEDs
    digitalWrite(D2, HIGH);
    digitalWrite(D3, LOW);
    delay(3000);
    digitalWrite(D2, LOW);
    digitalWrite(D3, HIGH);
    delay(3000);
}
Click to Expand
0

Making a Connected LED

Exercise 1: Modify the cloud function to blink the LED 3 times after it is called

0
0

Exercise 2: Instead of passing a HIGH Or LOW string pass the number of times you would like it to blink. Set the function to blink that number of times. Finally once it has completed all of the blinking it should turn the LED off

0
0

Exercise 3: Go back to the original program. Now add a second LED to the circuit. Change the program and cloud function to allow you to control both LEDs remotely

0
0
int ledPin = D2;
int ledPin2 = D3;
void setup()
{
    pinMode(ledPin, OUTPUT);
    pinMode(ledPin2, OUTPUT);
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2, LOW);
    Particle.function("led3x", ledControl);
    // Particle.function("ledUser", ledTimes);  
    Particle.function("led3x2", ledControl2);
}

void loop()
{
   // Nothing
}

// Ex 1 & 3: Blink LED 3 times
int ledControl(String command)
{
    int state = LOW;
    if(command == "HIGH") {
        for(int i = 0; i < 3; i++){
            digitalWrite(ledPin, HIGH);
            delay(300);
            digitalWrite(ledPin, LOW);
            delay(300);
        }
    }
    else if(command == "LOW") { 
       state = LOW;
    }
    else {
       return -1;
    }
    // write to the appropriate pin
    digitalWrite(ledPin, state);
    return 1;
}

// // Ex 2: Blink LED USer input
// int ledTimes(String command)
// {
//     int num = command.toInt();
//     for(int i = 0; i < num; i++){
//       digitalWrite(ledPin, HIGH);
//       delay(300);
//       digitalWrite(ledPin, LOW);
//       delay(300);
//     }
    
//     return 1;
// }

// Ex 3: Blink 2nd LED 3 times
int ledControl2(String command)
{
    int state = LOW;
    if(command == "HIGH") {
        for(int i = 0; i < 3; i++){
            digitalWrite(ledPin2, HIGH);
            delay(300);
            digitalWrite(ledPin2, LOW);
            delay(300);
        }
    }
    else if(command == "LOW") { 
       state = LOW;
    }
    else {
       return -1;
    }
    // write to the appropriate pin
    digitalWrite(ledPin2, state);
    return 1;
}
Click to Expand
0

Final Electric Circuit Setup

Shown Below

0

Reflection

o Following the tutorial is immensely helpful in learning how Particle works, and especially to get everything set up and code implemented on the circuit.

o Connecting Particle, and writing the code is documented beautifully in the documentation.

o It was a little challenging to understand the Particle.function as apparently only integers can be sent back as the ‘return_value’ variable, preventing fun messages to be exported like “Complete!”.

Finally, it was really fun to use the command line to access the functions. Finding the access token was a little challenging to jump into several other webpages.

o Aside from the return_value variable lesson, the command can only be in the String format, and not able to be changed at all.

o Implementation on the code can be much faster when understanding C/C++ better.

o Particle signal can be disrupted, especially in Exercise 3 of Making a Connected LED. When one LED is blinking, a signal to turn on the second LED will cut out the first LED, causing the first LED to wait for the second LED to finish blinking before it can complete its full blinking cycle.


Next Steps

o Testing out timing of the LED blinks to prevent disruption would need more exploration.


x
Share this Project

Courses

Focused on
About

Objective: Get familiar with Particle & LED Connections