Skills Dev II : Yashasvi

Made by ytulchiy · UNLISTED (SHOWN IN POOLS)

Creating a simple 2-in (photoresistor and button) 1-out (LED) device.

Created: November 12th, 2020

0

Goal 

- To creator a circuit that uses a photoresistor to collect data and display it, with a button to control input. 

- To add potentiometer and button to the circuit. The potentiometer will control the led brightness and the button will switch it on and off. 

0

Approach

Step by Step process on the DioT Labs site for Practice Exercise II

0

Creating a Circuit

0

Code

Setting up the sketch and connecting it to the Particle Cloud

0
int photoCellPin = A0;
int photoCellReading = 0;
int ledPin = D2;
int ledBrightness = 0;

void setup() {
    pinMode(ledPin, OUTPUT);
    
    Particle.variable("light", &photoCellReading, INT);

}

void loop() {
    
    photoCellReading = analogRead(photoCellPin);
    ledBrightness = map(photoCellReading, 0, 4095, 0, 255);
    analogWrite(ledPin, ledBrightness);
    delay(100);

}
Click to Expand
0

Adding potentiometer to control the intensity of led and button to switch the circuit on and off .

0

When the potentiometer reading is high

0

When potentiometer reading is low

0
int photoCellPin = A0;
int photoCellReading = 0;
int ledPin = D2;
int ledBrightness = 0;

int buttonPin = D3;
int buttonState;

int potPin = A0;
int potReading = 0;

void setup() {
    pinMode(ledPin, OUTPUT);
    
    pinMode(buttonPin, INPUT_PULLUP);
    
    Particle.variable("light", &photoCellReading, INT);

}

void loop() {
    
    buttonState = digitalRead(buttonPin);
    
    potReading = analogRead(potPin);
    
    if(buttonState ==LOW){

        int ledBrightness = map(potReading, 0,4095, 0,255);
        analogWrite( ledPin, ledBrightness);
    } else{
        digitalWrite( ledPin, LOW);
    }

  

}
Click to Expand
0
x
Share this Project

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


Courses

Focused on
About

Creating a simple 2-in (photoresistor and button) 1-out (LED) device.