Skills Dev II: Working with Inputs and Sensors

Made by Nick Possi-Moses · UNLISTED (SHOWN IN POOLS)

This project will use a photoresistor to translate differences in the amount of light. A good use case for this might be with dimming lights as it gets dark (or using blue light) to help people transition from being in a wake state to a sleep state.

Created: November 30th, 2022

0

Outcome

The objective of this lab was to create a successful circuit that used at least two inputs, including at least one sensor. Additionally, the aim of the lab was to introduce conditional statements and create different responses to those statements.

For this project specifically, I wanted to explore the use of light to transmit softer (or more intense) lighting. This is especially applicable when considering seasonal depression or the use of blue lights to help people be exposed to the right amount (or even type) of light at the right time. This project specifically focused on people being exposed to the right type of light at the right time, such as the case when someone is transitioning from a wake state to a sleep state. For example, as people prepare for bed, softer lights (and bluer lights) are often used so that their bodies can start to produce melatonin.

This circuit, when turned on via a switch, would turn 'blue' when there is less light being exposed to a photoresistor, which would indicate that it is night time and therefore time to be exposed to softer and bluer light. When more light was exposed to the photoresistor, more intense light would be emitted.

0

Process

The biggest problem I faced was creating troubleshooting the photoresistor. The circuit was otherwise easy to complete, but I initially could not get the photoresistor to work. I kept getting really odd readings from the cloud variable that I had created. I learned that due to the way that photoresistors work, I needed to create a pathway for the photoresistor 'response' to transmit to both the 10k ohm as well as the analog. Basically, I just needed to connect 2 wire to the photoresistor so that one connected to the analog, which could receive readings from the photoresistor, and so that the photoresistor's register of light would be transmitted through the 10k ohm and then subsequently to the 'ground.'

0

Reflection

I think my biggest takeaway was more insight into how circuits are created. The lessons from troubleshooting the photoresistor were extremely impactful. The same is also true for the switch, which allowed for the circuit to be connected/disconnected. I also learned more about how to use conditional statements to create different visible responses.

0
// We will be using D2 to control our LED
int redPin = D2;
int bluePin = D3; 

// Our button wired to D0
int switchPin = D4;

// Photoresistor
int photoCellPin = A0; 

// Create a variable to hold the light reading
int photoCellReading = 0; 

//Create a variable to store the Blue LED brightness
int blueLedBrightness = 0; 

//Create a variable to store the Red LED brightness
int redLedBrightness = 0; 

void setup()
{

  // For input, we define the
  // pushbutton as an input-pullup
  // this uses an internal pullup resistor
  // to manage consistent reads from the device

  pinMode( switchPin , INPUT_PULLUP); // sets pin as input

  // We also want to use the LED

  pinMode(redPin, OUTPUT);  // sets pin as output
  pinMode(bluePin, OUTPUT); // sets pin as output
  
  
  // Create a cloud variable of type integer
  // Called 'light' mapped to photoCellReading
  Particle.variable("light", &photoCellReading, INT); 

}

void loop()
{
    // find out if the button is pushed
    // or not by reading from it.
    int switchState = digitalRead( switchPin );
    
    
    // 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
    redLedBrightness = map(photoCellReading, 3000, 4000, 0, 255); 
    blueLedBrightness = map(photoCellReading, 3000, 3999, 0, 255); 


  // remember that we have wired the pushbutton to
  // ground and are using a pulldown resistor
  // that means, when the button is pushed,
  // we will get a LOW signal
  // when the button is not pushed we'll get a HIGH

  // let's use that to set our LED on or off

  if (switchState == LOW & photoCellReading >=3800)
  {
        // turn the LED On
        digitalWrite(bluePin, HIGH); 
        digitalWrite(redPin, LOW); 
  } 
  else if (switchState == LOW & photoCellReading >= 0 & photoCellReading < 3800)
  {
        digitalWrite(redPin,  HIGH);
        digitalWrite(bluePin, LOW); 
  }
  else { 
    // otherwise
    // turn the LED Off
    digitalWrite(redPin, LOW);
    digitalWrite (bluePin, LOW); 
  }
}
Click to Expand
1
x
Share this Project

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


Courses

About

This project will use a photoresistor to translate differences in the amount of light. A good use case for this might be with dimming lights as it gets dark (or using blue light) to help people transition from being in a wake state to a sleep state.