Hands 0N With Robotics Components
Hands 0N With Robotics Components
•PWM Pins 3, 5, 6, 9 and 11: These pins provide an 8-bit PWM output by using analogWrite() function.
•SPI Pins 10 (SS), 11 (MOSI), 12 (MISO) and 13 (SCK): These pins are used for SPI communication.
•In-built LED Pin 13: This pin is connected with an built-in LED, when pin 13 is HIGH – LED is on and
when pin 13 is LOW, its off.
•AREF (Analogue REFerence) : Used to provide reference voltage for analog inputs with
analogReference() function. It changes the sensitivity of Analog Pins ie. Value per unit step (total: 1024)
will change according to the maximum value reference provided through AREF.
What is SPI?
•SPI (Serial Peripheral Interface) is a serial communication protocol. SPI has a full duplex connection, which means
that the data is sent and received simultaneously. That is a master can send data to slave and a slave can send data
to master simultaneously.
SPI has following four lines MISO, MOSI, SS, and CLK
• MISO (Master in Slave Out)-Pin 12 - The Slave line for sending data to the master.
• MOSI (Master Out Slave In) -Pin 11- The Master line for sending data to the peripherals.
• SCK (Serial Clock) -Pin 13- The clock pulses which synchronize data transmission generated by the master.
• SS (Slave Select) -Pin 10 –Master can use this pin to enable and disable specific devices.
SPI is generally used for communication between two or more Arduino, for the same we need a library called “SPI.h”
What is PWM?
Title and Content Layout with Chart
• TWI (2-Wire Interface) Pins (I2C)
The TWI pins are SDA (DATA) or A4, & SCL (CLOCK) or A5, which can support the communication of TWI
with the help of “Wire.h” library. Using this we can communicate between two or more devices in
Master/Slave configuration.
I2C is better for longer data transfer, It supports multi master communication but it’s than SPI.
• delay(time)
• Used for giving delay in program.
• Time is given in milliseconds.
• digitalWrite(pin_number,value).
• Basically turns a pin ON or OFF. (HIGH or LOW)(1 or 0)
Functions in Arduino
• analogWrite(pin_number,value)
• Its function is same as the digitalWrite() but in this we can give
a pin a value from 0 to 255 - different voltages
• digitalRead(pin_number)
• Digitally read form the pin either HIGH or LOW
SERIAL
MONITOR
HARDWARE COMPONENTS
ULTRASONIC SENSOR
Servo Stepper Motor
DC Brushless Motor
DC Geared Motor
Jumpers
WiFi Module
Bluetooth Module
IR Module
L298N MOTOR
DRIVER
L293D MOTOR
DRIVER
LET’s CODE…!!!
LED Blinking using Digital Pins (without PWM)
//Simple LED blinking program
const int L1 = 2; //Declaring LED pin
void setup()
{pinMode(L1, OUTPUT); //Setting pin mode }
void loop()
{digitalWrite(L1, HIGH); //Turn on led
delay(1000); // On time in miliseconds
digitalWrite(L1, LOW); //Turn off led
delay(1000); //Off time }
LED Blinking (Fade) using Digital Pins (with PWM)
//Simple LED blinking program (FADE)
const int L1 = 3; // Led pin (must use a pwm output)
void setup()
{ pinMode(L1,OUTPUT);}
void loop()
{ for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5)
{ // A loop that goes from 0 to 255 which is 0V to 5V in an pwm output (3)
analogWrite(L1, fadeValue); // The led receive the value from 0 to 255
delay(100); //Time in miliseconds
}
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5)
{ // Same loop but from highest value to lowest value
analogWrite(L1, fadeValue); // The led receive the value from 255 to 0
delay(100);
}
}
Hands On with Ultrasonic Sensor
void loop() {
int trigPin = 7;
digitalWrite(trigPin, LOW);
int echoPin = 6;
delayMicroseconds(2);
long duration;
digitalWrite(trigPin, HIGH);
int distance;
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
void setup() {
pinMode(trigPin, OUTPUT);
duration = pulseIn(echoPin, HIGH);
pinMode(echoPin, INPUT);
distance= duration*0.034/2;
Serial.begin(9600);
}
Serial.print("Distance: ");
Serial.println(distance);
}
Ultrasonic Sensor using
>>Ultrasonic.h<<
Go to >>Tools<<
Look out for >>Manage Libraries…<< tab
Search for “Ultrasonic.h” by Erick Simões
#include <Ultrasonic.h>
/*
Pass as a parameter the trigger and echo pin, respectively, or only the signal pin (for sensors 3
pins), like:
Ex: Ultrasonic ultrasonic(7);
*/
Ultrasonic ultrasonic(7, 6);
int distance;
void setup() {
Serial.begin(9600);
}
void loop() {
distance = ultrasonic.read();
Serial.print("Distance in CM: ");
Serial.println(distance);
delay(1000);
}
Hands On with IR Sensor
( Analog )
/*
Using this code we will print analog readings received from IR Module via Analog Input Pin – ‘A0’
with a delay of 1000 milliseconds between 2 consecutive readings
*/
void setup() {
Serial.begin(9600);
pinMode(A0,INPUT);
}
void loop() {
// while(1) is an infinite loop…
while(1){
int current_analog_value = analogRead(A0);
Serial.print(“IR Value is: ”);
Serial.println(current_analog_value);
delay(1000);}
}
Motor driver - L293D IC
void loop(){
digitalWrite(enA,HIGH);
int motorPin1 = 9; digitalWrite(enB,HIGH);
int motorPin2 = 8; analogWrite(motorPin1, 180);
int motorPin3 = 7; analogWrite(motorPin2, 0);
int motorPin4 = 6; analogWrite(motorPin3, 180);
int enA = 10; analogWrite(motorPin4, 0);
int enB = 5; delay(5000);
//This code will turn Motor A counter-
void setup(){ clockwise for 2 sec.
pinMode(enA,OUTPUT); analogWrite(motorPin1, 0);
pinMode(enB,OUTPUT); analogWrite(motorPin2, 180);
pinMode(motorPin1, OUTPUT); analogWrite(motorPin3, 0);
pinMode(motorPin2, OUTPUT); analogWrite(motorPin4, 180);
pinMode(motorPin3, OUTPUT); delay(5000);
pinMode(motorPin4, OUTPUT); }
}
Line Following Bot
Logic!!!
Logic!!!
Logic!!!
Logic!!!
THANK YOU …!!!
-TEAM ARC