Adjusting the brightness of an LED light

Made by Brian Hernandez

It will let the user to turn a knob allowing the user to control the brightness of the led light

Created: December 6th, 2023

0

Intention

The intention behind this project was to create an LED light that's brightness can be controlled with a knob. This way if someone wants to dim the lights on their LED light they can.

0

Process

The process included adding a LED light and a rotating knob on a breadboard. I made sure to add in the code the highest brightness that the LED can go and make it dim to almost not light. There were a lot of changes I had to make like reducing the size of my button and also seeing what dimmer would fit and also the type of LED light to use. 

0
0

Short video with me demonstrating one dimming and undimming the LED lights.

0

Reflection

In this process I learned the basic skills to build a functioning LED light and I learned how to write basic functions in code. I realized how much a lowercase or even a semicolon can change the whole code not allowing the code to work properly. 

I feel like if I had more time I could create a small desk lamp that allows one to rotate a dial for the user's ideal light brightness.

0
//Set Up Variable 
int ledPin = D2;
//bool status = LOW;                                                     //control with phone 
int buttonPin = D3;

int buttonState; //store the reading from the button

int potPin = A5;
int potReading = 0;

void setup() {

    pinMode( ledPin, OUTPUT );
    
    pinMode( buttonPin, INPUT_PULLUP );
    
    Particle.variable("dial", potReading);
    
//    pinMode( potPin, INPUT );
    
  //  Particle.function( "controllight", handleControllight );
  // analog pins are by default inputs (no need to configure them.)
    
}

void loop() {
    
    buttonState = digitalRead( buttonPin );
//    int buttonReading = digitalRead( buttonPin );
    
    potReading = analogRead( potReading );
    
    //AnalogRead = value from 0-4095
//    potReading = analogRead( potPin );
    
//    int ledBrightness = map( potReading, 0, 4095, 0, 255 );
    
//    analogWrite( ledPin, ledBrightness );
    
//    buttonState = digitalRead( buttonPin );
    
    if( buttonReading == LOW )
    {
        
//        int ledBrightness = map( potReading, 0, 4095, 0, 255 );
        
  //      analogWrite( ledPin, ledBrightness );
        
  //     digitalWrite( ledPin, HIGH );
 //   }else{
//         digitalWrite( ledPin, HIGH );
//    }else{
  // delay( 2000 );
    
         digitalWrite( ledPin, LOW );
    }else{
        
        int ledBrightness = map(potReading,0, 4095, 0, 255);
        
        analogWrite(ledPin, ledBrightness);
    }
  // delay( 2000 );
//    }
  //  digitalWrite( led, status );
       delay( 500 );
    
    // repeat and repeat ..etc
}

//   int handleControllight( String command ){

//    if( command.equals( "on" ) ){
//        status = HIGH;
  //      digitalWrite( led, HIGH );
    //     delay( 200 );
     //     digitalWrite( led, LOW );
      //    delay( 200 );
    //       digitalWrite( led, HIGH );
     //    delay( 200 );
      //    digitalWrite( led, LOW );
    //      delay( 200 );
     //      digitalWrite( led, HIGH );
    //     delay( 200 );
    //      digitalWrite( led, LOW );
    //      delay( 200 );
    //    return 1;
//    }
 
//    if( command.equals( "off" ) ){
 //       status = LOW;
 //       return 0;
//    }
 //   return -1;
//}
Click to Expand
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

It will let the user to turn a knob allowing the user to control the brightness of the led light