Combining Sensors and Inputs: Skills Dev II

Made by Bennett Goeke

Imagine a simple three component sensing device (an LED, a sensor and one additional sensor or input).

Created: November 11th, 2023

0

Imagine a simple three component sensing device (an LED, a sensor and one additional sensor or input). Using a switch, the photoresistor will start to work then and sense whether or not the led night light is needed. With lower levels of light, the light turns on and when it gets bright the led dims as its no longer needed. When one is ready to go to bed they can use the switch to completely turn it off.

0
Skills Dev II: 2-in (sensors or inputs) 1-out (LED) device
Bennett Goeke - https://www.youtube.com/shorts/8syAsfAaAps
0
int ledPin = D3;

int switchPin = D4;
int photoCellPin = A3;
int photoCellReading = 0;
int ledBrightness = 0;


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

}

void loop() {
    
    int buttonState = digitalRead( switchPin);
    photoCellReading = analogRead(photoCellPin);
    
    if(buttonState == HIGH) {
        if (photoCellReading <= 2000) {
        digitalWrite( ledPin, HIGH);
        }else{
            digitalWrite( ledPin, LOW);
            }
    }else{
        digitalWrite( ledPin, LOW);
    }

}
Click to Expand
0

Sensors Exercise 1:

The program shows how much light is available. When there is lots of light the LED is bright. When there is little light it’s dim.

0
int photoCellPin = A3;
int photoCellReading = 0;
int ledPin = D3;
int ledBrightness = 0;


void setup() {
    pinMode(ledPin, OUTPUT);

}

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

}
Click to Expand
0
Sensors + Inputs Exercise 1
Bennett Goeke - https://www.youtube.com/watch?v=slOGLQDWVkw
0

Sensors Exercise 2:

Modify the program so that the LED shows the opposite. When there is little light, it will be bright and when there’s lots of light, it will be off.  

0
//Modify the program so that the LED shows the opposite. 
//When there is little light, it will be bright and when there’s lots of light, it will be off.

int photoCellPin = A3;
int photoCellReading = 0;
int ledPin = D3;
int ledBrightness = 0;


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

}

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

}

//1300 is around the lowest light value  I can get for dark conditions
//3700 is around the highest light value I can get for normal room lighting
Click to Expand
0
Sensors + Inputs Exercise 2
Bennett Goeke - https://www.youtube.com/watch?v=BdlSXq-DGmc
0

Sensors Exercise 3:

Instead of fading your light, why not turn it on or off when the light reaches certain levels.

For example, if the light levels are below 600 turn the light on (and bright), otherwise turn it off.

Modify the program to work in this way.  

0
//Instead of fading your light, why not turn it on or off when the light reaches certain levels.

//For example, if the light levels are below 2000 turn the light on (and bright), otherwise turn it off.


int photoCellPin = A3;
int photoCellReading = 0;
int ledPin = D3;
int ledBrightness = 0;


void setup() {
    pinMode(ledPin, OUTPUT);

}

void loop() {
    
    photoCellReading = analogRead(photoCellPin);
    
    if (photoCellReading <= 2000) {
        digitalWrite( ledPin, HIGH);
    }else{
        digitalWrite( ledPin, LOW);
    }
    
    //ledBrightness = map(photoCellReading, 4095, 0, 0, 255);
    //analogWrite(ledPin, ledBrightness);
    //delay(100);
    

}
Click to Expand
0
Sensors + Inputs Exercise 3
Bennett Goeke - https://www.youtube.com/watch?v=FikqLsn34OY
0

Future Application:

Something that could be interesting to add would be the possibility to set schedules for the night light that could then automatically turn off instead of having to manually hit a switch when you want to go to bed. I also think the LED could be more of a light strip that's more of an ambient light source, allowing more opportunity for colors and brightness. 


0

Reflection:

One of the tricky aspects of this project was getting the reading of the photoresistor and figuring out how to publish that reading. This was important because then I could set up the values in the code so that they were accurate to the room I was in and the conditions that made the light turn on. At first the program wasn't working because I wasn't getting the lowest values I thought I would get when covering the photoresistor with my sleeve. The photoresistor was still getting values of light even when I thought I was completely covering it up.

x
Share this Project

Courses

48-675 Designing for the Internet of Things

· 11 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

Imagine a simple three component sensing device (an LED, a sensor and one additional sensor or input).