Skills Dev I: A Simple Internet Appliance

Made by Junke Zhao

The project is going to create a preliminary appliance with a Particle Argon microcontroller.

Created: December 4th, 2023

0

Intention

The goal of this project is to build a basic IoT project using the Particle Argon microcontroller and complete some basic code projects such as controlling LED lights.

0

Process

By following the tutorials on the DIoT Lab and official Particle Handbook, I connected the Argon microcontroller to Particle Cloud, and wrote various forms of code to enable different ways of controlling the LEDs.

0

Ex. 1: Make LED lights go on and off every 3 seconds。

0
0
int led = D3;

void setup() {
    
    pinMode(led,OUTPUT);
}

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

}
Click to Expand
0

Ex. 2: Using for loop to make the LED  enter a 3-second interrupt state every five flashes

0
0
int led = D3;

void setup() {
    
    pinMode(led,OUTPUT);
}

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

Ex. 3: Adding the second LED light,  then make the LED’s to alternate blinks. when LED 1 turns on, LED 2 turns off, then when LED 2 turns on, LED 1 turns off.

0
0
int led1 = D3;
int led2 = D2;

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

void loop() {
    
    for (int i = 0; i<5; i++){
        digitalWrite(led1, HIGH);
        digitalWrite(led2, LOW);
        delay(1500);
        digitalWrite(led1, LOW);
        digitalWrite(led2, HIGH);
        delay(1000);
        }
    delay(3000);
}
Click to Expand
0

Additional Ex. 1: Use the Particle Cloud function to send commands to the LEDs to make them blink.

0
int led1 = D3;

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

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

   if(command == "HIGH"){
	   state = HIGH;
   }else if(command == "LOW"){ 
	   state = LOW;
   }else{
	   return -1;
   }

   digitalWrite(led1, state);
   return 1;
}

void loop() {
    
}
Click to Expand
0

Additional Ex. 2: Change the input so that it can control the LED blinking by entering the number of times it blinks.

0
int led1 = D3;

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

int ledControl(String times)
{
   int n = times.toInt();

   for (int i = 0; i<n; i++){
        digitalWrite(led1, HIGH);
        delay(500);
        digitalWrite(led1, LOW);
        delay(500);
        }
    digitalWrite(led1, LOW);
    return 1;
}

void loop() {
    
}
Click to Expand
0

Additional Ex. 3: Add a second LED so that the two LEDs can be controlled separately in Particle Cloud.

0
int led1 = D3;
int led2 = D2;

void setup()
{
   //Register Particle function 
   Particle.function("led1", led1Control);
   Particle.function("led2", led2Control);
   pinMode(led1, OUTPUT);
   pinMode(led2, OUTPUT);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
}

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

   if(command == "HIGH"){
	   state = HIGH;
   }else if(command == "LOW"){ 
	   state = LOW;
   }else{
	   return -1;
   }

   digitalWrite(led1, state);
   return 1;
}

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

   if(command == "HIGH"){
	   state = HIGH;
   }else if(command == "LOW"){ 
	   state = LOW;
   }else{
	   return -1;
   }

   digitalWrite(led2, state);
   return 1;
}
void loop() {
    
}
Click to Expand
0

Reflection

In this section, I've learned basic skills to build a microcontroller developing environment, and also able to write basic functions to control the operation of the LEDs, including a way to transfer commands using Particle Cloud, and I'm exploring some other ways to run it.

In the process, I realized that it was important to keep the functions neat and easy to read, which would help keep things efficient as I added more features and equipment later.

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

The project is going to create a preliminary appliance with a Particle Argon microcontroller.