-
Notifications
You must be signed in to change notification settings - Fork 0
/
steadymate.ino
113 lines (80 loc) · 1.71 KB
/
steadymate.ino
1
/*CIPA Bracelet, Kelvin Cui 2019*/#include <SoftwareSerial.h>int rLED = 5;int yLED = 6;int buzzer = 9;int thermistor = 0;int vibration = 7;String input;float T;void setup() { pinMode(rLED,OUTPUT); pinMode(yLED,OUTPUT); pinMode(buzzer,OUTPUT); pinMode(vibration,OUTPUT); Serial.begin(9600); }void loop() { T = thermistorRead(thermistor); Serial.println(T); if ((T > 36) and (T <= 40)) { caution(); } else if (T > 40) { Serial.println(1000); critical(); } delay(1000); } void caution(){ analogWrite(yLED,255); digitalWrite(vibration,HIGH); tone(buzzer,5000); delay(250); analogWrite(yLED,0); noTone(buzzer); delay(250); analogWrite(yLED,255); tone(buzzer,5000); delay(250); analogWrite(yLED,0); digitalWrite(vibration,LOW); noTone(buzzer); delay(750); }void critical() { analogWrite(rLED,255); digitalWrite(vibration,HIGH); tone(buzzer,7000); delay(100); analogWrite(rLED,0); noTone(buzzer); delay(100); analogWrite(rLED,255); tone(buzzer,7000); delay(100); analogWrite(rLED,0); noTone(buzzer); delay(100); analogWrite(rLED,255); tone(buzzer,7000); delay(100); analogWrite(rLED,0); noTone(buzzer); digitalWrite(vibration,LOW); delay(200); }float thermistorRead(int Tpin) { int Vo; float logRt,Rt,T; float R = 9870; // fixed resistance, measured with multimeter// c1, c2, c3 are calibration coefficients for a particular thermistor float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07; Vo = analogRead(Tpin); Rt = R*( 1024.0 / float(Vo) - 1.0 ); logRt = log(Rt); T = ( 1.0 / (c1 + c2*logRt + c3*logRt*logRt*logRt ) ) - 267.15;return T;}