Digital & Analog Sensors

Concept

For this assignment, I thought of making a multipurpose sensor but I decided to create a rough design of a night lamp that has a space touch to it. I used two LEDs, a blue and a yellow one, where the blue was used for the moon and the yellow was used for the sun. For the digital aspect of this assignment, I used a button that turns on the blue light, and when clicked for the second time, the blue light starts to blink as well as the yellow light if it’s on, and when clicked for the third time, the blue light turns off. For the analog aspect, I used the sensor to detect light, so when it’s dark enough or the brightness is below 500, the yellow light turns on, and it can be in blinking mode along with the blue light if the button is clicked. 

Code 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
if (isButtonPressed) {
buttonMode = (buttonMode + 1) % 3;
isButtonPressed = false;
switch (buttonMode) {
case 0: // Off
analogWrite(BUTTON_LED_PIN, 0);
break;
case 1: // On
analogWrite(BUTTON_LED_PIN, 255);
break;
case 2: // Fading
break;
}
}
if (isButtonPressed) { buttonMode = (buttonMode + 1) % 3; isButtonPressed = false; switch (buttonMode) { case 0: // Off analogWrite(BUTTON_LED_PIN, 0); break; case 1: // On analogWrite(BUTTON_LED_PIN, 255); break; case 2: // Fading break; } }
if (isButtonPressed) {
    buttonMode = (buttonMode + 1) % 3;
    isButtonPressed = false;

    switch (buttonMode) {
      case 0: // Off
        analogWrite(BUTTON_LED_PIN, 0);
        break;

      case 1: // On
        analogWrite(BUTTON_LED_PIN, 255);
        break;

      case 2: // Fading
        break;
    }
  }

The overall code was not very challenging, but it’s definitely new to me and  it took me a while to make sure I have my code right so that I could focus on the hardware. I liked this piece of code because I’m using the switch function which really helped me organize what I had in mind. Also, I initially wanted the lights to fade but I need to work on it to figure out why its blinking.

Reflection 

This assignment challenged me to learn more about the bread board and the arduino and how to separate different functions from each other. I started this assignment by experimenting with what I already learned in class and making a few adjustments, and thought of just leaving it as a multipurpose sensor that can be used in a bedroom setting, a museum, or anywhere else, but I wanted it to have some creative aspect to it, and hence, I used whatever tools I had with me to create a rough design of a night lamp.

Video : https://intro.nyuadim.com/wp-content/uploads/2023/11/lampsensors.mp4

Leave a Reply