Sie sind auf Seite 1von 60

Welcomes You To

Workshop on Arduino
18th – 19th Feb
Gayatri Vidya Parishad
What Li2 Means

“Li2”
Listen Learn
Innovate Implement
Introduction to
Robotics
What is a ROBOT?
What is a ROBOT?
“A robot is an automatically
guided machine which is able to do
tasks on its own, almost always due
to electronically programmed
instructions. Another common
characteristic is that by its
appearance or movements, a robot
often conveys a sense that it
has intent or agency of its own.”

“A ROBOT is an
intelligent
MACHINE.”
Use of Robots
Four Ds of Robotics
1. Dirty
2. Dull
3. Dangerous
4. Difficult
Robot Anatomy
 Power Supply
 Mechanical System

 Actuators

 Sensors

 Data Processing Unit

 Control System
Why Arduino?
 Inexpensive

 Cross-platform

 Simple, clear programming environment

 Open Source and extensible software


MOUNTING
Motors
Attaching the Wheels
Mounting the Caster
H-Bridge
Arduino Board
PROGRAMMI
NG
Arduino Programming Structure
 Declaration:
variables and header files

 Initialization:
void setup()--- Runs only once at the
beginning.
 Looping:
void loop()--- Runs repeatedly forever
until power off or reset.
Digital Functions
 pinMode ()
This function configures the specified pin
to behave either as an input or an output.
This is written in void setup().

Syntax: pinMode (pin_num, Mode);


Mode: OUTPUT or INPUT
 digitalWrite ()
This functions sets a particular output pin
as either ‘HIGH’ or ‘LOW’. Its dynamically
used in the void loop().

Syntax: digitalWrite (pin_num, Value);


Value: HIGH or LOW
Time Functions
 delay()
This function pauses the program (gives a delay)
for a specified time interval in milliseconds.
Syntax: delay(milliseconds);

 delayMicroseconds()
This function creates a delay for a specified time
interval in microseconds.
Syntax: delayMicroseconds(microseconds);
PROBLEM Statement #1
LED Blinking

Step 1: LED should glow for


1 second
Step 2: IT should go off for 1
second
Step 3: Go to Step 1
LED Blink – Pseudo Code
Step 1: Declare variables if any

Step 2: Initialize
void setup() // Executes only once
{
// Set pin number 13 as output
}

Step 3: Logic in Loop


void loop() // Executes Forever
{
// Set the led ON
// Wait for a second

// Set the led OFF


// Wait for a second
}
LED Blink: Code

int ledPin = 13;

void setup()
{
pinMode(ledPin, OUTPUT); // sets pin number 13 as
output
}

void loop()
{
digitalWrite(ledPin, HIGH); // sets the led ON
delay(1000); // waits for a second

digitalWrite(ledPin, LOW); // sets the led OFF


delay(1000); // waits for a second
}
Basic Robot
Navigation
DC Motors
 As the name suggests, a
motor which uses a DC
(Direct Current) power

 Can run in both directions

 Speed Controllable

 DC Motors are high–speed,


low-torque devices.

 Using gears, the high speed


of the motor is traded off into
torque
H Bridge driver (L293D)
Features
 2 H-Bridge circuits

 Wide supply-voltage
range (4.5V-36V)

 Output current up to 1A
per channel

 When an enable input


is high, the associated
drivers are enabled
Li2 H-Bridge Schematic
Motor Connection

 Motor1 on H Bridge (IN1) : Pin 4


and 5 on Arduino

 Motor2 on H Bridge (IN2) : Pin 6


and 7 on Arduino
Basic Motor Control
(Pseudo Code)
//initialize Pins for H-Bridge input

void setup()
{
// Set pins as OUTPUT
}

void loop()
{
// Rotate Motor in One direction
// Set a Delay
// Rotate Motor in the opposite direction
}
Basic Motor Control
(Code)
int m_pin1 = 3; //initialize Pins for H-Bridge input
int m_pin2 = 4;
void setup()
{
pinMode(m_pin1, OUTPUT); // Set pins as OUTPUT
pinMode(m_pin2, OUTPUT);
}

void loop()
{
digitalWrite(m_pin1, HIGH); // Control H Bridge
digitalWrite(m_pin2, LOW);
delay(3000); // Wait
digitalWrite(m_pin1, LOW);
digitalWrite(m_pin2, HIGH);
delay(3000); // Change Direction
}
PROBLEM Statement #2
Robot Navigation

Step 1: Robot should move


forward for ‘n’ seconds.
Step 2: Robot should move
backwards for ‘n’ seconds.
Step 3: Robot should turn right.
Step 4: Robot should turn left.
SERIAL
COMMUNICATION
Serial Communication
Serial communication is a process where data is broken into
bits and communicated one after the other using a single
wire.

Characteristics of Serial communication using PC


 Voltage Level Conversion
PC uses RS232 protocol : 3 to 15 V for LOW
-3 to -15 V for HIGH
Microcontroller uses TTL : 0V for LOW
5V for HIGH

 Fully Duplex
Both Transmission and Reception takes place
simultaneously
Serial Functions
The Serial object is used for communication between the
arduino board and a computer or other devices.

Some Basic Serial Functions:

 Serial.begin():
It sets the data rate in bits per second (baud) for serial
data transmission.
Syntax: Serial.begin(datarate);
datarate baud rate (usually 9600 for computer comm.)

Note: This function is called and initialized in the


void setup()
Serial Functions
 Serial.available():
Gets the number of bytes (characters) available for
reading over the serial port.

 Serial.print(data):
