Skills Dev II: Working with Inputs and Sensors

Made by Sohail Shaikh

Created: November 20th, 2022

0

Outcome

    • This project constitutes an FSR sensor (Force Sensitive Sensor), a switch for taking user input, and an LED for displaying the output. 
    • If the switch is set to ON and the user applies force on the FSR sensor, the LED starts blinking. The speed at which the LED blinks is dependent on the amount of force being applied to the FSR sensor. 
    • For this project, I have given 3 force ranges first force range- fsrReading greater than 50 and less than 1500, second force range-   fsrReading greater than 1500 and less than 3000, and the highest force range with fsrReading greater than 3000. 
    • The highest force of greater than 3000 will have the fastest LED blinking rate.
    • This project could be used in a number of devices where the weight or force applied needs to be tracked and the user needs to be alerted if incase high force is being applied to it.

0

Process

  • I initially started this project by exploring the various sensors present in the kit. Then I identified the use case for which I could use the FSR sensor. 
  • I then tried using the FSR sensor and understand the readings given from the FSR sensor.
  • Later, As I was working with the if condition, I realized that even if I don't apply pressure, the reading is giving up some value which ideally shouldn't be the case. Due to this I had to update the if condition and take values starting 50 onwards even though no pressure is being applied from user end. 
  • I also learned about giving range of values to perform an action using the & operand. 
  • While experimenting with the multiple conditions, I tweaked the LED speed i.e. reduced the delay with increase in fsrReading to differentiate how much pressure is being applied.

0

Reflection

  • In this project, I learnt on how I could work with two inputs. Also, I had used an Photoresistor sensor earlier, so working with the FSR sensor was new for me. This project also helped me understand the if and if else conditions and also, I learnt how to read values in between a range of values. 
0
// Define a pin that we'll place the FSR on
// Remember to add a 10K Ohm pull-down resistor too.
int fsrPin = A0;
// Create a variable to hold the FSR reading
int fsrReading = 0;
// Define a pin we'll place an LED on
int ledPin = D2;
// Create a variable to store the LED brightness.
int ledBrightness = 0;
int switchPin = D3;

void setup()
{
  // Set up the LED for output
  pinMode(ledPin, OUTPUT);
  pinMode( switchPin , INPUT_PULLUP); // sets pin as input
  Particle.variable("force", &fsrReading, INT);

}


void loop()
{
    
    int buttonState = digitalRead( switchPin );

  // Use analogRead to read from the sensor
  // This gives us a value from 0 to 4095
  fsrReading = analogRead(fsrPin);

    if(buttonState == HIGH){
        digitalWrite( ledPin, LOW);
    }
   else if( buttonState == LOW & fsrReading >50 & fsrReading <= 1500 )
    {
        digitalWrite( ledPin, HIGH);
        delay(1000);
        digitalWrite( ledPin, LOW);
        delay(1000);
    }
    else if (buttonState == LOW & fsrReading>1500 & fsrReading<=3000)
    {
        digitalWrite( ledPin, HIGH);
        delay(500);
        digitalWrite( ledPin, LOW);
        delay(500);
    }    
    else if (buttonState == LOW & fsrReading>3000)
    {
        digitalWrite( ledPin, HIGH);
        delay(100);
        digitalWrite( ledPin, LOW);
        delay(100);
    }       
    
 }
Click to Expand
0
x