In this version, we were able to build a working prototype of our Elevate table. The table was able to sense pressure applied to a top panel and activate and LED and the stepper motor, which in turn, raises the panel. See demo video below.
Future improvements will aim to make the pressure sensing more consistent. Currently, we are using a small, circular FSR to detect pressure. To better detect all objects, we would use a large square FSR. Additionally, we would like to improve the quality of the panels by leveling the top of the table.
Code:
Master Arduino:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | // Include the Arduino Stepper.h library: #include <Wire.h> const int aA = 0; const int aX = 1; const int aY = 2; const int aZ = 3; const int ledA = 2; const int ledX = 3; const int ledY = 4; const int ledZ = 5; // Array for LEDs in following order [a,x,y,z] boolean loaded[4] = { false , false , false , false }; unsigned long lastDebounceTime = 0; // the last time the output pin was toggled unsigned long debounceDelay = 40; void setup() { Serial.begin(9600); Wire.begin(); pinMode(ledA, OUTPUT); pinMode(ledX, OUTPUT); pinMode(ledY, OUTPUT); pinMode(ledZ, OUTPUT); } void loop() { hardware_input_poll(); } void hardware_input_poll( void ) { poll_sensor(); } void poll_sensor(){ // Read the analog input. int aVal = analogRead(aA); int xVal = analogRead(aX); int yVal = analogRead(aY); int zVal = analogRead(aZ); transmit(aVal, 0); transmit(xVal, 1); transmit(yVal, 2); transmit(zVal, 3); poll_lights(); } void transmit( int value, int index){ if ( value >= 600 ) { if (!loaded[index]){ if ((millis() - lastDebounceTime) > debounceDelay){ loaded[index] = true ; Wire.beginTransmission(4); // transmit to device #4 Wire.write(index*2); Wire.endTransmission(); } lastDebounceTime = millis(); } } else { if (loaded[index]){ if ((millis() - lastDebounceTime) > debounceDelay){ loaded[index] = false ; Wire.beginTransmission(4); // transmit to device #4 Wire.write(index*2+1); Wire.endTransmission(); } lastDebounceTime = millis(); } } } void poll_lights() { if (loaded[0]){ digitalWrite(ledA, HIGH); } else { digitalWrite(ledA, LOW); } if (loaded[1]){ digitalWrite(ledX, HIGH); } else { digitalWrite(ledX, LOW); } if (loaded[2]){ digitalWrite(ledY, HIGH); } else { digitalWrite(ledY, LOW); } if (loaded[3]){ digitalWrite(ledZ, HIGH); } else { digitalWrite(ledZ, LOW); } } |
Stepper Driver Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | #define enable 8 #define xDir 5 #define yDir 6 #define zDir 7 #define aDir 13 #define xStep 2 #define yStep 3 #define zStep 4 #define aStep 12 #include <Wire.h> int aPrev = 1; int xPrev = 3; int yPrev = 5; int zPrev = 7; int steps = 3200; int stepDelay = 300; void setup() { Serial.begin(9600); pinMode(xDir,OUTPUT); pinMode(xStep,OUTPUT); pinMode(yDir,OUTPUT); pinMode(yStep,OUTPUT); pinMode(zDir,OUTPUT); pinMode(zStep,OUTPUT); pinMode(aDir,OUTPUT); pinMode(aStep,OUTPUT); pinMode(enable,OUTPUT); digitalWrite(enable,LOW); Wire.begin(4); // join i2c bus with address #4 Wire.onReceive(receiveEvent); } void loop() { delay(100); } void step ( bool dir, byte dirPin, byte stepperPin, int steps) { digitalWrite(dirPin,dir); delay(100); for ( int i = 0; i < steps; i++){ digitalWrite(stepperPin, HIGH); delayMicroseconds(stepDelay); digitalWrite(stepperPin, LOW); delayMicroseconds(stepDelay); } } void stepY ( bool dir){ if (dir) { step( true ,yDir,yStep, 800); delay(2000); } else { step( false , yDir, yStep, 800); delay(2000); } } void stepX ( bool dir){ if (dir) { step( true ,xDir,xStep, 800); delay(2000); } else { step( false , xDir, xStep, 800); delay(2000); } } void stepZ ( bool dir){ if (dir) { step( true ,zDir,zStep, 800); delay(2000); } else { step( false , zDir, zStep, 800); delay(2000); } } void stepA ( bool dir){ if (dir) { step( true ,aDir,aStep, 800); delay(2000); } else { step( false , aDir, aStep, 800); delay(2000); } } void receiveEvent( int howMany) { int x = Wire.read(); Serial.println(x); switch (x) { case 0: if (aPrev != x) { aPrev = x; stepA( false ); break ; } case 1: if (aPrev != x) { aPrev = x; stepA( true ); break ; } case 2: if (xPrev != x) { xPrev = x; stepX( false ); break ; } case 3: if (xPrev != x) { xPrev = x; stepX( true ); break ; } case 4: if (yPrev != x) { yPrev = x; stepY( false ); break ; } case 5: if (yPrev != x) { yPrev = x; stepY( true ); break ; } case 6: if (zPrev != x) { zPrev = x; stepZ( false ); break ; } case 7: if (zPrev != x) { zPrev = x; stepZ( true ); break ; } } } |
Leave a Reply
You must be logged in to post a comment.