Fit your backpack

Components:

  • 1 pot
  • 1 FSR
  • 1x 10KΩ resistor
  • 1x 220Ω resistor
  • jumper wires
  • USB cable
  • computer
  • Arduino Uno
  • Breadboard

Description

I created a program that lets you know if the weight of your backpack is well distributed among your two shoulders. In theory I should use  two FSR, one in each strap. However, since I only have one I am simulating one of them by using a POT.

The two analog signals are acquired by using the Arduino’s ADC, and then they are compared. The result of the comparison is sent to the computer via serial communication, and this information is used to show a graphical depiction of the situation.

Arduino code


int sensorF = A0; // select the input pin for the FSR
int sensorP = A1; // select the input pin for the POT

void setup() {
// declare the ledPin as an OUTPUT:

Serial.begin(9600); // Sets the data rate in bits per second (baud) for serial data transmission.
Serial.println(“WELCOME to the Sensor lab!”);
Serial.print(‘n’);
// analogWrite(redPin, 0);
// analogWrite(bluePin, 0);
// analogWrite(greenPin, 0);
}

void loop() {
int PotValue=0;
int FSRValue=0;
int x=0;
// read the values from the sensors:
PotValue = analogRead(sensorP);
FSRValue = analogRead(sensorF);
x = PotValue – FSRValue;

if (x > -265 && x < 256)
//Serial.println(“Igual”);
Serial.println(0);
else if (x > -265)
//Serial.println(“Izquierda”);
Serial.println(-1);
else
//Serial.println(“Derecha”);
Serial.println(1);

/* Serial.println(FSRValue);
Serial.print(“POT: “);
Serial.println(PotValue);
delay(1000); */
}

Processing code


import processing.serial.*; // Import the library for the serial communication. Serial library reads and writes data to and from external devices one byte at a time.
String portname = “COM4”; // or “COM5” //Providing the name of the serial port.
Serial port; //Creating an object (called “Port”) from the class “Serial”.
String buf=””; //Declare and initialize the object “buff” from the class “String”
int cr = 13; // ASCII carriage return == 13. A carriage return means moving the cursor to the beginning of the line. The code is r
int lf = 10; // ASCII linefeed == 10. Line feed: moving one line forward. The code is n.
int serialVal = 0; //declaring and initialize the variable “serialVal” where we will store the data read from the serial
PShape bot;
void setup() {
size(1024,1024); //Size of window
bot = loadShape(“pp.svg”);
port = new Serial(this, portname, 9600);
noStroke();
}
void draw(){
background(240,240,240);
shape(bot, 400, 200); // Draw at coordinate (280, 40) at the default size
textSize(48);
fill(36, 148, 245);
text(“Backpack FIT”, 350, 100);
if (serialVal==0)
{
textSize(24);
fill(8, 193, 30);
text(“Your back is safe. You are good to go”, 300, 900);
triangle(590, 300, 530, 300, 560, 350);
triangle(490, 300, 430, 300, 460, 350);
}
else if (serialVal==-1)
{
textSize(24);
fill(255, 0, 0);
text(“Fix the left strap of your backpack”, 310, 900);
triangle(590, 300, 530, 300, 560, 350);
}
else
{
textSize(24);
fill(255, 0, 0);
text(“Fix the right strap of your backpack”, 310, 900);
fill(255, 0, 0);
triangle(490, 300, 430, 300, 460, 350);
}
}
// called whenever serial data arrives
void serialEvent(Serial port) { //fromn the library. Called when data is available. Use one of the read() methods to capture this data.
int c = port.read(); //Returns a number between 0 and 255 for the next byte that’s waiting in the buffer. Returns -1 if there is no byte, although this should be avoided by first cheacking available() to see if data is available.
if (c != lf && c != cr) {
buf = buf + char(c); //If the value read is not lf nor keep reading the data.
}
if (c == lf) { //When done with the reading
serialVal = int(buf); // convert the string buf to int
println(“val=”+serialVal); //debugging
buf = “”; //Reset object to nothing
}
}

Leave a Reply