project F:Arduino/Movement AirPressure
From student
(Difference between revisions)
Line 6: | Line 6: | ||
void setup() { | void setup() { | ||
Serial.begin(9600); | Serial.begin(9600); | ||
− | + | ||
pinMode(10, OUTPUT); // air IN, more air | pinMode(10, OUTPUT); // air IN, more air | ||
pinMode(11, OUTPUT); // air OUT | pinMode(11, OUTPUT); // air OUT | ||
Line 17: | Line 17: | ||
int sensorValue1 = analogRead(A1); | int sensorValue1 = analogRead(A1); | ||
+ | // check the movement sensor | ||
if (sensorValue1 >= 400 ) { | if (sensorValue1 >= 400 ) { | ||
isMovement = 1; | isMovement = 1; | ||
Line 28: | Line 29: | ||
Serial.print(" "); | Serial.print(" "); | ||
− | if (isMovement == 1 && airPressure < pressureMax) { | + | // movement found, and pressure not too high -> add more pressure |
− | airPressure += 10; | + | if (isMovement == 1 && airPressure < pressureMax) { |
+ | airPressure += 10; | ||
digitalWrite(10, HIGH); | digitalWrite(10, HIGH); | ||
digitalWrite(11, LOW); | digitalWrite(11, LOW); | ||
Line 35: | Line 37: | ||
Serial.print(" Blow "); | Serial.print(" Blow "); | ||
} | } | ||
+ | |||
+ | // no movement, and pressure higher that minimum -> let air out | ||
else if (isMovement == 0 && airPressure > pressureMin) { // no movement | else if (isMovement == 0 && airPressure > pressureMin) { // no movement | ||
airPressure = airPressure - 1; //vähennä painetta | airPressure = airPressure - 1; //vähennä painetta | ||
Line 42: | Line 46: | ||
Serial.print(" Suck "); | Serial.print(" Suck "); | ||
} | } | ||
+ | |||
+ | // otherwise close the valves, wait | ||
else { | else { | ||
digitalWrite(10, LOW); | digitalWrite(10, LOW); |
Latest revision as of 11:09, 21 December 2011
int airPressure = 1; int pressureMin = 5; int pressureMax = 255; void setup() { Serial.begin(9600); pinMode(10, OUTPUT); // air IN, more air pinMode(11, OUTPUT); // air OUT pinMode(9, OUTPUT); // airPressure pinMode(1, INPUT); // movement } void loop() { boolean isMovement = 0; int sensorValue1 = analogRead(A1); // check the movement sensor if (sensorValue1 >= 400 ) { isMovement = 1; } else { isMovement = 0; } Serial.print(isMovement); Serial.print(" "); Serial.print(airPressure); Serial.print(" "); // movement found, and pressure not too high -> add more pressure if (isMovement == 1 && airPressure < pressureMax) { airPressure += 10; digitalWrite(10, HIGH); digitalWrite(11, LOW); delay(200); Serial.print(" Blow "); } // no movement, and pressure higher that minimum -> let air out else if (isMovement == 0 && airPressure > pressureMin) { // no movement airPressure = airPressure - 1; //vähennä painetta digitalWrite(11, HIGH); digitalWrite(10, LOW); delay(50); Serial.print(" Suck "); } // otherwise close the valves, wait else { digitalWrite(10, LOW); digitalWrite(11, LOW); delay(20); Serial.print(" Wait "); } airPressure = constrain(airPressure, pressureMin, pressureMax); analogWrite(9, airPressure); Serial.println(airPressure); }