Shama_Sensors input+LED

Made by Shama Patwardhan

Set up a switch that turns on the photosensor for LED

Created: November 6th, 2024

0

Intention

Set up a two-input, one-output circuit. 

0

Process

I first set up a circuit with a photosensor and an LED. I also set up a second circuit with the switch and LED to familiarize myself with the process and the setup. I ran into a few snags with the photosensor as it was too bright in my workspace, and I had to recalibrate the readings for the input and output numbers. The digitalwrite channel D2 also seemed to not work at the start, but with some troubleshooting with Daragh, we changed it to D1 (for more power to flash the bulb)

0

Product

I set up the circuit with a switch button, a photosensor, and an LED Light. I think this can be used as an automatic night light with a manual override, perfect for places like hallways or bedrooms.

0

Reflection

I learned how to check for the input from the sensor on the Particle. I also learned how to combine both inputs. It was an interesting and fun project, figuring out the led bulb and a photo sensor. 

0
#include "Particle.h"
int ledPin = D1;
    int switchPin = D3;
    int photoCellPin = A0;
int photoCellReading = 0;
int ledBrightness = 0;
// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);

// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);

// setup() runs once, when the device is first turned on
void setup() {
       pinMode( switchPin , INPUT_PULLUP);
       pinMode( ledPin , OUTPUT );
       pinMode(ledPin, OUTPUT);
    Particle.variable("light", &photoCellReading, INT);
  // Put initialization like pinMode and begin functions here
}

void loop() {
    
    photoCellReading = analogRead(photoCellPin);
    ledBrightness = map(photoCellReading, 2700, 4095, 0, 255);
    analogWrite(ledPin, ledBrightness);
    delay(100);
    
    int buttonState = digitalRead( switchPin );
    
   if( buttonState == LOW );
{
    // turn the LED On
    digitalWrite(ledPin, HIGH);
  
  }else{
  
      digitalWrite(ledPin, LOW);
  }
Click to Expand
0
Click to Expand
x
Share this Project


About

Set up a switch that turns on the photosensor for LED