Parts List
Arduino Uno (or compatible board)
Servo, high-torque 25kg-cm
Power Supply (5V, 4A)
Jumper wires
Screw terminals (x2)
2 potentiometers (10K)
20mm PVC pipe, 1m (cut into x6 235mm sections)
M3 nuts and bolts ( lengths: 10mm, 15mm)
M4 nuts and bolts (lengths: 20mm)
Arduino Code (for quick copying/pasting)
/* Ventilator Control
* Uses Sweep as starting code
* by BARRAGAN
* This example code is in the public domain.
*
* modified 8 Nov 2013
* by Scott Fitzgerald
* http://www.arduino.cc/en/Tutorial/Sweep
*
* modified 25 Apr 2020
* by Wayne Smythe
*
* modified 1 Jun 2020
* by Brian Berletic
* servo pauses between delays in the resting position rather than compressing the bag
*
* Requirements: 2 adjusting knobs
* Air Volume Selection: 25%, 33%, 50%, 75%, 100% - determined by servo end position
* Rate of Compression: 6, 10, 14, 18, 24 cycles per minute (determined by delay)
* This requires 2 variable resistors connected to 5V and GND and to ANALOG IN pins 0 and 1 - I used 10K
*/
#include <Servo.h>
#define DEBUG 1
Servo myservo; // create servo object to control a servo
int pos = -70; // default -70: initialize the servo start position
int RateDelay = 2000; // default 2000: The delay used between strokes
int StopPosition = 150; //default 150: The stop position of the servo determining the volume of air
int potpinVol = 0; // analog pin used to connect the 10K potentiometer for volume
int potpinRate = 1; // analog pin used to connect the 10K potentiometer for rate
int val0; //variable to read the value from the analog pin
int val1; // variable to read the value from the analog pin
void setup() {
#ifdef DEBUG
Serial.begin(9600); // BaudRate for debug
#endif
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop(){
/* Number of Compressions per Minute
* rate of compression: 6, 10, 14, 18, 24, cycles per minute
* read the position of the Rate knob to determine the rate
*/
val1 = analogRead(potpinRate); // reads the value of the potentiometer
val1 = map(val1, 0, 1023, 0, 100);
#ifdef DEBUG
Serial.print("\t Delay map value = ");
Serial.print(val1);
#endif
if (val1>=0 && val1<=20)
{
RateDelay = 10000; // default 10000
}
else if(20<val1 && val1<=40)
{
RateDelay = 6000; // default 6000
}
else if(40<val1 && val1<=60)
{
RateDelay = 4286; // default 4286
}
else if(60<val1 && val1<=80)
{
RateDelay = 1500; // default 3333
}
else
{
RateDelay = 1000; // default 2500
}
#ifdef DEBUG
Serial.print("\n RateDelay = ");
Serial.print(RateDelay);
#endif
val0 = analogRead(potpinVol);
#ifdef DEBUG
Serial.print("\t pot value = ");
Serial.print(val0);
#endif
val0 = map(val0, 0, 1023, 0, 180);
#ifdef DEBUG
Serial.print("\t map value = ");
Serial.print(val0);
#endif
if (val0>=0 && val0<=36)
{
StopPosition = 30;
}
else if(36<val0 && val0<=72)
{
StopPosition = 60;
}
else if(72<val0 && val0<=108)
{
StopPosition = 90;
}
else if(108<val0 && val0<=144)
{
StopPosition = 120;
}
else
{
StopPosition = 170;
}
#ifdef DEBUG
Serial.print("\n Stop Position = ");
Serial.print(StopPosition);
#endif
for (pos = -70; pos <= StopPosition; pos += 1) { // goes from 0 to 180 degrees
myservo.write(pos);...