Skills Dev II: Working with Inputs and Sensors

Made by Tyler Howe · UNLISTED (SHOWN IN POOLS)

The circuit for this lab will use a photoresistor to detect low light and allow a potentiometer to adjust LED brightness.

Created: December 18th, 2022

0

Outcome

Demonstration: https://youtube.com/shorts/GDjL-Q3lSow


The outcome of this lab was to create a circuit that used a photosensor to detect if the light was low enough for a "night light", then allow a potentiometer to control the brightness of an LED. 

0

Process

I enjoyed the process of learning how sensors and their variables are setup in the particle cloud WEB IDE. This lab was somewhat straightforward when assigning pins and defining their variables for future use in loops. The most difficult part was coding the loop correctly to only turn on the night light when the photo cell reading was less than 2000. Ultimately, I got it to work and was able to produce the night light! 

0
// STEP 1 Define pins
// Photocell pin definition
int photoCellPin = A0;
// Potentiometer pin definition
int potPin = A5;
// LED pin definition
int ledPin = D2;

// STEP 2 Define variables 
// Light reading variable
int photoCellReading = 0;
// potentiometer reading variable
int potReading = 0;
// LED brightness reading variable
int ledBrightness = 0;	

// STEP 3 Setup
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);
    // Create a cloud variable of type integer called 'potReading'
    Particle.variable("potReading", potReading);
}

// STEP 4 Creating a loop()
void loop()
{
  // Use analogRead to read the photo cell reading w value 0 to 4095
  photoCellReading = analogRead(photoCellPin);
  // Use analogRead to read the pentiometer reading
  potReading = map(analogRead(potPin), 0,4095, 0, 255);
  // 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
       if(photoCellReading < 2000) {
            analogWrite(ledPin, potReading);
        } else {
            digitalWrite(ledPin, LOW);
        }
    delay(100);
}
Click to Expand
0

Reflection

I learned that there are many combinations of motors and actuators and ways to trigger those motors with different sensors! The only limitation is my ability to think of a useful or meaningful use case for which to build. 

x
Share this Project

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


Courses

About

The circuit for this lab will use a photoresistor to detect low light and allow a potentiometer to adjust LED brightness.