Dimming Wi-Fi LED

Made by Adwoa Asare

Make an LED that can dim using Wi-Fi control functions and the Photon 2 microcontroller.

Created: October 30th, 2024

0

Intention

The goal of this project was to explore some introductory skills for designing Internet of Things (IoT) devices. My goal was to make a smart light, using an LED, that could have adjustable dimming settings via Wi-Fi.

0

Process

  I started with a simple circuit consisting of a Photon 2 microcontroller, a red LED, and a 1 kOhm resistor. At first, I started with my LED being controlled by pin D2 as I tested simple HIGH and LOW digital output controls to turn the LED on and off. I then tried to use this same D2 pin for pulse width modulation (PWM) control through the analogWrite() function, but it did not work. I then changed my circuit and code to control the LED using the D1 pin and as able to successfully adjust the brightness from my Particle Console. I used a Particle function that accepted a String input and converted it to an integer to set the brightness to if the value was withing bounds.  

0
// Include Particle Device OS APIs
//#include "Particle.h"
//Adwoa Asare
//10/24/2024
// Let Device OS manage the connection to the Particle Cloud
//SYSTEM_MODE(AUTOMATIC);


int led1 = D1;
int brightness = 0;

// setup() runs once, when the device is first turned on
void setup() {
  
   
    //digitalWrite(led1,LOW);
    Particle.function("led1",ledControl);
    Particle.variable("brightness", brightness);
     pinMode(led1, OUTPUT);
}

// loop() runs over and over again, as quickly as it can execute.
void loop() {
  
    /*blink code
    digitalWrite(led1,HIGH);//LED ON
    delay(1000);//1 sec delay
    digitalWrite(led1,LOW);//LED OFF
    delay(1000);//1 sec delay
    */

}
/*
int ledControl(String command){
    int state = LOW;
    
    //set new state of LED
    if(command=="HIGH"){
        state = HIGH;
    }else if(command=="LOW"){
        state = LOW;
    }else{
        return -1;
    }
    
    //output state to pin for LED
    digitalWrite(led1, state);
    return 1;
    
}
*/
int ledControl(String command){
    //convert command to an int
    brightness = command.toInt();
    
    //bounds checking
    if(brightness > 255 || brightness <0) return -1;
    
    //set brightness of led using PWM
    analogWrite(led1, brightness);
    return 1;
}
Click to Expand
0
0

Outcome

My project was successful because I was able to control the brightness of my LED over Wi-Fi from my Particle Console. I tested the brightness at various different levels and observed the change. You can see my work here: https://youtu.be/baOVN3q9evc?si=OdvN9r0wGIftDDqJ

0

Reflection

I learned how to make functions that you could interact with over Wi-Fi. In the future, I would add some complexity to this project by adding more LEDs or using an RGB LED so I could make different colors. Overall, this was a good introduction to learning how to communicate with the Photon 2 and to understand the capabilities of the different pins.

x
Share this Project


Focused on
Skills
Tools
About

Make an LED that can dim using Wi-Fi control functions and the Photon 2 microcontroller.