Skills Dev 2: Inputs & Sensors

Made by Donner Kahl · UNLISTED (SHOWN IN POOLS)

Become familiar with sensors and how to convert inputs into outputs, such as lights.

Created: November 9th, 2022

0

Outcome

There are three different outcomes.

First, one set of code lights up a led light based on the brightness measured by the photoresistor. As the amount of light increases, the led brightness increases.

The second outcome reverses the interaction between the photoresistor and the led light: the light increases and the led darkens.

Finally, the led light reacts to a binary input from the photoresistor. If the photoresistor depicts the light dips below a defined threshold, the led light turns on. 

0
//#1 and #2

int snsr_light = A0;
int light_reading = 0;
int led = D2;
int led_bright = 0;

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

Particle.variable("light sensor",&light_reading,INT);

}

void loop() {

light_reading = analogRead(snsr_light);
analogWrite(led,led_bright);

//#1 Brighter LED in brighter light
// led_bright = map(light_reading, 1500,4095,0,255);

//#2 Brighter LED in lower light
led_bright = map(light_reading, 1000,3000,255,0);

delay(100);


}

//#3
int snsr_light = A0;
int light_reading = 0;
int led = D2;
int led_bright = 0;

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

Particle.variable("light sensor",&light_reading,INT);

}

void loop() {

if (analogRead(snsr_light) < 1200)

    digitalWrite(led,HIGH);
    
else

    digitalWrite(led,LOW);

}
Click to Expand
x
Share this Project

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


Courses

Focused on
About

Become familiar with sensors and how to convert inputs into outputs, such as lights.