Workshop 1
Workshop 1
Workshop-1
Ankur Mayank
Electrical Engineering Electrical Engineering
Raja Kumar
Your
Mechanical
Instructor Engineering
PROJECTS
04 05 06
TinkerCAD Sensors Actuators
projects Ultrasonic Sonar Sensor Servo motor and geared
Infrared Sensor motors
Components
Arduino uno R3 and cable L293D Motor Driver
Infrared Sensor
●
Arduino
(General Instruction)
● An Arduino is an open-source microcontroller
development board.
Arduino UNO
Basic Structure
of Arduino UNO
• Microcontroller: Microcontroller is the main component of Arduino Uno. The
Arduino Uno board is a microcontroller based on the ATmega328.
• 14 Digital Pins: Arduino Uno Consist of 14 Digital Pins Where output Components
like: LED, LCD, Relay etc. are connected. These work for a value of HIGH or LOW.
• Analog Pins: Arduino Uno Consist of 6 Analog Pins, Analog Pins are usually used to
connect sensor like: IR Sensor , RF Sensor these all sensor have analog value that’s
why they are connected to analog pins, Most of the input components are
connected here. These pins return a value of 0-255.
• PWM – The pulse width modulation pins marked with the (~) symbol can simulate
analog output
• Reset Button: This is used to start the programme again which is once uploaded.
• Voltage Regulator:The function of the voltage regulator is to control the voltage
given to the Arduino board and stabilize the DC voltages used by the processor
and other elements.
• Crystal Oscillator:The crystal oscillator helps Arduino in dealing with time issues.
How does Arduino calculate time? The answer is, by using the crystal oscillator.
The number printed on top of the Arduino crystal is 16.000H9H. It tells us that
the frequency is 16,000,000 Hertz or 16 MHz.
• Power LED indicator:This LED should light up when you plug your Arduino into a
power source to indicate that your board is powered up correctly. If this light
does not turn on, then there is something wrong with the connection.
• Built-in LED: This LED is internally connected to I/O pin 13 of Arduino uno and
lights up when commanded on pin 13.
• Power Supply: The power supply pins are Vin, 5V, 3.3V, GND, IOREF are used to
power Input and output components. The recommended range is 7 to 12 volts to play
your board safe.
• Power Jack: Arduino board can be powered either by USB connection or with an
external power supply. This is used to power the Arduino board where we connect a
dc source from 7-12 volts.
• USB Port: This port function to programme the board or to upload the programme.
The one end of USB cable is connected to the laptop and another to this port. With
help of Arduino software and USB cable, one can upload the programme on the
board.
A Brief Idea of
Pulse Width Modulation
(PWM)
A Brief Idea of Pulse Width Modulation
(PWM):
● Pulse Width Modulation, or PWM, is
a technique for getting analog
results with digital means.
● Digital control is used to create a
square wave, a signal switched
between on and off.
● This on-off pattern can simulate
voltages in between the full Vcc of
the board .
● By changing the portion of the time
the signal spends on versus the time
that the signal spends off.
● The duration of "on time" is called
the pulse width.
● To get varying analog values, you
change, or modulate, that pulse
width.
Arduino IDE
Arduino IDE:
● The Arduino language is C++ thus it is a
case sensitive language.
● Most of the time, people will use a small
subset of C++, which looks a lot like C.
If you are familiar with Java, then you
will find C++ easy to work with and to
recognize.
● The simplest possible Arduino sketch is
this
What are variables?
● name of the memory location. It is used to store data.Its value can be changed, and it can be reused
many times.
Integer (int) Numeric data type for numbers without fractions -707, 0, 707
Floating Point (float) Numeric data type for numbers with fractions 707.07, 0.7, 707.00
Array List with a number of elements in a specific order—typically of the same type rock (0), jazz (1), blues (2),
pop (3)
Character (char) Single letter, digit, punctuation mark, symbol, or blank space a, 1, !
String (str or text) Sequence of characters, digits, or symbols—always treated as text hello, +1-999-666-3333
Why we need function?
void checkTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
{
// Condition to check if
// area is not equal to 0
if (a == 0)
cout << "No";
else
cout << "Yes";
}
Function
The function is a block of statement
or instruction enclosed by curly
braces { } that together perform one
of the special tasks
Basic syntax of function
return_type function_name (parameter list){
//function body
return (expression)
}
return_type: Return type can be of any data type such as int, double, char, void, short etc.
argument list: Argument list contains variables names along with their data types. These arguments are
kind of inputs for the function. For example – A function which is used to add two integer variables, will
be having two integer argument.
Block of code: Set of statements, which will be executed whenever a call will be made to the function.
Example
If-else
statement
● If else Statement in C programming
language, when we need to execute a block
of statements that too when a particular
condition is met or not met that situation is
known as decision making.
● In C programming, the decision-making
process is used to specify certain orders in
which statements are executed.
Basic syntax of if-else statement
Example
int marks=75
if(marks<=40){
print(“You are fail”)
}
if(40<marks<=50){
print(“You got D grade”) Output:
}
else if(50<marks<=60){ You got A grade
print(“You got C grade”)
}
else if(60<marks<=70){
print(“You got B grade”)
}
else if(70<marks<=80){
print(“You got A grade”)
}
else {
print(“You got A+”)
Basic structure of for loop
for(initialization; test Expression; increment/decrement)
{
Body of Loop
}
initialization: this allows you to initialize the initial value for the loop control.
test expression: This is for testing the condition. If the condition satisfies enter into the for loop
body and execute the code of for loop.
increment/decrement: This is for increments or decrements of the value of the variable each
time after the execution of the for loop body.
Header file
● Language has numerous libraries that include predefined functions to make
programming easier.
● In C language, header files contain the set of predefined standard library functions.
● All the header file have a ‘.h’ an extension. By including a header file, we can use its
contents in our program.
● This code contains two functions in it.
● The first one is setup().
● Anything you put in this function will be executed by the Arduino just once when the
program starts.
● The second one is loop().
● Once the Arduino finishes with the code in the setup() function, it will move into a loop(),
and it will continue running it in a loop, again and again, until you reset it or cut off the
power.
● Notice that both setup() and loop() have open and close parenthesis? Functions can
receive parameters, which is a way by which the program can pass data between its
different functions.
● The setup and loop functions don’t have any parameters passed to them. If you add
anything within the parenthesis, you will cause the compiler to print out a compilation
error and stop the compilation process.
● Every single sketch you write will have these two functions in it, even if you don’t use
them.
● In fact, if you remove one of them, the compiler again will produce an error message.
Setting up Arduino IDE :
● Step-1: Go to https://www.arduino.cc/ or just search download Arduino IDE on google
● Step-2: Install the latest version of Arduino IDE according to your system.
● Step-3: Install the IDE by leaving everything as default.
● Step-4: Open the IDE.
Writing Our first
programme:
● Connect your Arduino UNO Board via the USB cable to your computer.
● In editor area write in the codes below:
void setup()
{
pinMode(ledPin,OUTPUT);
}
void loop()
{
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(1000);
}
● Click on verify button.
● Click on upload button.
● After the uploading is successful the terminal shows the message Done Uploading and you will
see the led on your board blinking at interval of 1 sec.
Arduino control the devices that work on digital and analog signals.
Digital signals are those signals which have only two discrete values namely:
● 0 or 1
● LOW or HIGH
● True or False
Whereas analog signals are those signals which only continuous values from 0
to full, whatever the full value may be defined as.
Basic Input/Output functions of Arduino:
● pinMode(PIN_NUMBER, INPUT/OUTPUT) :Sets the pin at the location PIN_NUMBER to be either an
INPUT or an OUTPUT. Eg: inMode(ledpin,OUTPUT)
● analogRead(PIN_NUMBER):Reads the analog pin PIN_NUMBER and returns an integer between 0 and
1023 . Eg: int b=analogRead(A0);
● analogWrite(PIN_NUMBER, VALUE):Emulates analog output VALUE using PWM on PIN_NUMBER i.e can
only write a value between 0 and 255.(note: only available on pins 3, 5, 6, 9, 10, and 11).
Other commonly used
functions:
● delay(INTEGER): Delays program execution for INTEGER milliseconds
● First go to
https://www.tinkercad.com/
and create a student account.
● Now click on new button and
then select Circuit.
● A new blank project starts.
01
TinkerCAD
Project 1
Basic LED Project
What we are working on
void loop(){
digitalWrite(13, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(LED_BUILTIN, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
01
TinkerCAD
Project 2
A simple traffic light circuit
What we are working on
TinkerCAD
Project 3
Working of sonar sensor
What we are working on
void loop()
int distance ; long duration;
{
digitalWrite(t1,LOW);
const int t1=13; //trigger
delayMicroseconds(2);
const int e1=12; // echo;
digitalWrite(t1,HIGH);
void setup(){
delayMicroseconds(2);
pinMode(t1,OUTPUT);
digitalWrite(t1,LOW);
pinMode(e1,INPUT);
duration=pulseIn(e1,HIGH);
Serial.begin(9600);
distance=0.034*duration/2;
}
Serial.print(distance);
Serial.println("cm");
}
Actuators:
● An actuator is a device that produces a motion by converting energy and
signals going into the system. The motion it produces can be either rotary or
linear.
● Some common types of actuators that we will be discussing are:
1. Servo Motors
2. DC Geared Motors
Servo Motors:
● A servo motor is a type of motor that can rotate with great
precision. Normally this type of motor consists of a control
circuit that provides feedback on the current position of the
motor shaft, this feedback allows the servo motors to rotate
with great precision.
● Servo motors have three wires: power, ground, and signal. The
power wire is typically red, and should be connected to the 5V
pin on the Arduino board. The ground wire is typically black or
brown and should be connected to a ground pin on the board.
DC Geared Motor:
● A Direct Current (DC) motor is a rotating electrical device that
converts direct current, of electrical energy, into mechanical
energy.
● A coil inside the DC motor produces a magnetic field that creates
rotary motion as DC voltage is applied to its terminal.
● Inside the motor is an iron shaft, wrapped in a coil of wire.
● This shaft contains two fixed, North and South, magnets on both
sides which causes both a repulsive and attractive force, in turn,
producing torque.
Working of DC Motor In a DC motor, an armature rotates
inside a magnetic field.
● The small DC motors (which has 12V or below 12V) made up of permanent magnet i.e.
it contains a permanent magnetic field. If we want to change the direction of the shaft
we change the polarity only. Because it contains only armature winding only.
//The first argument stands for the number of the motors in the shield and the second one stands
for the motor speed control frequency.
The second argument can be MOTOR12_2KHZ, MOTOR12_8KHZ, MOTOR12_8KHZ, and
MOTOR12_8KHZ for motors number 1 and 2, and it can be MOTOR12_8KHZ, MOTOR12_8KHZ, and
MOTOR12_8KHZ for motors number 3 and 4.
And if it left unchecked, it will be 1KHZ by default.
motor.setSpeed(200);
Turning of
bot
Left turning of bot
● In an attempt to rotate left 90 degree, the rear wheels
spins in opposite direction which are connected to the
Motor Drive.
void turnLeft() {
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
delay(1500);
}
Right turning of bot
Code
void turnRight() {
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(1500);
}
01
Project 1
The basic principle behind the working of ultrasonic sensor is to note down the
time taken by sensor to transmit ultrasonic beams and receiving the ultrasonic
beams after hitting the surface.
Project 2
This Arduino robot having a sensor that can detect any object near it and can
follow this object. if you come in front of the robot it will start following you.
This robot consists ultrasonic sensor and IR sensor which help to follow the
object.
IR sensor works on infrared light which can also detect the object near to it. so
there is two IR sensor one is at the left side of ultrasonic sensor and other is at
the right side of the ultrasonic sensor.
Circuit Diagram
CODE
Thank
You