/* Harvard University SEAS Course: ES227 Title: Soft Robotics KIT - Sample code V. 1.0 Creator: Panagiotis Polygerinos Date: January 2013 */ int regulator = 9; // Pressure regulator connected to digital pin 9 int flow = A0; // Select the analogue input pin for the flow sensor int pressure1 = A1; // Select the analogue input pin for pressure sensor 1 int pressure2 = A2; // Select the analogue input pin for pressure sensor 2 int potentiometer = A3; // Select the analogue input pin for potentiometer float sensorValue1 = 0; // Variable to store the value coming from the flow sensor float sensorValue2 = 0; // Variable to store the value coming from pressure sensor 1 float sensorValue3 = 0; // Variable to store the value coming from pressure sensor 2 float pot = 0; // Variable to store the value coming from potentiometer const int Valve1 = 2; // Select digital PIN 2 for valve 1 const int Valve2 = 3; // Select digital PIN 3 for valve 2 const int Valve3 = 4; // Select digital PIN 4 for valve 3 const int Valve4 = 5; // Select digital PIN 5 for valve 4 void setup() { Serial.begin(9600); // Initialize serial communications at 9600 bps pinMode(Valve1, OUTPUT); // Set digital PIN to output for valve 1 pinMode(Valve2, OUTPUT); // Set digital PIN to output for valve 2 pinMode(Valve3, OUTPUT); // Set digital PIN to output for valve 3 pinMode(Valve4, OUTPUT); // Set digital PIN to output for valve 4 pinMode(regulator, OUTPUT); // Set digital PIN as PWM output for Regulator } void loop() { // Read the value from potentiometer: pot = analogRead(potentiometer); // Read value from analogue input A3 // Read the value from Flow sensor: sensorValue1 = analogRead(flow); // Read value from analogue input A0 sensorValue1 = sensorValue1 * 0.0049; // Flow sensor calibration sensorValue1 = (sensorValue1-1.25)/0.75; // See datasheet of sensor for details Serial.print("\n\n Flow = " ); // Print message with the flow value Serial.print(sensorValue1); Serial.print(" SLPM " ); // Read the value from Pressure sensor 1: sensorValue2 = analogRead(pressure1); // Read value from analogue input A1 sensorValue2 = sensorValue2 / 204.6; // Pressure sensor calibration sensorValue2 = (sensorValue2 - 0.514)/0.04112; // See datasheet of sensor for details Serial.print("\n Pressure 1 = " ); // Print message with the pressure value Serial.print(sensorValue2); Serial.print(" PSI " ); // Read the value from Pressure sensor 2: sensorValue3 = analogRead(pressure2); // Read value from analogue input A2 sensorValue3 = sensorValue3 / 204.6; // Pressure sensor calibration sensorValue3 = (sensorValue3 - 0.514)/0.04112; // See datasheet of sensor for details Serial.print("\n Pressure 2 = " ); // Print message with the pressure value Serial.print(sensorValue3); Serial.print(" PSI " ); digitalWrite(Valve1, HIGH); // turn on/off valve 1 digitalWrite(Valve2, LOW); // turn on/off valve 2 digitalWrite(Valve3, LOW); // turn on/off valve 3 digitalWrite(Valve4, LOW); // turn on/off valve 4 analogWrite(regulator, pot/4); // analogRead values go from 0 to 1023, //analogWrite values from 0 to 255 // wait X milliseconds before the next loop. Adjust time according to your needs. delay(200); }