Presentation is loading. Please wait.

Presentation is loading. Please wait.

Line following tips photoresistors positioned near floor photoresistor circuits © 2011 LWTL faculty team living with the lab.

Similar presentations


Presentation on theme: "Line following tips photoresistors positioned near floor photoresistor circuits © 2011 LWTL faculty team living with the lab."— Presentation transcript:

1 line following tips photoresistors positioned near floor photoresistor circuits © 2011 LWTL faculty team living with the lab

2 add extensions to photoresistors while you may eventually use two photoresistors, you only need one to get started 2 living with the lab

3 review of photoresistor implementation int analogPin = 5; // middle terminal of voltage divider circuit int val = 0; // variable to store the value read void setup() { Serial.begin(9600); // setup serial display } void loop() { val = analogRead(analogPin); // read the input pin Serial.println(val); // print value to serial monitor } The “voltage” sensed at analog pin 5 is sent to the Serial Monitor for viewing. Here, and output of 0 represents 0V and 1023 represents 5V. 3 living with the lab 5V analog input 5 photoresistor 10k 

4 experiment with circuit & photoresistor placement void setup() { Serial.begin(9600); } void loop() { int val = analogRead(5); Serial.println(val); } photoresistor on analog pin 5 Move the robot with your hand so that the active photoresistor is over white and then over the black stripe. Make a note of the values sent to the serial monitor. Does it matter how far the photoresistor is from the ground level? R 5V analog input pin try different resistors to see which value gives the best response 4 living with the lab

5 photoresistor output variation void setup() { Serial.begin(9600); } void loop() { int val = analogRead(5); Serial.println(val); } Experimenting with your photoresistor in well lit conditions may result in consistent “white” and “black” output values. However, if you move to another environment, such as a dimly lit room, your “white” and “black” values would likely decrease (the way we have the circuit configured). To compensate for this variation, it is common practice to measure “white” and “black” values “on the fly” as your robot begins its mission. You could write a function that determines the “threshold” values for your robot. Consider the possible output values of your photoresistor setup: 5 living with the lab

6 Following the Left Edge of a Line Consider the case where we are following the left edge of a black line on a white background. One way to navigate along the edge of the line is to... Go forward and to the left when the photoresistor is over black Go forward and to the right when the photoresistor is over white 1 2 3 4 Considerations:  Robot path: how sharp should the robot turn as it moves forward?  Would it be possible to go straight when you are on the edge of the line? Possible Algorithm:  Go right if output > 520  Go straight if 440 < output < 520  Go left if output < 440 6 living with the lab

7 #include Servo myservo1; Servo myservo2; int white=520; // this number probably won't work for you int black=440; // this number probably won't work for you void setup() { myservo1.attach(2); myservo2.attach(3); Serial.begin(9600); } void loop() { int val = analogRead(5); Serial.print("white = "); Serial.print(white); Serial.print(" black = "); Serial.print(black); Serial.print(" val = "); Serial.println(val); if (val>white) {slow_right(); } // over white else if (val<black) {slow_left(); } // over black else {slow_forward(); } // over gray } void slow_forward() { myservo1.writeMicroseconds(1550); myservo2.writeMicroseconds(1450); } void slow_right() { myservo1.writeMicroseconds(1550); myservo2.writeMicroseconds(1520); } void slow_left() { myservo1.writeMicroseconds(1480); myservo2.writeMicroseconds(1450); } simple left-edge line following program 7 living with the lab


Download ppt "Line following tips photoresistors positioned near floor photoresistor circuits © 2011 LWTL faculty team living with the lab."

Similar presentations


Ads by Google