Building on SparkFun’s Force Sensitive Resistor code, this tutorial demonstrates one method for enabling a pressure sensor response after a set threshold has been consistently sensed over a period of time. There are many applications for setting pressure response after a set duration has past. One application is distinguishing the difference between a person (who maybe me homeless) sleeping on a steam vent in the street and normal foot traffic in an urban environment for the purpose of delivering emergency response in extreme cold weather situations more efficiently.
Components:
Arduino Uno
Adafruit Square Force-Sensitive Resistor (FSR)
3.3KOhm -10KOhm Resistor
Circuit:
The circuit is very simple. One side of my FSR connects to 5v and other connects my analog pin o (A0), my resistor ( 10K Ohm) and then to ground.
How it works:
using the code for FSR it will use voltage and static resistor value to
calculate FSR resistance as grams of force pressure (weight): see figure below
In order to distinguish between someone who is sleeping on a steam vent and someone simply walking on it you will need to set a threshold value which will be calculated in grams in my case is set my threshold to 40823.3 (roughly 90lbs) assuming that is a fair weight for someone exposed to living on the street. Next I defined a value for how many times the sensor reading is equal to or greater than the threshold value ( int countAboveThreshold). finally I defined a constant value for when threshold has been match or passed enough to trigger the action from Office of homeless services or similar homeless advocacy group to intervene by setting (const int iterationsToHold) to 600 which is a value found by dividing 20mins by my 2second delay. When the countAboveThreshold and iterationsToHold . You can get creative in how you define your duration but for my particular focus 20mins is a good enough guess since average pedestrians are not likely to stand on grates for late long.
In the following Serial monitor read-out
I set my const int iterationsToHold to 6 for demonstration purposes
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
/****************************************************************************** Michael Cooley pressure sensor and duration for reaction This code is adapt from the following source: Force_Sensitive_Resistor_Example.ino Example sketch for SparkFun's force sensitive resistors (https://www.sparkfun.com/products/9375) Jim Lindblom @ SparkFun Electronics April 28, 2016 Create a voltage divider circuit combining an FSR with a 3.3k resistor. - The resistor should connect from A0 to GND. - The FSR should connect from A0 to 3.3V As the resistance of the FSR decreases (meaning an increase in pressure), the voltage at A0 should increase. Development environment specifics: Arduino 1.6.7 ******************************************************************************/ const int FSR_PIN = A0; // Pin connected to FSR/resistor divider // Measure the voltage at 5V and resistance of your 3.3k resistor, and enter // their value's below: const float VCC = 4.98; // Measured voltage of Ardunio 5V line const float R_DIV = 3230.0; // Measured resistance of 3.3k resistor void setup() { Serial.begin(9600); pinMode(FSR_PIN, INPUT); } const int threshold = 40823.3; //value for force in Grams( grams is defined later) roughly 90lbs int countAboveThreshold = 0; // counts how many long the threshold value is being match detected const int iterationsToHold = 600; // 20min/2sec (loopdelay)= 600. if the threshold is >= threshold then signal send const int loopDelay = 2000; void loop() { int fsrADC = analogRead(FSR_PIN); // If the FSR has no pressure, the resistance will be // near infinite. So the voltage should be near 0. if (fsrADC != 0) // If the analog reading is non-zero { // Use ADC reading to calculate voltage: float fsrV = fsrADC * VCC / 1023.0; // Use voltage and static resistor value to // calculate FSR resistance: float fsrR = R_DIV * (VCC / fsrV - 1.0); Serial.println("Resistance: " + String(fsrR) + " ohms"); // Guesstimate force based on slopes in figure 3 of // FSR datasheet: float force; float fsrG = 1.0 / fsrR; // Calculate conductance // Break parabolic curve down into two linear slopes: if (fsrR <= 600) force = (fsrG - 0.00075) / 0.00000032639; else force = fsrG / 0.000000642857; Serial.println("Force: " + String(force) + " g"); Serial.println(); if (force >= threshold) { countAboveThreshold += 1; } else { countAboveThreshold = 0; } if (countAboveThreshold == iterationsToHold) { Serial.println("person is resting on grate#X "); //Placeholder action to communicate with GSM sensor FONA-mini cellular SMS breakout } delay(loopDelay); } else { // No pressure detected } } |