# Isha Hans - Skills Dev II

Learning about inputs, sensors and conditional logic for creating Outputs

Created: November 10th, 2021

0

## Outcome

• Practice exercise for learning to use button and potentiometer
• A simple device for the table: DND and okay to disturb signal using flex sensor, Switch and LED.
0

0

## Reflection

0

Exercise 1: Controlling LED brightness with a Potentiometer

0
``````int ledPin = D2;
int buttonPin = D3;
int buttonState;

int potPin = A5;
int potReading = 0;

void setup() {
pinMode( buttonPin, INPUT_PULLUP);
pinMode( ledPin, OUTPUT);
}

void loop() {
int brightness = map( potReading, 0, 4095, 0, 255 );
analogWrite( ledPin, brightness );

//  int buttonState = digitalRead( buttonPin );
// if( buttonState == LOW) {
//     digitalWrite( ledPin, HIGH);
// }else{
//     digitalWrite( ledPin, LOW);
// }

delay( 500 );

}``````
Click to Expand
0
Designing for IoT 2.1: using a button for controlling an LED
Isha Hans
0
Designing for IoT 2.2: Controlling brightness with potentiometer
Isha Hans
0

Exercise 2: Using Flex Sensor to indicate availability

Use Scenario

When I'm working on my desk in the studio, I often get disturbed by peers wanting to chat or ask a question. This sometimes breaks my flow of work and I would really appreciate a subtle way of communicating when is it okay for someone to disturb me and when it's an absolute DND. Therefore, I hope to design a phone holder that gives out warnings when I pick up the phone.

Input:

- Switch: turn the light system on/off

- Flex Sensor (FSR): sense the bend

Output:

- Switch: turn the light system on/off

- (when the flex sensor is bent halfway): low brightness of LED

- (when the flex sensor is all the way): high brightness of LED

0
``````int flexPin = A0;
int flexReading = 0;
int ledPin = D2;
int ledBrightness = 0;
int switchPin = D3;

void setup() {
pinMode( switchPin , INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
Particle.variable("brightness", ledBrightness );

}

void loop() {
int buttonState = digitalRead( switchPin );
if( buttonState == LOW ) {
digitalWrite( ledPin, HIGH);
ledBrightness = map(flexReading, 100, 1500, 0, 255);
analogWrite(ledPin, ledBrightness);
delay(500);
}else{
digitalWrite( ledPin, LOW);
}

}``````
Click to Expand
0
Designing for IoT 2.3: Convey availability using flex sensor, switch and led
Isha Hans