Designing for IOT Lab 1

Made by bmkaufma · UNLISTED (SHOWN IN POOLS)

The goal of this project is to gain familiarity with the Particle IOT development board/platform by creating a connected LED circuit.

Created: November 1st, 2022

0

Lab 1

Outcome

The outcome of this lab was a successful circuit and code that allows for an LED to be controlled by sending a command through the particle cloud. 

Process

The process for this lab was pretty straightforward. As this was the first lab of the mini, step-by-step instructions as well as code was provided. I followed the instructions and modified the code as needed to complete the assignment.

Reflection

I enjoyed this activity. It has been a while since I worked with a microcontroller and it felt good to dust the cobwebs off. I have little experience with the cloud connected function of the particle board, so it was really cool to learn how to interface with the cloud and actually control the device remotely. Next time I will read through all of the exercises first to see if there is a way I can optimize the structure of my code to work better for all cases.

0

Exercise 1: Make the LED blink three times when called with the command "HIGH"

0
int ledPin = D2;

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

int ledControl(String command)
{
   int state = LOW;

   // find out the state of the led
   if(command == "HIGH"){
	    for (int x = 1; x <= 3; x++){
      digitalWrite(ledPin, HIGH);
      delay(500);
      
      digitalWrite(ledPin, LOW);
      delay(500);
  }
        	   
   }else if(command == "LOW"){ 
	   state = LOW;
   }else{
	   return -1;
   }

   // write to the appropriate pin
   digitalWrite(ledPin, state);
   return 1;
}
Click to Expand
0

Exercise 2: Make the LED blink a given number of times then turn it off.

0
int ledPin = D2;

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

int ledControl(String command)
{
   
    int blinks = command.toInt();
    int state = LOW;

   // find out the state of the led
   if(command == "HIGH"){
	    for (int x = 1; x <= blinks; x++){
      digitalWrite(ledPin, HIGH);
      delay(500);
      
      digitalWrite(ledPin, LOW);
      delay(500);
   }

}
Click to Expand
0

Exercise 3: Addition of a second LED that allows for independent control of each.

0
int ledPin = D2;
int ledPin2 = D3;

void setup() {
     pinMode(ledPin, OUTPUT);
     digitalWrite(ledPin, LOW);
     pinMode(ledPin2, OUTPUT);
     digitalWrite(ledPin2, LOW);
 
     Particle.function("Red led", ledControl1);
     Particle.function("Orange led", ledControl2);
 
}

int ledControl1(String command)
{
   int state = LOW;

   if(command == "HIGH"){
      digitalWrite(ledPin, HIGH);
      delay(500);
  } 
	      
   }else if(command == "LOW"){ 
	   state = LOW;
   }else{
	   return -1;
   }

   // write to the appropriate pin
   digitalWrite(ledPin, state);
   return 1;
}

int ledControl2(String command)
{
   int state = LOW;

   if(command == "HIGH"){
      digitalWrite(ledPin2, HIGH);
      delay(500);
  } 
	      
   }else if(command == "LOW"){ 
	   state = LOW;
   }else{
	   return -1;
   }

   // write to the appropriate pin
   digitalWrite(ledPin2, state);
   return 1;
}
Click to Expand
x
Share this Project

This project is only listed in this pool. Be considerate and think twice before sharing.


Courses

About

The goal of this project is to gain familiarity with the Particle IOT development board/platform by creating a connected LED circuit.