Shama_Sensors input+LED
Made by Shama Patwardhan
Made by Shama Patwardhan
Set up a switch that turns on the photosensor for LED
Created: November 6th, 2024
Set up a two-input, one-output circuit.
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)
#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
Set up a switch that turns on the photosensor for LED