Night Light Sensor
My project is a night light sensor. Once you plug in the Arduino, the ringed-shaped light will automatically light up. Once you put the night light in the dark, the rest of the LED lights will light up, creating a brighter atmosphere for a blue night light. If the project is in the light, the night light will not be turned all the way on.
My project is a light sensor, essentially. When in the light, it is dimly lit; when in the dark, it lights up like a night light. The photoresistor outside of the bulb detects the light to see whether it should turn up the brightness or not. The LEDs add to the NeoPixel for more light.
To set up my NeoPixel, I used the code from Chapter 8 from the Electronics Class Website. The NeoPixel color was at first green, but by changing the code from (0, 255, 0=green) to (0, 0, 255), the color of the ring changed blue. First I had to download the new Arduino Program to access the NeoPixel code. For the code, I included Adafruit_NeoPixel, the official coding name for getting the NeoPixel to work. The NeoPixel wire is attached to ~6 (PWM) to work. Next, the Adafruit_NeoPixel had to understand how many pixels and which pin to send the signals to. I then delayed the value of changing the LEDs for half of a second. To get the 6 LEDs to light up by using a photo resistor, I had to create a variable called sensorPin, which is attached to A0. This senses light or darkness and turns the LEDs on or off. I added 6 LEDs and gave them variables to light them up (and made sure to add a resistor to each of them as well). I attached the LEDs to 12, 13, 8, 7, 2 and 4. The sensorValue variable makes sure when it is dark to turn on the LEDs. If it is less than 40, the LEDs will be turned on and vice versa.
In the void setup, there is a code that ends the special code for the NeoPixels. Then I began my Serial monitor for the LEDs. It is at 9600 baud and all LEDs are initialized as an output. Once darkness is above the photo resistor, the numbers on the Serial monitor go from the 100s to the 50s. Also included in the void setup, is the pixels.begin function, which initializes the NeoPixel library.
In the void loop, I created a function to turn the NeoPixels on and make sure they stay on. Next, I created a variable for the photo resistor to read the value, meaning when I touch or the room is dark over the photo resistor, it will read the value of darkness and turn the LED on. The Serial monitor then prints the value to monitor. Then, I repeat this same code 6 times to correspond to the 6 LEDs: if the value is less than the sensorValue, then turn the LED on. But if the value is greater than the sensorValue, it will turn the LED off. Lastly, I included my void neoPixelsOn() function to make sure the NeoPixel stayed on. The for statement shows that if the first NeoPixel is 0, the second is 1, and all the way up to the count of pixels minus 1. This is for when I originally had the NeoPixel turning on one pixel at a time. For will keep repeating what ever is in the brackets as long as the condition is true. Under the for statement, I set the pixel color to blue and then used pixels.show() to send the updated pixel color to the hardware.