Isha Hans - Skills Dev II

Made by ihans

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

Process

  • I had a hard time making any exercise work in the first go because of consistently dropping Wi-fi. But once that was fixed, it became much smoother work.
  • We learnt the void blinkLED function in Lab Session 4 which I decided to try out in this assignment for blinking the LED. I decided to use this in the loop as a part of conditional logic and write code on my own based on what I think might be logical. This kept giving me an error that I was unable to resolve on my own.


0

Reflection

  • The first time I was connecting, I had forgotten to use jumper wires to power the whole circuit. It's so easy to get caught up and excited about engaging with the input and output because of which I made multiple mistakes in setting up the circuit.
  • Writing code on your own without an exact reference is hard. I wanted to make sure I'm getting the basics right instead of just copying code and it took me multiple trials and errors and multiple hours, despite which I couldn't get it right. Following is the code I couldn't get to work, hence I decided to design something different for exercise. If you spot my mistake and know how to fix it, please comment and let me know.  
  • int flexPin = A0;

    int flexReading = 0;

    int ledPin = D2;

    int ledBrightness = 0;

    void setup() {

    pinMode(ledPin, OUTPUT);

    Particle.variable("snoopy", flexReading );

    }

    void loop() {

    flexReading = analogRead(flexPin);

    ledBrightness = map(flexReading, 0, 4095, 0, 255);

    analogWrite(ledPin, ledBrightness);

    delay(100);

    }

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() {
   potReading = analogRead( potPin );
   int brightness = map( potReading, 0, 4095, 0, 255 );
   analogWrite( ledPin, brightness );
   
   
    // int buttonReading = digitalRead( buttonPin);
    //  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 - https://youtu.be/PsI8pKkAXgA
0
Designing for IoT 2.2: Controlling brightness with potentiometer
Isha Hans - https://youtu.be/XIGKNxGHtxU
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("floopy", flexReading );
    Particle.variable("brightness", ledBrightness );

}


void loop() {
    int buttonState = digitalRead( switchPin );
    if( buttonState == LOW ) {
        digitalWrite( ledPin, HIGH);
        flexReading = analogRead(flexPin);
        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 - https://youtu.be/c0SDUmntKk4
x
Share this Project

Courses

Focused on
About

Learning about inputs, sensors and conditional logic for creating Outputs