Beruflich Dokumente
Kultur Dokumente
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
Control System
Why Arduino?
Inexpensive
Cross-platform
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().
delayMicroseconds()
This function creates a delay for a specified time
interval in microseconds.
Syntax: delayMicroseconds(microseconds);
PROBLEM Statement #1
LED Blinking
Step 2: Initialize
void setup() // Executes only once
{
// Set pin number 13 as output
}
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
Speed Controllable
Wide supply-voltage
range (4.5V-36V)
Output current up to 1A
per channel
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
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.
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.)
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
Characteristics
Optical sensor
Connections:
Hint 1
Sensor on White gives Higher value
Hint 2
Sensor on Black gives Lower value
Loop
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
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
Loop Loop
Run M1 Run M1
Stop M2
Run M2
Stop M1 Stop M2
Wait for time 'x''
Wait for time 'r + x'
End loop
End loop
End
End