/* V1.0 * Made by: Daan Idsinga, Jordy vanvliet and Nienke Brouwer from Delft university of technology * This script will work with 2 hall sensors and a 8x8 Led matrix */ const int analogInPin1 = A0; // Input pin for sensor for flow to the left. const int analogInPin2 = A1; // Input pin for sensor for flow to the right. int sensorValue1 = 0; // variable to store the value of the sensor int sensorValue2 = 0; // variable to store the value of the sensor uint8_t colPins[8]={ 2, 3, 4, 5, 6, 7, 8, 9}; // For the 8x8 matrix // Definitions for 8x8 matrix #define SER_PIN 10 #define SCK_PIN 11 #define RCK_PIN 12 // Setup the Pin in's and out's void setup() { pinMode(analogInPin1, INPUT); // Declare the hall sensor left as an input in A0: pinMode(analogInPin2, INPUT); // Declare the hall sensor right as an input in A1: // Turn everything to low from 8x8 matrix for(int i=0; i<8; i++) { pinMode(colPins[i],OUTPUT); } pinMode(SER_PIN, OUTPUT); pinMode(SCK_PIN, OUTPUT); pinMode(RCK_PIN, OUTPUT); Serial.begin(9600); } void loop() { sensorValue1 = analogRead(analogInPin1); // read the value from the sensor left: delay(3); sensorValue2 = analogRead(analogInPin2); // read the value from the sensor right: // Flow to the right if (sensorValue1 < 565 && sensorValue1 > 480 && sensorValue2 < 900) { Serial.println("\t Flow to the right"); Serial.print(sensorValue1); Serial.print(','); Serial.print(sensorValue2); byte character[8]={0x18, 0x3c, 0x7e, 0xff, 0x3c, 0x3c, 0x3c, 0x3c}; // Led matrix Arrow to the right int rowbits = 0x80; for(int row=0; row<8; row++) { for(int k=0; k<8; k++) digitalWrite(colPins[k],HIGH); // Cleanup cols write595(rowbits); // prepare to write the row for(int col=0; col<8; col++) digitalWrite(colPins[7-col], character[row] & 1 << col ? LOW : HIGH); delay(1); write595(0); rowbits >>= 1; } } // Flow to the left else if ((sensorValue1 > 570 || sensorValue1 < 480) && sensorValue2 > 900) { Serial.println("\t Flow to the left"); Serial.print(sensorValue1); Serial.print(','); Serial.print(sensorValue2); byte character[8]={0x3c, 0x3c, 0x3c, 0x3c, 0xff, 0x7e, 0x3c, 0x18}; // LED matrix Arrow to the left int rowbits = 0x80; for(int row=0; row<8; row++) { for(int k=0; k<8; k++) digitalWrite(colPins[k],HIGH); // Cleanup cols write595(rowbits); // prepare to write the row for(int col=0; col<8; col++) digitalWrite(colPins[7-col], character[row] & 1 << col ? LOW : HIGH); delay(1); write595(0); rowbits >>= 1; } } // No flow Detected else if ((sensorValue1 > 570 || sensorValue1 > 480) && sensorValue2 < 900) { Serial.print(sensorValue1); Serial.print(','); Serial.print(sensorValue2); Serial.println("\t No Movement"); byte character[8]={0xc3, 0xe7, 0x7e, 0x3c, 0x3c, 0x7e, 0xe7, 0xc3}; //LED matrix Cross int rowbits = 0x80; for(int row=0; row<8; row++) { for(int k=0; k<8; k++) digitalWrite(colPins[k],HIGH); // Cleanup cols write595(rowbits); // prepare to write the row for(int col=0; col<8; col++) digitalWrite(colPins[7-col], character[row] & 1 << col ? LOW : HIGH); delay(1); write595(0); rowbits >>= 1; } } //Error both non_return valves are open else if (sensorValue1 < 565 && sensorValue1 > 480 && sensorValue2 > 900) { Serial.print(sensorValue1); Serial.print(','); Serial.print(sensorValue2); Serial.println("\t Error"); byte character[8]={0xff, 0xff, 0x7e, 0x3c, 0x18, 0x0, 0x18, 0x18}; //Led matrix Exlamation mark int rowbits = 0x80; for(int row=0; row<8; row++) { for(int k=0; k<8; k++) digitalWrite(colPins[k],HIGH); // Cleanup cols write595(rowbits); // prepare to write the row for(int col=0; col<8; col++) digitalWrite(colPins[7-col], character[row] & 1 << col ? LOW : HIGH); delay(1); write595(0); rowbits >>= 1; } } } void write595(byte data) { digitalWrite(RCK_PIN, LOW); shiftOut(SER_PIN, SCK_PIN, LSBFIRST, data); digitalWrite(RCK_PIN, HIGH); }