├── .gitignore ├── README.md ├── arduino ├── calibrate_flex.ino ├── test_haptic.ino ├── bend_sense.ino └── posture.ino └── compute └── process.py /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Biosense 2 | 3 | ## Introduction 4 | 5 | Posture and repetitive stress syndrome detection kit. The code is mostly on Arduino platform. 6 | 7 | ## Hardware 8 | 9 | * Arduino UNO 10 | * Flex Sensor 11 | * Resistances 12 | 13 | ## 14 | 15 | Code developed during MIT DI Workshop 2013, PESIT. -------------------------------------------------------------------------------- /arduino/calibrate_flex.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Code to calibrate the different flex sensor bendings 3 | */ 4 | 5 | int flexPin; 6 | int flexVal; 7 | 8 | void setup() { 9 | Serial.begin(9600); 10 | flexPin = 0; 11 | } 12 | 13 | void loop() { 14 | while(Serial.available()) { 15 | Serial.read(); 16 | flexVal = analogRead(flexPin); 17 | Serial.println(flexVal); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /arduino/test_haptic.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Tests the haptic sensor 3 | */ 4 | int hapticPin; 5 | 6 | void setup() { 7 | Serial.begin(9600); 8 | hapticPin = 13; 9 | pinMode(hapticPin, OUTPUT); 10 | } 11 | 12 | void loop() { 13 | while(Serial.available()) { 14 | Serial.read(); 15 | digitalWrite(hapticPin, HIGH); 16 | delay(2000); 17 | digitalWrite(hapticPin, LOW); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /arduino/bend_sense.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Code sense bending movements in posture 3 | */ 4 | 5 | int flexPin; 6 | int flexVal; 7 | int hapticPin; 8 | 9 | void setup() { 10 | // Serial.begin(9600); 11 | flexPin = 0; 12 | hapticPin = 13; 13 | pinMode(hapticPin, OUTPUT); 14 | } 15 | 16 | void loop() { 17 | flexVal = analogRead(flexPin); 18 | if(flexVal < 360) { 19 | digitalWrite(hapticPin, HIGH); 20 | delay(500); 21 | digitalWrite(hapticPin, LOW); 22 | } 23 | delay(300); 24 | } 25 | -------------------------------------------------------------------------------- /arduino/posture.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Code to communicate with Python on laptop and buzz 3 | */ 4 | 5 | int flexPin; 6 | int flexVal; 7 | int hapticPin; 8 | int counter; 9 | char buzz; 10 | 11 | void setup() { 12 | Serial.begin(9600); 13 | flexPin = 0; 14 | hapticPin = 13; 15 | counter=0; 16 | pinMode(hapticPin, OUTPUT); 17 | } 18 | 19 | void loop() { 20 | flexVal = analogRead(flexPin); 21 | Serial.println(flexVal); 22 | while(Serial.available()){ 23 | Serial.read(); 24 | digitalWrite(hapticPin, HIGH); 25 | delay(1000); 26 | digitalWrite(hapticPin, LOW); 27 | } 28 | delay(1000); 29 | } 30 | -------------------------------------------------------------------------------- /compute/process.py: -------------------------------------------------------------------------------- 1 | # Code to do the processing of wrong posture across a timeframe 2 | 3 | import csv, serial 4 | 5 | # initializing some stuff 6 | ser = serial.Serial("/dev/ttyACM0", 9600) 7 | csvfile = open("data.csv", 'wb') 8 | csvwriter = csv.writer(csvfile, delimiter = ',', quotechar='"', quoting = csv.QUOTE_MINIMAL) 9 | csvwriter.writerow(["sl_no", "flexVal", "buzzed"]) 10 | 11 | num = 1 # reference value for first reading 12 | counter = 0 # initial value of counter 13 | limit = 10 # tolerance value for counter 14 | threshold = 420 # threshold value, below this we should buzz 15 | 16 | # main program loop 17 | ser.flushInput() 18 | while(ser.isOpen()): 19 | val = int(ser.readline()[:3]) 20 | # track the bad posture 21 | if(val < threshold): 22 | counter = counter + 2 23 | 24 | # if the bad posture is prolonged, send the buzz 25 | if(counter > limit): 26 | ser.write('1') 27 | csvwriter.writerow([num, val, 1]) 28 | counter = 0 29 | else: 30 | csvwriter.writerow([num, val, 0]) 31 | # if the posture is good, then reverse the effect of bad posture 32 | else: 33 | if(counter > 0): 34 | counter = counter - 1 35 | csvwriter.writerow([num, val, 0]) 36 | num = num + 1 37 | 38 | ser.close() 39 | --------------------------------------------------------------------------------