Download presentation
Presentation is loading. Please wait.
1
Line Following Tips photoresistor circuits
photoresistors positioned near floor
2
DISCLAIMER & USAGE The content of this presentation is for informational purposes only and is intended for students attending Louisiana Tech University only. The authors of this information do not make any claims as to the validity or accuracy of the information or methods presented. Any procedures demonstrated here are potentially dangerous and could result in damage and injury. Louisiana Tech University, its officers, employees, agents and volunteers, are not liable or responsible for any injuries, illness, damage or losses which may result from your using the materials or ideas, or from your performing the experiments or procedures depicted in this presentation. The Living with the Lab logos should remain attached to each slide, and the work should be attributed to Louisiana Tech University. If you do not agree, then please do not view this content. boosting application-focused learning through student ownership of learning platforms
3
Add extensions to photoresistors
while you may eventually choose to use two photoresistors, you only need one to get started.
4
Review of photoresistor implementation
int analogPin = 4; // 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 5V analog input 4 photoresistor 10kW The “voltage” sensed at analog pin 4 is sent to the Serial Monitor for viewing. Here, an output of 0 represents 0V and 1023 represents 5V.
5
Try different resistors to see which value gives the best response
Experiment with circuit & photoresistor placement void setup() { Serial.begin(9600); } void loop() { int val = analogRead(2); Serial.println(val); 5V analog input 2 photoresistor R 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? Try different resistors to see which value gives the best response
6
Photoresistor output variation
void setup() { Serial.begin(9600); } void loop() { int val = analogRead(2); Serial.println(val); Consider the possible output values of your photoresistor setup: 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.
7
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 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 1 2 3 4
8
Simple left-edge line following program
#include <Servo.h> 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() { myservo2.writeMicroseconds(1520); } void slow_left() { myservo1.writeMicroseconds(1480);
9
Hints/tips to get you started:
Class Problem: Using the mats provided program your Arduino to travel forward until the photoresistor detects the black line. Once the black line is detected, program your Arduino to immediately stop. Hints/tips to get you started: What is the analog value read by your Arduino when it sees the mat versus the black line? Use the servo library and/or functions to help with motion.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.