0

Line Robot - Basic lessons - Barrier

Light barrier in this robot consists of a highly directional LED and a photoresistor. The phototransistor outputs its signal and we can read it as analog value, which is smaller when a ball interrupts the light.
void RobotLine::loop() {
	if (analogRead(35) < 600)
		print("Ball\n\r");
	else
		print("\n\r");
}
analogRead() is Arduino function for reading analog values. Analog - it usually means numbers from 0 to 1023 or similar. Contrary to digital, which consists of just 2 values. The function has this form:
analogRead(pinNumber);
Our pin number is 35, therefore the command in the program has 35 as the argument. If the returned value is smaller than 600 (some other number may be good for Your case), that means that the light is interrupted, and the program will display "Ball".

Task: stop when ball found.

Put a ball 15 cm in front of the robot. Use terminal to lower "lift" servo and open "catch" servo, so that the arm is in catch-ready position. Terminal command is "ses". Write a program that will go towards the ball and stop when the ball is in the position where the arm can catch it.