/*Light dependent resistors (LDR) or photoresistors are often used in circuits where it is necessary to detect the presence of light.
If the LDR sensor value is above 1000, when the resistance is high all lights in NeoPixel Ring will emit red : indicating that today is a full moon day.
If the LDR sensor value is above 500, when the resistance is middle all lights in NeoPixel Ring will emit yellow : indicating that today is a half moon day.
If the LDR sensor value is below 500, when the resistance is low all lights in NeoPixel Ring will emit green : indicating that today is a no moon day.*/
//library which is required to perform the action of NeoPixel Ring
#include <Adafruit_NeoPixel.h>
int Neopixel_PIN = 9;
int N_LEDS = 16;
Adafruit_NeoPixel ring = Adafruit_NeoPixel(N_LEDS, Neopixel_PIN);//ring is variable
int LDR_PIN = A0; //reading the changing values from the LDR sensor.
int value = 0;
void setup() {
ring.begin();//starts functionality
Serial.begin(9600); // Sending and receiving data between Arduino Uno and the LDR sensor.
}
void loop() {
value = analogRead(LDR_PIN);//helps to read the value from the specified analog pin.
Serial.println(value); //print on console
if (value > 1000)
{
Serial.println("Red");
set_color(ring.Color(255, 0, 0)); //RED
}
else if(value > 500)
{
Serial.println("Yellow");
set_color(ring.Color(255, 255, 0));//YELLOW
}
else
{
Serial.println("Green");
set_color(ring.Color(0, 255, 0)); //GREEN
}
}
//Define function; uint32_t is a data type which has the storage capacity of 32 bits.
int set_color(uint32_t col)
{
for(int i=0; i<N_LEDS;i++ )
{
ring.setPixelColor(i , col); // set color for each LED in ring
ring.show();//show ring led lights
delay(500);
}
}
/*OUTPUT- If the LDR sensor value decreases, it means
the light intensity is high, and when the sensor value is greater than 1000, then all
RED LEDs will glow in the NeoPixel Ring. Similarly for others*/