Last active
April 8, 2020 17:46
-
-
Save wolframalexa/17dba05e03405ea6272a075b01c95b4e to your computer and use it in GitHub Desktop.
Arduino code for the Columbia DIY Ventilator Challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int bpm = 30; // breaths per minute; can be changed by clinician | |
// sensors | |
int presLimit = 100; // [g], limit for pressure sensor | |
int colorLimit = 200; // limit for color sensor | |
int FSRSeries = 10000; // resistor value in series w/ FSR | |
float presLimitVoltage = FSRSeries/(FSRSeries + 8000); | |
float colorLimitVoltage = (colorLimit/256)*5; | |
float presVoltage = 0; | |
int redValue = 0; | |
int previousRed = 0; | |
// motor specs | |
float wormGear = 1/4; | |
int gearbox = 40; | |
int noloadRPM = 150; | |
int MotorPWM = (255*bpm/(noloadRPM*wormGear)); | |
// color sensor pins | |
#define greenPin A2 | |
#define redPin A3 | |
#define bluePin A1 | |
#define FSRPin A4 | |
#define SpeakerPin 1 | |
#define MotorInput 2 | |
// buttons | |
#define upButton 8 | |
#define downButton 9 | |
#define EStop 10 | |
void setup() { | |
digitalWrite(SpeakerPin, LOW); | |
pinMode(MotorInput, OUTPUT); | |
} | |
void loop() { | |
// motor control using PWM | |
analogWrite(MotorInput, MotorPWM); | |
// read pressure from FSR: voltage divider | |
presVoltage = FSRSeries/(FSRSeries + A4); | |
// read color from sensor | |
redValue = redPin; | |
if ((redValue > colorLimitVoltage) and (previousRed > colorLimitVoltage) | |
or (presVoltage < presLimitVoltage) or (EStop == LOW)) { | |
// if the color sensor detects red for two consecutive cycles, | |
// the manometer has been in the low position too long | |
// or, if the bag is no longer being pressed into the table, | |
// there's a leak | |
tone(SpeakerPin, 440, 1000); // plays A440 | |
} | |
if (downButton == LOW){ | |
bpm -= 1; | |
} | |
if (upButton == HIGH){ | |
bpm +=1; | |
} | |
previousRed = redValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment