Scary Dark Dark- the Breathing Lamp in Dark

Introduction: Scary Dark Dark- the Breathing Lamp in Dark

This lamp is made for people that have to walk to their beds after closing the light. By adjusting the time length of the LED light, you could have your own lamp that doesn't shine through the night but could provide you a safe way back to your bed!

Step 1: Prepare the Materials

    1. Arduino Leonardo Board 1
    2. LCD 16*2 I2C Display 1
    3. Photoresistor 1
    4. Potentiometer 1
    5. 40PCS Dupont Wire Jumpercables 20cm 2.54MM Male - male 1P-1P 8
    6. 40PCS Dupont Wire Jumpercables 20cm 2.54MM Male - Female 1P-1P 11
    7. A light-emitting diode (any color)
    8. USB 2.0 a-male to micro b cable 1
    9. A computer with Arduino and USB as the input, if not, be sure to use an adapter!
    10. A Power bank with USB output
    11. Cardboards
    12. Kadian Sid (color of choice)
    13. Utility knife 1
    14. Ruler (Longer than 17.5 cm) 1

    Step 2: Build the Circuit

    Connect all the materials just as the picture

    Step 3: Make the Exterior Container

    Above is a blueprint and the size of the boards, I used cardboard and Kadian Sid for making the box. The could be a different choice on the materials in this step.

    Step 4: Download File for LCD Display

    BE SURE TO DOWNLOAD THIS FILE IN THE LINK BELOW TO MAKE YOUR LCD DISPLAY WORK!

    https://github.com/johnrickman/LiquidCrystal_I2C

    Step 5: Copy and Paste the Code on Arduino

    gistfile1.txt

    #include
    #include
    int _brightness ;
    int _time ;
    int _flag ;
    // For these LCD controls to work you MUST replace the standard LCD library from...
    // https://github.com/marcoschwartz/LiquidCrystal_I2C
    // Direct download https://github.com/marcoschwartz/LiquidCrystal_I2C/archive/master.zip
    // Your project will not compile until this is done.
    LiquidCrystal_I2C lcd_I2C_27(0x27,16,2); // set the LCD address for a 16 chars and 2 line display
    void setup(){
    Serial.begin(9600);
    lcd_I2C_27.init (); // initialize the lcd
    lcd_I2C_27.backlight();
    pinMode( 6 , OUTPUT); // set the LED as output
    _brightness = 0 ;
    _time = 1 ;
    _flag = 1 ;
    }
    void loop(){
    Serial.print(analogRead( A0 )); //Potentiometer
    Serial.print(" ");
    Serial.println();
    Serial.print(analogRead( A1 )); //Photoresistor
    Serial.print(" ");
    Serial.println();
    lcd_I2C_27.clear();
    if ( analogRead( A1 ) < 3000 && _flag == 1 ) {
    _time = constrain( map ( analogRead( A1 ) , 0 , 1023 , 1 , 300 ) , 1 , 300 ) ; //Set the time limit to 300 seconds, it would be possible to change the time limit to higher or lower values by changing the maximum number 300.
    lcd_I2C_27.setCursor(6 , 0) ;
    lcd_I2C_27.print( _time );
    lcd_I2C_27.setCursor(3 , 1) ;
    lcd_I2C_27.print( "seconds" ); //the LCD shows the instant time set up by the Potentiometer
    delay( 280 );
    }
    if ( analogRead( A0 ) < 600 && _flag == 1 ) {
    digitalWrite( 6 , HIGH ); // Sets the LED on
    delay( ( _time * 1000 ) ); //Delay for the time set up
    for (int i4 = 0 ; i4 < 255 ; ++i4 ) {
    _brightness = ( _brightness - 1.0 ) ; //Decreasing the brightness
    analogWrite(6 , _brightness); //LED slowly diminishes
    delay( 5 );
    }
    _flag = 0 ;
    // When flag==1, the device is always restarting, so the light will continue to glow.
    //The flag is set to 0 so after the glow, so the light only lights up once in the dark.
    lcd_I2C_27.setBacklight(LOW); //turn the LCD display dark
    }
    if( analogRead( A0 ) > 500 && _flag == 0 ) {
    delay(3000);
    if(analogRead( A0 ) > 500 ){ //If the light is on for 3 seconds or more, the device resets itself so that you could adjust the time limit and turn off the light again with your smart lamp!
    _flag = 1 ;
    lcd_I2C_27.backlight();
    }
    }
    }
    view rawgistfile1.txt hosted with ❤ by GitHub

    Step 6: Connect the Arduino Leonardo Board to Your Computer and Upload the Code~

    Step 7: Doneeeeeee

    To adjust the time length, turn the potentiometer clockwise to increase the time, anticlockwise to decrease the time.

    In normal conditions (opening the light), the LED would also have a constant brightness, and that is normal instead of an error in the code!

    Be the First to Share

      Recommendations

      • Organization Contest

        Organization Contest
      • Halloween Contest

        Halloween Contest
      • Space Contest

        Space Contest

      2 Comments

      0
      sharonliao
      sharonliao

      Reply 1 year ago

      Thank you for your compliment!