Hello! I'm planning to have a sensor read air flow(which is then printed out to a LCD display) where depending on the air flow value the motor speed is changed and the motor pumps a certain value of air
I was hoping someone can check my circuit, offer advice for safety and help with forming an override switch
Oh okayy then would two wires come out from the 5V? One being from the motor driver and one to the breadboard to power everything else? And thank you for your reply!!
A stationery supply house? All you need is pen and paper. I've started to use KiCad but that is for projects going to PCB. Everything else is hand drawn, here.
Just a suggestion, also edit your thread title to make it more explanatory and generic to attract help.
//SPIROMETER CONSTANTS
const int analogInPin = A1; // Analog input pin, connected to pressure sensor
const float ADC_mV = 4.8828125; // from Arduino ADC value to voltage in mV. 5V/1024
const float SensorOffset = 254; // analog read at rest *adc should = offset,in mV taken from datasheet 200to425
const float sensitivity = 4.413; // in mV per mmH2O taken from datasheet MPX5010DP
const float mmh2O_kpa = 0.00981; // convert from mmH2O to kPa 0.00980665
const float kPa_Pa = 1000; // convert from kPa to Pa
const float tubeArea_L = 0.000404707; // Larger inlet diameter is 22.7mm= 0.000404707 square Meters
const float tubeArea_S = 0.000029225; // Smaler venturi diameter is 6.1mm= 0.000029225 square Meters
const float sampleRate = 0.01 ; //in seconds = 100 readings per second
const int trigger = 177; // trigger value to start volume count. (useing FlowRate_ml should be177?)is 127 after shield cable
const float P = 1.225; // Density of air @ ISA@15c@ sealevel@QNH. 1.225 KG/m3! .To do, correcting via input sensors!!!
float pressure_pa = 0; //
float volumetricFlowRate = 0; // M^3/s
float TotalVolume_ml = 0; // flow rate totalized over time
float FlowRate_ml = 0; // cm^3/s=ml/s
// initialise motor pins
int motor1pin1 = 2;
int motor1pin2 = 3;
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD
// Wiring: SDA pin is connected to A4 and SCL pin to A5.
// Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered)
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); // Change to (0x27,20,4) for 20x4 LCD.
void setup() {
// Initiate the LCD:
lcd.init();
lcd.backlight();
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
// Enable A to Pin 9 of arduino for PWM
pinMode(9, OUTPUT);
}
void loop()
{
float pressure_pa = kPa_Pa *(( (analogRead(A1))* ADC_mV - SensorOffset) / sensitivity * mmh2O_kpa);// result in Pa. calibration to read Zero via SensorOffset
float volumetricFlowRate = tubeArea_L * (sqrt((2/P) * (pressure_pa/(sq(tubeArea_L/tubeArea_S)-1))));//= Q in M^3/s. https://en.wikipedia.org/wiki/Venturi_effect
float FlowRate_ml = volumetricFlowRate *1000000; // convert M^3/s*1000000 = cm^3/s=ml/s
//Serial.println(analogRead(A1));//test///////use for calibration////////////////////////////////////////////////////////////////////////////////////////////////////////
if(FlowRate_ml>trigger)// 176 was idle top with no filter capacitor. readjust after filter capacitors installed 124, see note below.
{
TotalVolume_ml = FlowRate_ml*sampleRate + TotalVolume_ml; // Total volume over time totalized?????for VolTotal
delay(sampleRate*1000);// *1000 to match sampleRate in milli seconds
Serial.println(TotalVolume_ml);
}
else
{
TotalVolume_ml = 0;// to get volume to read zero
}
// Print Air Flow to Display
lcd.setCursor(2, 0); // Set the cursor on the third column and first row.
lcd.print("Air Flow(ml): "); // Print the string "Air Flow""
lcd.setCursor(2, 1); //Set the cursor on the third column and the second row (counting starts at 0!).
// Waits for 1 second before printing value
delay(1000);
// Prints Air Flow on LCD
lcd.print(TotalVolume_ml,2);
// if input air flow exceeds normal tidal breath of 500ml, lower motor speed, standard breath cycle for abnormal breaths(higher)
if(TotalVolume_ml > 550) {
//Controlling speed (0 = off and 255 = max speed):
analogWrite(9, 100); //ENA pin
// Inhalation for 2 seconds
delay(2000);
//Controlling spin direction of motors:
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
// Exhalation for 1.5 seconds
delay(1500);
// otherwise higher motor speed, standard breath cycle
}else {
//Controlling speed (0 = off and 255 = max speed):
analogWrite(9, 255); //ENA pin
// Inhalation for 2 seconds
delay(2000);
//Controlling spin direction of motors:
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
// Inhalation for 2 seoond
delay(2000);
}
// exhalation is the 2 second interval of rest the microcontroller takes to obtain sensor readings
}
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
This driver will drop 1-2V from input voltage, so you will likely not be getting the full voltage at the pump.
You have named motor pins 1 and 2 but not the pin for PWM
float in the Arduino world has only 6-7 digits of precision. And double is the same as float in Arduino!
You have a number of variables in loop() that are actually constants.
You could move the constant part out of the formulas as much as possible and pre-compute them on another computer and plug in the results into this program. (It is possible that the compiler will be able to do this for you, depending on compiler, not guaranteed).
Instead of using floats, multiply the numbers by say 1,000,000 and do integer arithmetic (using long unsigned int)