A simple internet appliance

Made by Bennett Goeke

Created: October 31st, 2023

0

Intention

First Sketch

0

Exercise #1

Modify the program to Blink on and off every 3 seconds

https://youtu.be/Fvu5Uzgurug

0
int led1 = D2;

void setup() {
    
    pinMode(led1, OUTPUT);

}

void loop() {
    
    digitalWrite(led1, HIGH);
    
    delay(3000);
    
    digitalWrite(led1, LOW);
    
    delay(3000);

}
Click to Expand
0

Exercise #2

Change the program to blink on and off 5 times then stop for 3 seconds. Each blink should be 0.5s

https://youtube.com/shorts/VJ9PyxXeIFI

0
int led1 = D2;

void setup() {
    
    pinMode(led1, OUTPUT);

}

void loop() {
    
    for (int b = 0; b < 5; b++) {
        digitalWrite(led1, HIGH);
        delay(500);
        digitalWrite(led1, LOW);
        delay(500);
        
    }
    
    delay(3000);

}
Click to Expand
0

Exercise #3

Add a second LED to the circuit. 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

https://youtube.com/shorts/2XBQcB7MKBc

0
int led1 = D2;
int led2 = D3;

void setup() {
    
    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);

}

void loop() {
    
    digitalWrite(led1, HIGH);
    
    delay(3000);
    
    digitalWrite(led1, LOW);
    
    //delay(3000);
    
    digitalWrite(led2, HIGH);
    
    delay(3000);
    
    digitalWrite(led2, LOW);
    
    //delay(3000);

}
Click to Expand
0

Connected LED

Exercise #1

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

https://youtu.be/P7HK83dqlVM

0
int led1 = D2;

void setup() {
    
    pinMode(led1, OUTPUT);
    digitalWrite(led1, LOW);
    Particle.function("led", ledControl);

}

void loop() {
    //nothing here
    

}

int ledControl(String command){
    int state = LOW;
    if(command == "ON"){
        for (int b = 0; b<3; b++){
            digitalWrite(led1, HIGH);
            delay(500);
            digitalWrite(led1,LOW);
            delay(500);
        }
    } else {
        return -1;
    }
    
    digitalWrite(led1, state);
    return 1;
}
Click to Expand
0

Exercise #2

Pass the number of times user 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

https://youtu.be/voj6k34X_YQ

0
int led1 = D2;

void setup() {
    
    pinMode(led1, OUTPUT);
    digitalWrite(led1, LOW);
    Particle.function("led", ledControl);

}

void loop() {
    //nothing here
    

}

int ledControl(String command){
    int number = atoi(command);
    if (number != 0){
        for(int b=0; b<number; b++){
            digitalWrite(led1, HIGH);
            delay(500);
            digitalWrite(led1, LOW);
            delay(500);
        }
        return 1;
    }else{
        return -1;
    }
}
Click to Expand
0

Exercise #3

Add a second LED to the circuit.

Change the program and cloud function to allow you to control both LEDs remotely

https://youtu.be/jz31qzILWFY

0
int led1 = D2;
int led2 = D3;

void setup() {
    
    pinMode(led1, OUTPUT);
    digitalWrite(led1, LOW);
    pinMode(led2, OUTPUT);
    digitalWrite(led2, LOW);
    Particle.function("led", ledControl);

}

void loop() {
    //nothing here
    

}

int ledControl(String command){
    int state1 = LOW;
    int state2 = LOW;
    if(command == "LED1"){
        state1 = HIGH;
    } else if(command == "LED2"){
        state2 = HIGH;
    } else {
        return -1;
    }
    
    digitalWrite(led1, state1);
    digitalWrite(led2, state2);
    
    return 1;
}
Click to Expand
0

Process

In reaching the intended goal, I faced several challenges and proceeded through a sequence of actions. Initially, I encountered difficulty due to my lack of familiarity with Particle syntax. To overcome this, I looked into the Lab Docs, specifically searching for information on the "for loop."

While testing the initial code version, which aimed to make the LED blink three times before turning on/off, I encountered an issue where the LED only blinked once. Upon investigation, I realized that I had overlooked including a delay(500) function at the end of the for loop. This absence led the LED to flash so quickly that it escaped human perception.

Moreover, I tackled various parts of the exercise by following the instructions outlined on the DIoT website. I made adjustments to the details and order of the sample code components to observe potential different outcomes. Beyond the guide's instructions, I dedicated more time to practice circuit connection and arrangement, meticulously checking the code for syntax errors, particularly focusing on parentheses and spaces, and engaging with programming syntax files for better comprehension.

0

Reflection

Reflect on the process of making this project. What did you learn? What would you do differently?

An ongoing challenge I faced was making sure I had set up the circuit correctly. I had found that often times it wasn't working simply because I had a mistake in my wiring where I put the connecting wire in the wrong slot to line up with the LED.

Another lesson learned is the importance of saving multiple versions of the code for future reference when working on new exercises.

I've found the "verify" tool in the online IDE to be extremely useful. Given my familiarity with Python, I tend to forget to include semicolons at the end of each line, and the "verify" feature consistently saves me time by catching these omissions.

x
Share this Project

Courses

48-675 Designing for the Internet of Things 24

· 11 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

~