Prints a data from Arduino to the serial port.
It is a overloaded function to accommodate various
datatypes.
Serial.print(b);
Serial.print("Hello World!");
 Serial.println(data):
It prints a data to the serial port followed by new line.

 Serial.read():
This function reads the incoming serial data.
Serial Function: Example Code
int data;

void setup()
{
Serial.begin(9600);
}

void loop()
{
if(Serial.available())
{
data = Serial.read();
Serial.print(“I received – “);
Serial.println(data);
}
}
PROBLEM Statement #3
PC Controlled ROBOT

Task 1: Robot should move


forward if ‘w’ is pressed
Task 2: Robot should move
backwards if ‘s’ is pressed
Task 3: Robot should turn right if
‘d’ is pressed
PC Controlled Robot – Code
// Initialize Pins for Motors
char data; // To store Serial data input
void setup()
{
// Set Motor Pins as OUTPUT
// Initialize Serial communication using 9600 datarate
}
void loop()
{ if(Serial.available())
{ data=Serial.read();
switch(data)
{
case ‘w’: // Move Robot Forward
case ‘a’: // Turn Robot Left
case ‘s’: // Move Robot Backwards
case ‘d’: // Turn Robot Right
}
}
// Robot Should STOP if nothing is Pressed
}
InfraRed (IR)
SENSORS
What are Sensors?

 Analogous to human sensory organs


 Eyes, ears, nose, tongue, skin

 Sensors help the robot knowing its surroundings better

 Improves its actions and decision making ability

 Provides feedback control


IR Sensor

Characteristics
 Optical sensor

 Comprises IR emitter and receiver

 Senses any IR radiation in its proximity.

 Gives high voltage output if IR radiation


received.
 Gives low voltage output if IR radiation is
not received.
IR Sensor Connection

Connections:

Sensor Vcc : 5V H-Bridge

Sensor Gnd: GND H-Bridge

Sensor O/P : Arduino Analog I/P


pins 0-5
Analog Functions
 analogRead()
Reads the value from the specified
analog pin.

The Arduino board contains 10-bit


Analog-to-Digital converter.

Syntax: data = analogRead(pin_num);


IR Sensor Calibration:
int ir_sense_pin = 1;
float i;
void setup()
{
Serial.begin(9600);
}
void loop()
{
i = analogRead(ir_sense_pin);
Serial.println(i);
delay(250);
}
PROBLEM Statement #4

Line Following ROBOT


- The ROBOT should follow a black line
present on a white background using
only ONE IR Sensor.
Line Follower – Sensor Mounting
Line Follower - Hints

 Hint 1
 Sensor on White gives Higher value

 Hint 2
 Sensor on Black gives Lower value

 Motion can be controlled based on


these values
Line Follower – THE Hint
Expected Trajectory of the ROBOT
Line Sensor Flowchart
Start

Calibrate Sensor for Black and


Declare variables White
Initialize

Loop

Read line sensor


value

N
Sensor On White Move Left
Sensor > threshold

Move Right

End loop

End
Line Follower – Pseudo Code
int threshold = 60;
Int Sense;

void setup()
{
// Declare pin-4,5,6,7 as OUTPUT pins.
}

void loop()
{
Sense = analogRead(1);
If( Sense>threshold )
// Turn left
If( Sense<threshold )
// Turn Right
}
See you tomorrow!!!!
Hands On: LED Fading
Step 1: Declare variables
int value = 0; // variable to keep the actual value
int ledpin = 9; // light connected to digital pin 9

Step 2: Initialize
void setup()
{
}
Step 3: Logic in Loop
void loop()
{
for( Value increment by 5 upto 255) // fade from min to max)
{
// Write analog
}
for( Value Decrement from 255 by steps of 5) // fade from max to
min)
{
//write analog
}
}
Code: LED Fading
int value = 0; // variable to keep the actual value
int ledpin = 9; // light connected to digital pin 9

void setup()
{
// nothing for setup
}

void loop()
{
for(value = 0 ; value <= 255; value+=5) // fade from min to max)
{
analogWrite(ledpin, value); // sets range from 0 to 255
delay(30); // waits to see dimming effect
}
for(value = 255; value >=0; value-=5) // fade from max to min)
{
analogWrite(ledpin, value);
delay(30);
}
}
Circle Maker Robot

 Build a robot that can track a circle


of given radius.

 Radius is measured with respect to


inner wheel
 Tolerance for deviation 5 cm diameter
Concept Building
Clue 1:
Inner Circle (Ic) = 2(pi)r
Outer Circle (Oc)= 2(pi)(r+x)
Where x = wheel base

Clue 2:
Ic / Oc = r /(r + x)

Clue 3:
Speed = d / t
d1 = 2(pi)(Wr) * t * Ic
d2 = 2(pi)(Wr) * t * Oc

Wr = Wheel radius
Logic
Logic I
 Ratio of speed = Ratio of radii
 Run M1 / M2 = r / (r + x)
 Run M1 stop M2 (wait for time r)
 Run M2 stop M1 (wait for time r +x)

Logic II
 Run M1 at full speed
 Run M2 at r / r + x speed
 M2 Running for time r
 M2 Stop for time x
Flowchart
Start Start

Declare variables Declare variables


Initialize Initialize

Loop Loop

Run M1 Run M1
Stop M2

Wait for time 'r'


Run M2
Wait for time 'r '

Run M2
Stop M1 Stop M2
Wait for time 'x''
Wait for time 'r + x'

End loop
End loop

End

End

Das könnte Ihnen auch gefallen