Yuchuan Shan – Skills Dev II

Made by Yuchuaun Shan

Working with Inputs and Sensors

Created: November 10th, 2021

0

Phone holder that reminds people to limit smartphone usage

Use Scenario

When I'm working, sometimes I would start checking my phone mindlessly before realizing a long time has passed. Therefore, I hope to design a phone holder that gives out warnings when I pick up the phone.

Input: 

- Force Sensitive Resistor (FSR): sense the weight of a smartphone

- Switch: turn the light system on/off

Output:

- (when a phone is sensed on the holder): blue LED on / red LED off

- (when a phone is NOT sensed on the holder): red LED on / blue LED off

0
SkillsDev2
Yu Chuan Shan - https://youtu.be/AYHCEENLe74
0
// Define a pin that we'll place the pot on
int potPin = A5;

// Create a variable to hold the pot reading
int potReading = 0;

// Define a pin we'll place an LED on
int ledPin = D2;

// Create a variable to store the LED brightness.
int ledBrightness = 0;

// Switch is wired to D3
int switchPin = D3;

//
void setup(){

  // Set up the LED for output
  pinMode(ledPin, OUTPUT);

  // Create a cloud variable of type integer
  // called 'light' mapped to photoCellReading
  Spark.variable("pot", potReading );
  
  // Define switch as an input-pullup
  pinMode(switchPin, INPUT_PULLUP);
}

void loop() {
    
   // find out if the button is pushed
   // or not by reading from it.
   int buttonState = digitalRead( switchPin );

  if ( buttonState == LOW ) {
    // turn the LED On and control brightness with potentiometer
        digitalWrite( ledPin, HIGH);
         // Use analogRead to read the potentiometer reading
         // This gives us a value from 0 to 4095
        potReading = analogRead(potPin);
        
        // Map this value into the PWM range (0-255)
        // and store as the led brightness
        ledBrightness = map(potReading, 0, 4095, 0, 255);
        
        // fade the LED to the desired brightness
        analogWrite(ledPin, ledBrightness);
        
        // wait 1/10th of a second and then loop
        delay(100);
        
    }else{
    // otherwise
    // turn the LED Off
        digitalWrite( ledPin, LOW);
    }

  
}
Click to Expand
0

Reflection

This exercise helped me become more familiar with how the FSR responds to pressure. Due to the size and shape of the FSR, it was more convenient for me to test it with finger press. And when I press on the FSR hard, the reading is usually a little above 2000. That helped me to determine the threshold to set for triggering the warning light. For next steps, it would be helpful to identify the range of readings that can be received from the weight of a real smartphone. 

x