Skills Dev I: A Simple Internet Appliance

Made by Sohail Shaikh

Goals: Get oriented with the Particle platform, build your first circuit and code your first project.

Created: November 3rd, 2022

0

Process:

I initiated this project by going through the course instructions for making a circuit and coding in Arduino. After following the initial steps of connecting an LED to a particle cloud, I started learning about for loops and if conditions to control the LED from the particle cloud.  The main challenge for me was to think of a way to fade two led pins by giving brightness from the Particle platform. I learned about converting the user input into an integer value using the toInt() function.

Reflection: 

In this project, I learned how to code using the particle platform and control LED through the cloud. It also helped me learn the basics of Arduino language (Variables, Loops, if Conditions). It helped me develop confidence in making basic circuits. I tried the Controlling PWM exercise as well to fade two LEDs using the user input.   

Next Steps : 

I would like to learn more about the inbuilt functions and more about the other Pins of Argon. 

0

First Sketch: Making an LED Blink

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

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
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
int led1= D2;

void setup() {
pinMode(led1, OUTPUT);
}
void loop() {
    for(int i=0; i<5; i++){
        digitalWrite(led1, HIGH);
        delay(500);
            
        digitalWrite(led1, LOW);
        delay(500);
    }
    digitalWrite(led1, LOW);
    delay(3000);
}
Click to Expand
0
0

Exercise 3: Go back to the original program. Now 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.  

0
int led1= D2;
int led2= D1;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, LOW);
    delay(1000);
    
    digitalWrite(led1, LOW);
    digitalWrite(led2, HIGH);
    delay(1000);
}
Click to Expand
0
0

Making a Connected LED

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

0
int led1= D2;
void setup() {
   pinMode(led1, OUTPUT);
   digitalWrite(led1, LOW);
   Particle.function("led", ledControl);
}
void loop() {
}   

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

Exercise 2

Modify the cloud function as follows:

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
int led1= D2;
void setup() {
   pinMode(led1, OUTPUT);
   digitalWrite(led1, LOW);
   Particle.function("ledBlinkCounts", ledControl);
}
void loop() {
}   
int ledControl(String command)
{
    int blinkCounts= command.toInt();
    if(blinkCounts<0)
    {
        return -1;
    }
    for(int i=0; i<blinkCounts; i++){
	          digitalWrite(led1, HIGH);
	          delay(500);
	          digitalWrite(led1, LOW);
	          delay(500);
	   }
	    digitalWrite(led1, LOW);
   return 1;
}
Click to Expand
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
int led1= D2;
int led2= D1;

void setup() {
    
    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);
   // Initialize both the LEDs to be OFF
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    Particle.function("ledBlinkCounts", ledControl);
}

void loop() {
}   

int ledControl(String command)
{
    delay(2000);
    int blinkCounts= command.toInt();
    if(blinkCounts<0)
    {
        return -1;
    }
    for(int i=0; i<blinkCounts; i++){
	          digitalWrite(led1, HIGH);
	          digitalWrite(led2, LOW);
	          delay(500);
	          digitalWrite(led1, LOW);
              digitalWrite(led2, HIGH);
	          delay(500);
	   }
	   
	    digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
   return 1;
}
Click to Expand
0
0

Controlling PWM: Using analogWrite

Exercise 2: 

Go back to the original program. Now add a second LED to the circuit. 

Set the second LED to work as the opposite amount of brightness to the first. For example if the first is set at 55, the second should be set at 200. Hint: led2Brightness = (255 - led1Brightness)

0
int ledPin1 = D2;
int ledPin2 = D3;
// create a variable to store the
// current brightness of the LED
int ledValue = 0;

void setup() {
//Register our Particle function to allow
   // Control of the LED
   Particle.function("led", ledControl);

   Particle.variable("brightness", ledValue);

   // Set up pin for output
   pinMode(ledPin2, OUTPUT);

   pinMode(ledPin1, OUTPUT);
}

void loop() {

}

int ledControl(String command)
{
    // Convert the passed variable to an integer
   ledValue = command.toInt();

   // Check it is a valid number
   if( ledValue > 255 ) return -1;
   if( ledValue < 0 ) return -1;
   if (ledValue < 255){
        int led2Brightnes= (255 - ledValue);
        for(int j=led2Brightnes; j>=0; j--){
        analogWrite(ledPin2, j);       
        delay(10);
       }
       for(int i=ledValue; i>=0; i--){
        analogWrite(ledPin1, i);       
        delay(10);
       }
   }  

   // Return 1 to say completed successfully
   return 1;
}
Click to Expand
0
x
Share this Project

Courses

About

Goals: Get oriented with the Particle platform, build your first circuit and code your first project.