Narayan - Skills Dev II: Input and Sensors

Made by Narayan Ashanahalli

The goal of this project is to explore sensor-based inputs and their programming applications, focusing on understanding how sensor readings control outputs. By using a light sensor and LED, the objective is to create a system where the LED turns on or off based on sensor values. This project aims to build a solid understanding of sensor calibration, programming logic, and the relationship between physical inputs and digital outputs, laying the groundwork for future sensor-based applications.

Created: November 11th, 2024

0
int photoCellPin = A0;

// Variable to store the light reading from the sensor
int photoCellReading = 0;

// Pin where the LED is connected
int ledPin = D10;

void setup()
{
  // Set up the LED pin as an output
  pinMode(ledPin, OUTPUT);

  // Create a cloud variable to track the light sensor reading remotely
  Particle.variable("light", photoCellReading);
}

void loop()
{
  // Get the light reading from the sensor, range from 0 to 4095
  photoCellReading = analogRead(photoCellPin);

  // Print the reading to the Serial Monitor to keep track of it
  Serial.println(photoCellReading);

  // If the reading is more than 500, I want the LED to turn on
  if (photoCellReading > 500) {
    digitalWrite(ledPin, HIGH);  // LED on
  } else {
    digitalWrite(ledPin, LOW);   // LED off
  }

  // Wait 100ms before reading again, helps avoid unnecessary flicker
  delay(100);
}
Click to Expand
0
x
Share this Project


Focused on
About

The goal of this project is to explore sensor-based inputs and their programming applications, focusing on understanding how sensor readings control outputs. By using a light sensor and LED, the objective is to create a system where the LED turns on or off based on sensor values. This project aims to build a solid understanding of sensor calibration, programming logic, and the relationship between physical inputs and digital outputs, laying the groundwork for future sensor-based applications.