Absolute Position Encoder and Photoresistor Reader Arm

Absolute Position Encoder and Photoresistor Reader Arm

Description

This is the absolute position encoder that I made into a wind vane in my last video. I ended up scrapping this idea in the interim because I think photoresistors alone won't work, at least not for me. To make this work, one would need to either calibrate the Arduino to recognize the current light conditions and adjust readings accordingly, or the device would need to provide its own light in some way, to make the readings much more distinct. The way that I plan to improve this design in the future is by adding lasers to an arm that goes on top of the disk. That way, there's no question about whether or not the area above the photoresistor is open. Find out more in my video: https://www.youtube.com/watch?v=MsWjWp4STqc Code for the encoder: int p0 = A0; int p1 = A1; int p2 = A2; int p3 = A3; int p4 = A4; int p5 = A5; int p0v; int p1v; int p2v; int p3v; int p4v; int p5v; void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: p5v = analogRead(A5); p4v = analogRead(A4); p3v = analogRead(A3); p2v = analogRead(A2); p1v = analogRead(A1); Serial.print(p5v); Serial.print(" "); Serial.print(p4v); Serial.print(" "); Serial.print(p3v); Serial.print(" "); Serial.print(p2v); Serial.print(" "); Serial.print(p1v); Serial.println(" "); int hi = p5v; int lo = p5v; if (hi < p4v){hi = p4v;} if (hi < p3v){hi = p3v;} if (hi < p2v){hi = p2v;} if (hi < p1v){hi = p1v;} if (p5v < lo){lo = p5v;} if (p4v < lo){lo = p4v;} if (p3v < lo){lo = p3v;} if (p2v < lo){lo = p2v;} if (p1v < lo){lo = p1v;} //Serial.print(hi); //Serial.print(" "); //Serial.println(lo); delay(10); //int median = (hi + lo)/2; //if (p5v > median){p5v = 16;}else{p5v = 0;} //if (p4v > median){p4v = 8;}else{p4v = 0;} //if (p3v > median){p3v = 4;}else{p3v = 0;} //if (p2v > median){p2v = 2;}else{p2v = 0;} //if (p1v > median){p1v = 1;}else{p1v = 0;} //Serial.println(median); //Serial.println(hi - lo); //int allSame = -1; //if (hi - lo < 250){ // if (median < 135){ // allSame = 0; // } // else if (median > 750){ // allSame = 1; // } // else{ // allSame = -1; // } //} //Serial.println(allSame); //Serial.println(allZero); //Serial.print(p5v); //Serial.print(" "); //Serial.print(p4v); //Serial.print(" "); //Serial.print(p3v); //Serial.print(" "); //Serial.print(p2v); //Serial.print(" "); //Serial.print(p1v); //Serial.println(" "); }

Statistics

Likes

0

Downloads

0

Category

Engineering