Inputs and Sensors
Made by Stephanie Ho
Made by Stephanie Ho
Created: November 9th, 2023
I built familiarity with several of the sensors, including the operations of:
I encountered several difficulties when trying to repeat the design and ultimately did not use the light sensor because it responded poorly and slowly. I adjusted the original code for a 300-4095 range and that worked the first time, but did not respond in subsequent tests.
int photoCellPin =A0;
int photoCellReading=0;
int ledPin=D2;
int ledBrightness=0;
void setup() {
pinMode(ledPin, OUTPUT);
Particle.variable("light",&photoCellReading, INT);
}
void loop() {
//analogRead reads the photocell, and gives a value from 0 to 4095
photoCellReading =analogRead (photoCellPin);
//We want to map this value into the PWM range of 0-255
ledBrightness =map(photoCellReading, 3000,4095,0,255);
//fade the LED to the desired brightness, sets the value
analogWrite(ledPin, ledBrightness);
//waits and then loops
delay(100);
}
Click to Expand
int flexSens =A0;
int YellowPin=D2;
int GreenPin=D3;
int ledBrightness;
int flexSensReading;
void setup() {
pinMode(YellowPin, OUTPUT);
pinMode(GreenPin, OUTPUT);
pinMode(flexSens, INPUT);
Particle.variable("power",&flexSensReading, INT);
}
void loop() {
//analogRead reads the sensor, and gives a value from 0 to 4095
flexSensReading =analogRead (flexSens);
//We want to map this value into the PWM range of 0-255
ledBrightness = map(flexSensReading, 0, 4095, 0, 255);
if(flexSensReading<=1000){
analogWrite(YellowPin, ledBrightness);
}
//fade the LED to the desired brightness, sets the value
else if (flexSensReading >2000){
analogWrite(YellowPin, ledBrightness);
analogWrite(GreenPin, ledBrightness);
}
//waits and then loops
delay(100);
digitalWrite(YellowPin, LOW);
digitalWrite(GreenPin, LOW);
}
Click to Expand
My learnings from this skill development are to 1) explore different ways to "bug test", such as testing a different sensor and 2) utilize the cloud readings as input to adjust the cloud. I spent a significant amount of time trying to understand the issue with the light sensor that may have been helpful testing something else!
A hands-on introductory course exploring the Internet of Things and connected product experiences.
~