
The IR sensor consists of an individual IR LED and an IR Photodiode. If necessary you must adjust the delays for the required turn angle depending of your motors (also, sometimes left and right pulse values should be a little bit different to compensate any lack of balance of the motors.
#Line follower arduino while loop full#
The code bellow, can be used as a base for a complete motor test (Forward, Backward, Full stop, Turn Left, Turn Right). Before that, the program will be stopped in the infinite loop. Note that the 2 lines that will command the Robot to turn LEFT, wait 500ms and turn RIGHT only will happen after you press the button (buttonPin = 0). This button is very useful for test purposes and for robot's start.įor example: while(digitalRead(buttonPin)) Left Servo forward speed goes from 1,500us (stopped) to 1,000 (full speed)Īn external LED is add to pin13, for signalization and test purposes (you can use the internal Arduino LED, instead an external if you want, but take in consideration that will be hard to see it in the middle of the cables).Īlso a button is connected to pin 9.Right Servo forward speed goes from 1,500us (stopped) to 2,000us (full speed).Note that due the way that the servos are mounted (in opposition) the speed range is: Connect the Servos to Arduino: LEFT => Pin 5 RIGHT => Pin 3.Connect the GND of Power Grid to Arduino GND.Connect the Arduino Nano to the breadboard.

Connect the Battery to be used with servos: Left one of lateral power grid exclusively for servos source.This set of battery will be installed between the breadboard and the body frame. The Power Supply for the motors will come from one of the 5V set of batteries.Fix the Ball Caster using the Binder Clip.Adjust the length of the platform to your needs. Fix the 2nd squared wood to the above one using the Binder Clips.With the 3M Command frame strip, fix the 2 Servos to the one of the squared wood piece.The Arduino code bellow can do the job: #include // Servo library NOTE: If your servo does not have this phisical adjustment, try to change the parameter "1500" microsecond inside the function (up or down) until you get the full stop. If not, the servos must be adjusted to full stop (look for the yellow bolt, bellow the servo). Once all connected, the first thing that must be done, is to send a 1.5ms pulse to verify if the motors are "stopped" (not running). Once you have both servos physical connected, follow the drawing circuit above to source them (external 5V or 6V) and feed them with Arduino's signal: Pulse between 1.0 and 1.5ms or 1.5ms and 2.0ms, will generate proportional speed.A pulse of 2.0ms full speed in the opposite direction.A pulse of 1.0ms will command the servo to full speed (around 70 RPM) in one direction.A pulse of 1.5ms will position the servo at neutral position, or ”stopped”.

Other servos can work with different pulse width. For this specific servo, the pulse width goes from 1.0ms (1,000 microseconds) to 2.0ms (2,000 microseconds). Those servos will run on a given speed, defined by the pulse width received on its data input.

They will be "glued" together making a single and solid block as you can see at the photo (use the 3M Command strip, glue or double face tape). For motors, 2 continuous servos (SM-S4303R) were used.
