LED Blink

Made by Yi Sun

Created: December 9th, 2022

0

Intention&Outcome

In this lab, we built circuit for LED and programed to let LED blink in different ways. We also connected it with cloud to control LED remotely.

Exercise 1.1: the LED can blink and off every 3 seconds.

Exercise 1.2: the LED blink on and off 5 times then stop for 3 seconds. Each blink is 0.5s.

Exercise 1.3: Two LEDs alternatively blinks.

Exercise 2.1: call the cloud function to trigger the LED blink 3 times.

Exercise 2.2: pass the number of times to blink remotely and control the LED to blink that number of times

Exercise 2.3: control two LEDs separately and can let them blink a different number of times.

0

Process

I didn't meet too many problems this time. There was one time that the LED didn't respond after flashing the code. It was because I wrongly passed the led pin.

0

Reflection & Next Steps

In this project, I got familiar with LED and Arduino, I also learned how to build simple circuit and how to control LED through cloud functions. 

In the future, I can build more complex circuit and use cloud functions to implement more fancy functions.

0
// 1.1 Modify the program to Blink on and off every 3 seconds.

int ledPin = D3;

void setup() {
  // We want to tell the Argon that we'll use
  // D3 as an output pin.
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // First... On
  digitalWrite(ledPin, HIGH);   // Turn ON the LED pins
  delay(3000);               

  // Now... Off
  digitalWrite(ledPin, LOW);   // Turn OFF the LED pins
  delay(3000);               
  // rinse + repeat

}
Click to Expand
0
// 1.2 Change the program to blink on and off 5 times then stop for 3 seconds. Each blink should be 0.5s
int ledPin = D3;

void setup() {
  // We want to tell the Argon that we'll use
  // D3 as an output pin.
  pinMode(ledPin, OUTPUT);
}

void loop() {
    for (int i=0; i<5; i++) {
        digitalWrite(ledPin, HIGH);   // Turn ON the LED pins
        delay(500);               

        // Now... Off
        digitalWrite(ledPin, LOW);   // Turn OFF the LED pins
        delay(500);   
                
    }
    delay(3000);
}
Click to Expand
0
// 2.1 Modify the cloud function to blink the LED 3 times after it is called
int ledPin = D3;

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

   digitalWrite(ledPin, LOW);
   
   Particle.function("led", ledControl);
}

void loop() {

}

int ledControl(String command)
{
   for (int i=1; i<=3; i++) {
        digitalWrite(ledPin, HIGH);   
        delay(500);               

        digitalWrite(ledPin, LOW);   
        delay(500);  
   }

   return 1;
}
Click to Expand
0
// 2.2 
int ledPin = D3;

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

   digitalWrite(ledPin, LOW);
   
   Particle.function("led", ledControl);
}

void loop() {

}

int ledControl(String command)
{
    int times = command.toInt();
   for (int i=1; i<=times; i++) {
        digitalWrite(ledPin, HIGH);   
        delay(500);               

        digitalWrite(ledPin, LOW);   
        delay(500);  
   }

   return 1;
}
Click to Expand
0
// 1.3
int ledPin1 = D3;
int ledPin2 = D2;

void setup() {
  // We want to tell the Argon that we'll use
  // D3 as an output pin.
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
}

void loop() {
    digitalWrite(ledPin1, HIGH);   
    digitalWrite(ledPin2, LOW);
    delay(500); 
    digitalWrite(ledPin2, HIGH);   
    digitalWrite(ledPin1, LOW);
    delay(500); 
}
Click to Expand
0
//2.3
int ledPin1 = D3;
int ledPin2 = D2;


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

   digitalWrite(ledPin1, LOW);
   
   pinMode(ledPin2, OUTPUT);

   digitalWrite(ledPin2, LOW);
   
   Particle.function("led1", led1Control);
   Particle.function("led2", led2Control);
}

void loop() {

}

int led1Control(String command)
{
    int times = command.toInt();
   for (int i=1; i<=times; i++) {
        digitalWrite(ledPin1, HIGH);   
        delay(500);               

        digitalWrite(ledPin1, LOW);   
        delay(500);  
   }

   return 1;
}

int led2Control(String command)
{
    int times = command.toInt();
   for (int i=1; i<=times; i++) {
        digitalWrite(ledPin2, HIGH);   
        delay(500);               

        digitalWrite(ledPin2, LOW);   
        delay(500);  
   }

   return 1;
}
Click to Expand
0

Video

Excersise1.2 blink five times then stop for 3 secondshttps://youtube.com/shorts/oPV695Jrnoo

Exercise1.3 Program the LED’s to alternate blinks: https://youtu.be/ockKZTUl0Yo

Exercise2.1 blink the LED 3 times after it is called: https://youtu.be/fyhtGntTN9Y

Exercise2.2 Set the function to blink that number of times: https://youtu.be/L6KXCx_-unA

Exercise2.3 control both LEDs remotely: https://youtu.be/dR6AStHpS2Y

x