Electronics and Line Follower Theory

28
By RoboSpecies

description

basics of arduino

Transcript of Electronics and Line Follower Theory

By RoboSpecies

Basic Shield

Pinout..!

Blink led’s on Basic Shield Connect shield to Arduino board.

Connect Vcc and Gnd of Basic Shield to 5V and Gnd of Roboduino

So to blink LED’s 1&2 on Shield use Digital Pins 8&9 of Arduino in Program.

Connect pins 1&2 below LED’s to 8&9 digital pins of your Roboduino with F-F wire.

You can connect any LED pins to any digital pin of your choice.

Now Program to blink one LED at a time.

void setup()

{

pinMode(8, OUTPUT); // Initialize digital 8 pin as output

pinMode(9, OUTPUT); // Initialize digital 9 pin as output

}

void loop() {

digitalWrite(8, HIGH); // set the LED 1 on

digitalWrite(9, LOW); // set the LED 2 off

delay(1000); // wait for a second

digitalWrite(8, LOW); // set the LED 1 off

digitalWrite(9, HIGH); // set the LED 2 on

delay(1000); // wait for a second

}

Blink led using push button Push button is a sensor which takes input.

Pressed or Released.

Blink LED when pressed.

LED off when released.

Connect Switch Pin 1 of Basic Shield to Digital Pin 9 of Roboduino and LED pin1 to Digital pin 10 with F-F wire

You can connect any Switch from Basic Shield to any Digital pin of Roboduino Board.

Now Program to blink LED 1 with switch 1.

Program It..! int buttonpin = 9;

int ledpin = 10;

int buttonstate = 0; // variable for reading the

pushbutton status

void setup() {

pinMode(ledpin, OUTPUT);

pinMode(buttonpin, INPUT);

}

void loop()

{

// read the state of the pushbutton value:

buttonstate = digitalRead(buttonpin);

// check if the pushbutton is pressed.

// if it is, the buttonState is HIGH:

if (buttonstate == HIGH)

{

// turn LED on:

digitalWrite(ledpin, HIGH);

}

else

{

// turn LED off:

digitalWrite(ledpin, LOW);

}

}

IR Sensors

Emitter (Transmitter)

Detector (Receiver)

How does IR sensor works? How does it identify Black & White Surface??

Today’s IR Sensor

Motor Driver Board

IR Sensor Calibration Connect Batteries to Motor Driver Board.

Connect Vcc & Gnd of IR Sensor to Vcc and Gnd pins of Motor Driver.

Now calibrate with the help of Variable Resistor on IR Sensor.

Calibrate on Black and White surface such that Red LED on IR Sensor Blinks when on white and is off when on black surface.

Motor Driver L-293D

To control Speed and Direction of DC Motors.

16 Pin IC

Pinout

Connections

Truth Table

Input A

Input B

Motor State

LOW

LOW

Braking occurs

HIGH

LOW

Turns Clockwise

LOW

HIGH

Turns Anti-Clockwise

HIGH

HIGH

Braking Occurs

Program to run a motor Check the Data Sheet for connections of L 293D to

Motor Driver Board

For Motor 1

Enable Pin 1 of L 293D to 2 Digital Pin of Arduino

Input1 Pin 2 of L 293D to 3 Digital Pin of Arduino

Input2 Pin 7 of L 293D to 4 Digital Pin of Arduino

For Motor 2

Enable Pin 9 of L 293D to 5 Digital Pin of Arduino

Input1 Pin 10 of L 293D to 6 Digital Pin of Arduino

Input2 Pin 15 of L 293D to 7 Digital Pin of Arduino

Program to run motor using push button

int switchpin = 9; // switch input

int motor1pin1 = 3; // pin 2 on L293D

int motor1pin2 = 4; // pin 7 on L293D

void setup()

{

// set the switch as an input:

pinMode(switchpin, INPUT);

// set all the other pins you're using as outputs:

pinMode(motor1pin1, OUTPUT);

pinMode(motor1pin2, OUTPUT);

}

void loop()

{

// if the switch is high, motor will turn on one direction:

if (digitalRead(switchpin) == HIGH)

{

digitalWrite(motor1pin1, HIGH); // set pin 2 on L293D high

digitalWrite(motor1pin2, LOW); // set pin 7 on L293D low

}

// if the switch is low, motor will turn in the opposite direction:

else

{

digitalWrite(motor1pin1, LOW); // set pin 2 on L293D low

digitalWrite(motor1pin2, HIGH); // set pin 7 on L293D high

}

}

Summary

You learned to Blink LED’s.

You Learned to control DC motor, and change its direction.

You learned to use IR Sensors and calibrate them.

Integrate it and write the program for Line-Follower..!!

Line-Follower Concept

When both left and right sensor are sensing white, means black line is in between and bot goes forward.

When Right sensor senses black means a Right Turn. Turn off the Right Motor so that it turns Right until Right Sensor senses white again.

Similarly for Left turn.

Line-Follower Robot.

Program It…! int motor1Pin1 = 3; // pin 2 on L293D

int motor1Pin2 = 4; // pin 7 on L293D

int motor2Pin1 = 6; // pin 10 on L293D

int motor2Pin2 = 7; // pin 15 on L293D

int sensor1 = 10;

int sensor2 = 11;

int sensorstate1 = 0;

int sensorstate2 = 0;

void setup() {

// initialize the digital pin as an output.

pinMode(10, INPUT);

pinMode(11, INPUT);

pinMode(motor1Pin1, OUTPUT);

pinMode(motor1Pin2, OUTPUT);

pinMode(motor2Pin1, OUTPUT);

pinMode(motor2Pin2, OUTPUT);

}

void loop() {

sensorstate1 = digitalRead(sensor1);

sensorstate2 = digitalRead(sensor2);

if (sensorstate1 == HIGH) {

digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D High

digitalWrite(motor1Pin2, LOW);

}

else {

digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D low

digitalWrite(motor1Pin2, LOW);

}

if (sensorstate2 == HIGH) {

digitalWrite(motor2Pin1, HIGH); // set pin 10 on L293D High

digitalWrite(motor2Pin2, LOW);

}

else {

digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low

digitalWrite(motor2Pin2, LOW);

}

}

Thank you..!