Skills Dev I: A Simple Internet Appliance
Made by Justin Slusher ·
Made by Justin Slusher ·
In this project, I will create my own internet-connected appliance, a cloud-connected light using the Particle Argon microcontroller. To accomplish this, I will set up the hardware, which includes LEDs, breadboards, jumper wires, and resistors, program the microcontroller, and integrate the device with the Particle Cloud.
Created: November 7th, 2023
Project Summary:
In this project, I completed a series of IoT projects using Particle's Argon microcontroller platform to create a connected internet appliance. I first modified a cloud function to make an LED blink three times upon activation. Next, I enhanced the function to accept input for controlling the number of LED blinks and creating a sequence of five blinks with a delay between sequences. Lastly, I added a second LED to my setup and created a program to alternate, with a minor delay, the blinking of the two LEDs. For these exercises, I added the cloud function for the remote control. I also integrated it with Particle's REST API by pulling my Device ID and creating an access token, using the "curl" terminal command to place my appliance onto the internet.
In each below exercise, the process and outcome are explained.
Turning the light on and connecting it to the cloud (image/code below):
This code controls a light where the light is connected and assigned to pin D3. The setup function configures the pin as an output and registers a cloud function "led" for remote control. The "ledControl" function enables the light to be turned on or off based on the commands provided. Returning -1 for invalid commands and 1 for successful commands. Physically, I aligned the resistor to the D3 pin and placed the anode side of the LED to align to the resistor, which will incorporate the LED to the D3 pin on the microcontroller. The LED cathode then utilizes a jumper to the breadboard's power rail. A similar jumper is also used to connect the microcontroller's ground pin to the power rail.
// Turning the light on and connecting it to the cloud
// Name and assign the pins
int ledPin = D3;
void setup() {
// Configure the pin to be an output
pinMode(ledPin, OUTPUT);
// LED to be OFF
digitalWrite(ledPin, LOW);
// Register cloud function here
Particle.function("led", ledControl);
}
void loop() {
}
int ledControl(String command) {
int state = LOW;
// LED state
if (command == "HIGH") {
state = HIGH;
} else if (command == "LOW") {
state = LOW;
} else {
return -1; // Invalid command
}
// Write to the pin
digitalWrite(ledPin, state);
return 1;
}
Click to Expand
Making light blink every 3 seconds (video/code: below):
The added code to make the light blink involves a loop that is coded in to command the light to turn on (digitalWrite(ledPin, HIGH)) for three seconds (delay(3000)) and then turn off (digitalWrite(ledPin, LOW)) for another three seconds. This made the light go on and off at three-second intervals. Physically everything has stayed the same.
// Making the light blink every 3 seconds
// Name and assign the pins
int ledPin = D3;
void setup() {
// Configure the pin to be an output
pinMode(ledPin, OUTPUT);
// LED to be OFF
digitalWrite(ledPin, LOW);
// Register cloud function here
Particle.function("led", ledControl);
}
void loop() {
// Blink the LED every 3 seconds
digitalWrite(ledPin, HIGH); // Turn ON the LED
delay(3000); // 3 Sec Delay
digitalWrite(ledPin, LOW); // Turn OFF the LED
delay(3000); // 3 Sec Delay
}
int ledControl(String command) {
int state = LOW;
// LED state
if (command == "HIGH") {
state = HIGH;
} else if (command == "LOW") {
state = LOW;
} else {
return -1; // Incorrect command
}
// Write to pin
digitalWrite(ledPin, state);
return 1;
}
Click to Expand
Making light blink five times in a sequence with a short delay between sequences (video/code: below):
In the adjusted code, a loop within loop() function was added to make the light blink on/off five times, which was provided with a short delay between the on/off and a 3-second delay after the five blinks. Physically, everything had remained the same.
// 5 blinks and 3 sec delay
// Name and assign the pins
int ledPin = D3;
void setup() {
// Configure the pin to be an output
pinMode(ledPin, OUTPUT);
// LED to be OFF
digitalWrite(ledPin, LOW);
// Register cloud function here
Particle.function("led", ledControl);
}
void loop() {
// Blink 5 times then stop for 3 sec
for (int i = 0; i < 5; i++) {
digitalWrite(ledPin, HIGH); // Turn ON the LED
delay(500); // 0.5 Sec Delay
digitalWrite(ledPin, LOW); // Turn OFF the LED
delay(500); // 0.5 Sec Delay
}
delay(3000); // 3 Sec Delay after 5 blinks
}
int ledControl(String command) {
int state = LOW;
// LED state
if (command == "HIGH") {
state = HIGH;
} else if (command == "LOW") {
state = LOW;
} else {
return -1; // Incorrect command
}
// Write to the pin
digitalWrite(ledPin, state);
return 1;
}
Click to Expand
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. (video/code: below):
The string command of the function "if and else if" creates a half-second delay between the alternating of the red and orange LED lights. Physically, I have changed out the color of the LED lights. Red is now coordinated with LED1 and Ogrand with LED2. Two separate resistors have been placed at each LED light's anode, with Red(D3) and Orange (D2) and a red cathode jumper for the Red LED and a yellow cathode jumper for the Orange LED, which both jump the breadboard's power raid. The same black ground jumper jumps the microcontroller's ground pin to the breadboard's power rail.
// Two lights alternating blinking
// Name and assign the pins
int ledPin1 = D3; // First LED (RED)
int ledPin2 = D2; // Second LED (Orange)
void setup() {
// Configure the pins to be outputs
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// LED Off
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
// Register cloud function here
Particle.function("led", ledControl);
}
void loop() {
// LED Blinking between LED 1 and LED 2
digitalWrite(ledPin1, HIGH); // Turn ON the first LED
digitalWrite(ledPin2, LOW); // Turn OFF the second LED
delay(500); // 0.5 Sec Delay
digitalWrite(ledPin1, LOW); // Turn OFF the first LED
digitalWrite(ledPin2, HIGH); // Turn ON the second LED
delay(500); // 0.5 Sec Delay
}
int ledControl(String command) {
if (command == "LED1_ON") {
digitalWrite(ledPin1, HIGH);
} else if (command == "LED1_OFF") {
digitalWrite(ledPin1, LOW);
} else if (command == "LED2_ON") {
digitalWrite(ledPin2, HIGH);
} else if (command == "LED2_OFF") {
digitalWrite(ledPin2, LOW);
} else {
return -1; // Incorrect command
}
return 1;
}
Click to Expand
Next Steps:
One of the items I did not get to was going through the "Bonus Adventure," which covers making a color-controlled version of the LED. This is something I certainly would like to try next. I also look forward to beginning to utilize sensors on the microcontroller.
Reflection:
One of the primary obstacles I encountered was understanding the programming components, such as the void loop, the created integer variable "ledControl" and placing these into an else if in a way that works properly. The process became easier as I began to label certain places in the code that I was creating, and that enabled me to place specific components into "buckets" that made it easier to read through them and make sense of what I needed to do next.
This project is only accessible by signed in users. Be considerate and think twice before sharing.
A hands-on introductory course exploring the Internet of Things and connected product experiences.
In this project, I will create my own internet-connected appliance, a cloud-connected light using the Particle Argon microcontroller. To accomplish this, I will set up the hardware, which includes LEDs, breadboards, jumper wires, and resistors, program the microcontroller, and integrate the device with the Particle Cloud.