Skills Dev II

Made by Ben Oppenheim · UNLISTED (SHOWN IN POOLS)

Create a "night light" that allows you to adjust the brightness of the light when normal lights are turned off (i.e. photosensor is below a certain value).

Created: November 6th, 2022

0

Outcome - Night Light

Using the photosensor, the light level is detected to determine if all of the lights are off in a given space. This is done by finding a setting where the photosensor is below a specific ambient light level determined through testing (about 2000 in my testing). If the light levels are below a specific point, then the user is able to adjust the brightness of the LED using the potentiometer to create a custom light brightness.

0
// Define a pin that we'll place the photo cell on
// Remember to add a 10K Ohm pull-down resistor too.
int photoCellPin = A0;

// Create a variable to hold the light reading
int photoCellReading = 0;

// Define a pin that we'll place the pot on
int potPin = A5;

// Create a variable to hold the pot reading
int potReading = 0;

// Define a pin we'll place an LED on
int ledPin = D2;

// Create a variable to store the LED brightness.
int ledBrightness = 0;


void setup()
{
  // Set up the LED for output
  pinMode(ledPin, OUTPUT);
  
  // Create a cloud variable of type integer
  // called 'light' mapped to photoCellReading
  Particle.variable("light", &photoCellReading, INT);
  Particle.variable("pot", potReading );
}

void loop()
{
  
  // Use analogRead to read the photo cell reading
  // This gives us a value from 0 to 4095
  photoCellReading = analogRead(photoCellPin);
  
  // Use analogRead to read the potentiometer reading
  // This gives us a value from 0 to 4095
  potReading = analogRead(potPin);
  ledBrightness = map(potReading, 0, 4095, 0, 255);


    if(photoCellReading < 2000){  //sensor was never less than 3000
        // fade the LED to the desired brightness
        analogWrite(ledPin, ledBrightness);
    } else{
        digitalWrite(ledPin, LOW);
    }
    
  // wait 1/10th of a second and then loop
  delay(100);
}
Click to Expand
0

Process

I went through a few different iterations before landing on this setup. Originally I was going to use the RGB LED to change the hue of the light with the potentiometer, but I could not get the RGB LED to set up properly following the instructions, so I will attempt that for next time. Next, I was going to use the temperature sensor to set the LED brightness to a corresponding level of heat (so low light for low temp, etc) however, the wiring diagram online must have had some errors because when I set it up following that it got hot and I immediately had to remove it. So I settled on something a bit different than where I started to still explore how these two components could interact. The next step would be to eliminate the potentiometer and have the user provide input on their device using a slider.

0

Reflection

I am definitely understanding better how to create the code to run the individual components. I am still struggling with wiring up the individual components because I don't quite understand how each individual component is intended to be wired to prevent any problems. I also have trouble diagnosing between code and wiring errors. If there is a way to test the board setup without code to ensure it's set up correctly that would be useful to know!

I really want to use the RGB LED so in our next lab I will try to focus on making that work!

x
Share this Project

This project is only listed in this pool. Be considerate and think twice before sharing.


Courses

About

Create a "night light" that allows you to adjust the brightness of the light when normal lights are turned off (i.e. photosensor is below a certain value).