Skills Dev II: Sensor the Reads Light Intensity

Made by pgomezte

The objective of this project is to build a circuit with a photoresistor sensor to read the intensity of the light in the room. The intensity of the light in the room can be read in a scale in the Cloud.

Created: November 9th, 2022

-1
  I built a circuit that senses the intensity of the light around it. The idea behind this is to be able to check how intense or dim the surrounding light is. This could be a good building step to build an IoT device that can sense the light and do a useful action afterwards.  
0
int photoCellPin = A0;

// Create a variable to hold the light reading
int photoCellReading = 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() {
    
pinMode(ledPin, OUTPUT);

 // Create a cloud variable of type integer
  // called 'light' mapped to photoCellReading
  Particle.variable("light", &photoCellReading, INT);


}

void loop() {
    
// Use analogRead to read the photo cell reading
  // This gives us a value from 0 to 4095
  photoCellReading = analogRead(photoCellPin);

  // Map this value into the PWM range (0-255)
  // and store as the led brightness
  ledBrightness = map(photoCellReading, 0, 4095, 0, 255);

  // fade the LED to the desired brightness
  analogWrite(ledPin, ledBrightness);

  // wait 1/10th of a second and then loop
  delay(100);

}
Click to Expand
0

The code above is what programs the sensor to check the light intensity, while showing the reading in the cloud console.

To test it out, I set up the sensor with regular light. When I looked for the light intensity in the cloud console, I would get readings in the 1700-1800 range (this scale is specified in the code). See Video 1 in the video demonstration link below.

For the second test, I turned off some lights off so that the room would be dimmer. I checked the cloud console to see what the light intensity was and as expected, the readings decreased to the 1000-1100s range. This showcases that the sensors work and the code is doing what I wanted it to do. See Video 2 in the video demonstration link below.

0
0
x
Share this Project

Courses

About

The objective of this project is to build a circuit with a photoresistor sensor to read the intensity of the light in the room. The intensity of the light in the room can be read in a scale in the Cloud.