MAR Lab Manual 1 2
MAR Lab Manual 1 2
MAR Lab Manual 1 2
Lab Manual
Course Outcomes:
1. The students will be able to identify different sensors, understand their significance related to Robotics
and select a sensor as per the requirement.
2. The students will be able to understand the internal configuration and architecture of microcontroller.
3. The students will be able to interface different sensors and peripherals to a microcontroller and program
the same.
4. The students will be able interface different display devices, actuators and control them using a program.
5. The students will be able to understand working principle of different communication protocols used in
Robotics.
6. The students will be able to understand significance of different systems used in Robotics and Automation
Create front end web pages using HTML5 and CSS3 tags and attributes
Contents
Sr. Title of Experiment Page CO
No no mapping
1. Know Your Arduino Uno Kit 3 2
Note :
1. First five Assignments are Mandatory . Out of rest 7 any three can be chosen.
2. Minimum 8 experiments are required.
3. Part A and B of every assignment is compulsory for all students.
2
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Experiment No-1.
Title: Know your Micro-controller kit.
Tasks:
A) Get introduced to the Arduino Uno kit hardware.
B) Get introduced to the features of Arduino IDE.
The Arduino UNO is an open-source microcontroller board based on the Microchip AT mega
328P microcontroller and developed by Arduino. Arduino is a prototype platform (open-source)
based on an easy-to-use hardware and software. It consists of a circuit board, which can be
programed (referred to as a microcontroller) and a ready- made software called Arduino IDE
(Integrated Development Environment), which is used to write and upload the computer code to
the physical board.
Key Features -
• Arduino boards are able to read analog or digital input signals from different sensors and
turn it into an output such as activating a motor, turning LED on/off, connect to the cloud
and many actions.
• You can control your board functions by sending a set of instructions to the microcontroller
on the board via Arduino IDE (referred to as uploading software).
• Unlike most previous programmable circuit boards, Arduino does not need an extra piece of
hardware (called a programmer) in order to load a new code onto the board. You can
simply use the USB cable since it provides the In system programming facility.
• Additionally, the Arduino IDE uses a simplified version of C++, making it easier to learn
to program.
• Finally, Arduino provides a standard form factor that breaks the functions of the
micro-controller into an easily accessible package.
• Microcontroller: ATmega328
• Digital / pins: 14 C6 are PWM) 01 Analog Vo pins 16. • De current per 1/0 pin - 40mA for 3.3v
pin-50mA
• Flash memory - 32 KD of which 0.5 XB wed by boot loader → SRAM -2kh (ATmega328)
3
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
• Sketch editing tools- Arduino programs are called as sketch. Tool has various libraries to
perform different mathematical, interfacing functions. Also provides the facility of a Serial
Monitor to observe interim results. One can choose board of the choice as per requirements.
Port selection is also available.
• Arduino programs can be divided in three main parts: Structure, Values (variables and
constants), and Functions. In this tutorial, we will learn about the Arduino software program,
step by step, and how we can write the program without any syntax or compilation error.
Software structure consist of two main functions −
• Setup( ) function - The setup() function is called when a sketch starts. Use it to initialize the
variables, pin modes, start using libraries, etc. The setup function will only run once, after each
power up or reset of the Arduino board.
• Loop( ) function - After creating a setup() function, which initializes and sets the initial values,
the loop() function does precisely what its name suggests, and loops consecutively, allowing
your program to change and respond. Use it to actively control the Arduino board.
•
4
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Experiment No- 2
Tasks: Interface external LEDs with the UNG kit in a variety of combination and write a
program.
A) To glow 5 LEDS in
B) To implement vehicle, turn / parking indicator in visual made. Blink two LEDS - I) Alternatively
ii) simultaneously.
C) To simulate working of traffic signal for two three way road. Formulate your own theme and
delay cycle Decide the hardware required and assemble the same on a breadboard for your theme
Theory: As per the problem statement, we need to connect given LEDS into the specified variety
of combinations using Arduino Uno, jumpers, Lea's, breadboards and resistance.
In the case of 5-LED problem statement, we need to arrange the LEDs in Specified manner along
with appropriate resistance in order to prevent LED from bursting. Similarly, vehicle turn indicator
and traffic signal are safety measures, which would work on similar principle.
Working: When we complete the total connection and coding part, the working can be understood
easily.
• First of all, in all the 3 cases, LED's blink or glow so using "Digital write" they can glow.
• In the alternating lightening case 1, 3, 5 glow while LED, 2, 4 are off and vice-versa...
Whereas in loop run, we just increase the delay time. In case of parking light system, similar
mechanism is used. used along with delay, where the system depicts left led glowing to show that
vehicle is turning left and right glower when the vehicle is turning right and bath of them glow
when the vehicle u parked, while above two cases are similar, traffic light has 6 Led's in total (for
two way) and two glow at a time, where delay time is quite different as compared to above two
cares.
5
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
• Arduino Uno - operating voltage 5.v. AT mega 328P. No of digital 1/o pins-14, Input voltage
limits 6-20 V.
• LEDs should be available in different colors as per requirement. Specification forward biased.
1.2 to 36 V rated about 10 to 30 mA.
Interfacing Circuit diagram: (Draw Connections between Arduino Uno and the Sensors as
well as other components )
Algorithm: Write (Type) detailed steps of algorithm for each Tasks given i.e., for each of the Aim
A) and B).
Note:
• Connecting Arduino board and other connections was taking caring of anode & cathode in
LEDs was necessary...
Industrial application:
• This project can be used in traffic signals and vehicle indicator.
• In day to day life, in festival lightings, road safety boards, etc.
6
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Experiment No.-3
Tasks: Interface LDR with the UNO kit and write a program.
A) To implement automated street light ON OFF system depending upon at ambient light intensity.
Use at least 3-Leds as street Light.
B) To count number of objects passing through. The system should use light source (LED) and
detector (LDR). Initially count should be. Zero and with every object passing it should be
incremented by '1' Display the count on serial monitor of the OND simulator.
Theory:
Working Principle - The working principle of an LDR is photoconductivity, which & nothing but
an optical phenomenon.
When the material absorbs the light then the conductivity of the material enhances. When the light
falls on the LDR, then the elections in the material's valence bond are eager to the conduction I
band. But, the photons in the incident light must have energy superior to the band gap of the
material to make the electrons jump from one band to another band (valence to conduction).
Hence, when light has ample energy, more electrons are excited to the conduction band which
grades in many change canters. When the effect of this process and the flow of the current starts
flowing more the resistance of the device decreases.
Sensor Specifications -
7
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
For the first problem statement, an automated sheet be implemented. Here, when the light is falling
on the LDR the LEDS will turn off and when the LDR is not receiving no / low light intensity the
LEDS will glow, which depicts that during the day the street lights would be off and during night
times they will turn on.
For the second problem statement, a counted is to be implemented where in the system would
record the number of objects posted through. Here, an LDR and & light source led would be placed
opposite to each other. When an object passes between both of them it would block the light source
to the LDR due to which the LDR will turn off hence incrementing the count. So, every time an
object passes the count will be incremented and from this, we can get the total number of objects
passed. The final count would be printed on the serial monitor.
Interfacing Circuit diagram: (Draw Connections between Arduino Uno and the Sensors as
well as other components )
8
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
The first Tasks was connecting the LDR and Arduino Uno on the bread board which was to be
done very carefully to avoid errors. Then, the coding part expected was quite easy and lastly it was
working at.
Conclusion:
• Infrared astronomy.
9
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Experiment No.-4
Tasks: Interface ultrasonic sensor with the UNO kit and write a program.
A) To find distance (in cm) between the sensor and fixed surface like wall etc. Display the distance
on Serial monitor. Verity the distance by actual measurement.
Theory:
Working Principle - Ultrasonic sensors work by sending out a sound wave at a frequency above
the range of human hearing. The transducer of the sensor acts as a microphone to receive and send
the ultrasonic sound.
Sensor Specifications:
• Buzzer
Firstly, the sensor and Arduino Uno are connected. Now, as per the problem statement, we have to
measure the distance between the sensor and a fixed surface. Once the power supply is given, the
sensor will send and receive the sound waves and calculate the time taken for the waves to return.
Distance will be calculated by wing the formula distance = (speed of sound X time) /2, and this
distance measured will be displayed on the Serial monitor.
10
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
• Jumpers - set of make to male connectors & a set of male to female connectors.
• Buzzer
Interfacing Circuit diagram: (Draw Connections between Arduino Uno and the Sensors as
well as other components )
Industrial application: Apart from the distance measurement, ultrasonic sensors are used in robot
sensing, presence detection, tank level detection and many application on the production line, etc.
11
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Experiment No. 5
Tasks:
A) Write a program to display Hello World! On LCD at desired location
B)Write a program to scroll custom message on Right or Left direction on LCD.
C)Write a program to display custom characters on LCD
Theory:
Liquid Crystal Display (LCD) is the display device that can be interfaced with Arduino. For this,
The LiquidCrystal library (LiquidCrystal.h) allows to control LCD displays. LCDs have a parallel
interface, meaning that the microcontroller has to manipulate several interface pins at once to
control the display. The interface consists of the following pins:
1) A register selects (RS) pin that controls where in the LCD's memory for writing data to.
One can select either the data register, which holds what goes on the screen, or an instruction
register, which is where the LCD's controller looks for instructions on what to do next.
2) A Read/Write (R/W) pin that selects reading mode or writing mode
3) An Enable pin that enables writing to the registers
4) 8 data pins (D0 -D7). The states of these pins (high or low) are the bits that you're writing
to a register when you write, or the values you're reading when you read.
A) Also, the LiquidCrystal library shows how to use the scrollDisplayLeft() and
scrollDisplayRight() methods to reverse the direction the text is flowing.
B) For custom character display,
Create a custom character for use on the LCD. Up to eight characters of 5x8 pixels are
supported (numbered 0 to 7). The appearance of each custom character is specified by an
array of eight bytes, one for each row. The five least significant bits of each byte determine
the pixels in that row. To display a custom character on the screen, write() its number.
There's also a display contrast pin (Vo), power supply pins (+5V and Gnd) and LED Backlight
(Bklt+ and BKlt-) pins that you can use to power the LCD, control the display contrast, and turn
on and off the LED backlight, respectively.
12
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
LCD functions :1. LiquidCrystal. Begin(16x2)- Initializes LCD specifying size in number of
columns and rows.
Electronic components and materials required:
• Arduino UNO Development Board,
• USB Cable,
• Breadboard,
• LED, Resistor (1 k ohm),
• 10K Potentiometer,
• Connecting Wires,
• 16x2LCDModule.
Interfacing Circuit diagram: (Draw Connections between Arduino Uno and the Sensors as
well as other components )
Also Draw spl character matrix 5x8 and explain formation of special character.
13
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
lcd.begin(16,2);
pinMode(A0,INPUT);
Step - 4
The setup part is over. Next loop part First to clear the display use the function "lcd. Clear()". This
function will clean the entire display. lcd. Clear();
Step - 5
We need a starting point to start printing. So set the cursor to that particular point by the function
"lcd.setCursor()". This function has only two attributes. It is that starting points.(The number of
column and number of row). Start from first column first row. The first column is represented as
0, second is 1, and so on and the first raw is represented as 0, second is 1. So, we need to start from
the position (0, 0). You can easily understand if you know about matrix. The piece of code become,
lcd.setCursor(0,0);
Step - 6
The instruction to print. to print "Hello World" by the instruction "lcd.print()". Alternatively, you
can print anything. Please don, t forgot the double quote marks.
lcd.print("Hello World");
Step -7
In the above printing statement, we use total of 14 characters. So, the current position of cursor is
at (14, 0). Now to print on the next line, i.e., the position (0, 1). Set the cursor to that point by the
function "lcd.setCursor()".
lcd.setCursor(0,1);
Step - 8
Now the cursor is at the position of second row and first column(0, 1). Then print another text
"Value" by the function lcd.print().
lcd.print("Value : ");
Step - 9
Here we use 8 characters in second line. So, the current position of cursor is (8, 1). Next, we need
to read the analog value from the pin A0 and print it to the display. It uses "analogRead()" function
to read the analog value and use the "lcd.print()" function to print the value to the display. And
there is no need of double quotes.
lcd.print(analogRead(A0));
Step - 10
Delay(): we have to add some delay. Otherwise, the text will blink continues. That because of the
first instruction "LCD. Clear()". Every time when see this command the Arduino will clear the
display, This results the blinking of display. But use of delay will decrease this blinking.
delay(500);
Step - 11
Connection
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
14
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K POT:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
15
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Experiment No. 6
Tasks:
A) Write a program to transfer message from mobile and display it on the serial monitor using
Bluetooth.
B) Write a program to Transfer message from mobile and display it on the LCD using Bluetooth
Theory:
A Bluetooth technology is a high-speed low powered wireless technology link that is designed to
connect phones or other portable equipment together. It is a specification (IEEE 802.15.1) for the
use of low power radio communications to link phones, computers and other network devices over
short distance without wires. Wireless signals transmitted with Bluetooth cover short distances,
typically up to 30 feet (10 meters).
It is achieved by embedded low-cost transceivers into the devices. It supports on the frequency
band of 2.45GHz and can support up to 721KBps along with three voice channels. This frequency
band has been set aside by international agreement for the use of industrial, scientific and medical
devices (ISM).
Working with the help of HC 05 android app:
• Download the Application
• Pair your device with HC 05/06 Bluetooth module
• Turn ON HC 05/06 Bluetooth module
• Scan for available device
• Pair to HC 05/06 by entering default password 1234 OR 0000
• Open the Application.
• Press paired devices
• Select your Bluetooth module from the List (HC 05)
The Bluetooth module at other end receives the data and send to Arduino through the TX
pin of Bluetooth module (RX pin of Arduino). The Code fed to Arduino checks the received
data and compares. If received data is 1 the LED turns on turns OFF when received data is
0.
16
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Interfacing Circuit diagram: (Draw Connections between Arduino Uno and the Sensors as
well as other components )
Algorithm: Write (Type) detailed steps of algorithm for each Tasks given i.e., for each of the Aim
A) and B).
Result:(Put screenshot of serial monitor for each Tasks given i.e., for each of the Aim A) and B).
Conclusion: Bluetooth is widely used in remote controls, headphones, to transfer files from one
device to another, devices such as keyboard, printer and mouse, etc.
17
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Experiment No. 7
Theory: Thermistors are variable resistors that change their resistance with temperature. They are
classified by the way their resistance responds to temperature changes. In Negative Temperature
Coefficient (NTC) thermistors, resistance decreases with an increase in temperature. In Positive
Temperature Coefficient (PTC) thermistors, resistance increases with an increase in temperature.
NTC thermistors are the most common, NTC thermistors are made from a semiconducting material
(such as a metal oxide or ceramic) that’s been heated and compressed to form a temperature
sensitive conducting material.
The conducting material contains charge carriers that allow current to flow through it. High
temperatures cause the semiconducting material to release more charge carriers. In NTC
thermistors made from ferric oxide, electrons are the charge carriers. In nickel oxide NTC
thermistors, the charge carriers are electron holes.
Thermistor Symbol
The Arduino will measure the voltage at a point between the thermistor and a known resistor. This is
known as a voltage divider. The equation for a voltage divider is:
Vout=Vin xR2/R1+R2
In terms of the voltage divider in a thermistor circuit, the variables in the equation above are:
18
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Vout Voltage between Thermistor and known Resistor
Vin Vcc i.e., +5V
R1 Known Resistor
R2 resistance of Thermistor
Interfacing Circuit diagram: (Draw Connections between Arduino Uno and the Sensors as
well as other components )
Algorithm: Write (Type) detailed steps of algorithm for each Tasks given i.e., for each of the Aim
A) and B).
Result:(Put screenshot of serial monitor for each problem statement given i.e., for each of the Aim
A) and B).
19
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Experiment No. 8
Theory:
When Arduino application only needs to display numbers, consider using a seven-segment display.
The seven-segment display has seven LEDs arranged in the shape of number eight. They are easy
to use and cost effective.
Seven segment displays are of two types: common anode and common cathode. The Internal
structure of both types is nearly the same. The difference is the polarity of the LEDs and
common terminal. In a common cathode seven-segment display (most popularly used), all seven
LEDs plus a dot LED have the cathodes connected to pins 3 and pin 8. To use this display, we need
to connect GROUND to pin 3 and pin 8 and, and connect +5V to the other pins to make the
individual segments light up. The following diagram shows the internal structure of common-
cathode seven-segment display:
The common anode display is the exact opposite. In a common-anode display, the positive terminal
of all the eight LEDs is connected together and then connected to pin 3 and pin 8. To turn on an
20
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
individual segment, you ground one of the pins. The following diagram shows the internal structure
of the common-anode seven-segment display.
Interfacing Circuit diagram: (Draw Connections between Arduino Uno and the Sensors as
well as other components )
Algorithm: Write (Type) detailed steps of algorithm for each Tasks given i.e., for each of the Aim
A) and B).
21
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Experiment No. 9
Components: Arduino UNO Development Board, USB Cable, Breadboard, LED, Resistor (1 k
ohm, 10Kohm), Connecting Wires, Push Button (Micro Switch), DC Motor etc.
Theory:
The pushbutton is a component that connects two points in a circuit when you press it. We
connect three wires to the Arduino board. The first goes from one leg of the pushbutton through
a pull-up or pull-down resistor (here 10 KOhms) to the 5-volt supply. The second goes from
the corresponding leg of the pushbutton to ground. The third connects to a digital I/o pin (here
pin 7) which reads the button's state. When the pushbutton is open (unpressed) there is no
connection between the two legs of the pushbutton, so the pin is connected to 5 volts (through
the pull-up resistor) and we read a HIGH. When the button is closed (pressed), it makes a
connection between its two legs, connecting the pin to ground, so that we read a LOW. (The
pin is still connected to 5 volts, but the resistor in-between those means that the pin is "closer"
to ground.)
22
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Interfacing Circuit diagram: (Draw Connections between Arduino Uno and the Sensors as
well as other components )
Algorithm: Write(Type) detailed steps of algorithm for each Tasks given i.e., for each of the Aim
A), &B)
Result: Put screenshot of serial monitor for each Tasks given i.e., for each of the Aim A),& B)
23
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Experiment No. 10
Components: Arduino UNO Development Board, USB Cable, Breadboard, Connecting Wires,
3x4 and 4x4 keypad module, 16x2 LCD, Potentiometer 10K etc.
Theory:
The library Keypad’s is used for interfacing keypad with Arduino. A keypad is often needed to
provide input to an Arduino system, and membrane-type keypads are an economical solution for
many applications. They are quite thin and can easily be mounted wherever they are needed. A 12-
button keypad has three columns and four row. Pressing a button will short one of the row outputs
to one of the column outputs. From this information, the Arduino can determine which button
was pressed. For example, when key 1 is pressed, column 1 and row 1 are shorted. The Arduino
will detect that and input a 1 to the program.
How the rows and column are arranged inside the keypad is shown in the figure below.
A 4×4 Matrix Keypad consists of 16 Keys or Buttons arranged in four rows and four columns. The
internal circuit of the 4×4 Keypad with all the 16 buttons. When a key is pressed, the corresponding
column will become LOW as the current flows from HIGH Column Pin to LOW Row Pin. The
Arduino can easily identify the Column of the Key just by scanning for LOW on Columns. The
trick part comes in identifying the Row of the Key. For this, the Arduino should make the Rows of
the keypad HIGH, one-by-one and check for the Column Pins to become HIGH. This procedure is
24
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
continued till the earlier detected Column becomes HIGH. This way, the Arduino can determine
both the Column and the Row of the Key and hence the Key pressed is identified.
Operating components and materials required with specifications:
• Arduino UNO Development Board,
• USB Cable, Breadboard,
• Connecting Wires,
• Push Button (Micro Switch)
• DC Motor etc.
Interfacing Circuit diagram: (Draw Connections between Arduino Uno and the Sensors as
well as other components )
Algorithm: Write(Type) detailed steps of algorithm for each Tasks given i.e., for each of the Aim
A), &B)
Result: Put screenshot of serial monitor for the Tasks given i.e., Aim A) and B)
25
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Experiment No. 11
Theory:
A servo motor is an electric device used for precise control of angular rotation. It is used in
applications that demand precise control over motion, like in case of control of a robotic arm, The
rotation angle of the servo motor is controlled by applying a PWM signal to it. By varying the
width of the PWM signal, we can change the rotation angle and direction of the motor.
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. The signal pin is typically yellow or
orange and should be connected to PWM pin on the board. In these examples, it is pin number 9.
Functions Used
1. Servo my servo
2. myservo.attach(pin)
3. myservo.write(angle)
• This function writes a value to the servo, thus controlling the position of the shaft.
• Angle can take values between 0 to 180.
26
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
• This function is used to map a number from one range to another range.
• This means that “value” having a value between “fromLow” to “fromHigh” gets
converted to equivalent values in the range of “toLow” to “toHigh”. “fromLow” gets
mapped to “toLow” and so on.
Interfacing Circuit diagram: (Draw Connections between Arduino Uno and the Sensors as
well as other components )
Algorithm: Write (Type) detailed steps of algorithm for each Tasks given i.e., for each of the Aim
A), &B).
A) Program to control the Servo Motor Rotation by one Degree
STEP 1- Start
STEP 2- include servo.h library
STEP 3- define angle
STEP 4- create a new object myservo from the library
STEP 5- in void setup, declare myservo.attach(9)
STEP 6- in void loop, use for loops to rotate the motor
STEP 7- Stop
27
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
B) Program to control servo motor with potentiometer.
STEP 1- Start
STEP 2- include servo.h library
STEP 3- create a new object myservo from the class Servo
STEP 4- define a variable val and port pin and initialize it to the analogue pin of the Arduino A0
STEP 5- in void setup, declare myservo.attach(9)
STEP 6- in void loop, initialize the variable val to the value from the analogue input of the
potentiometer
STEP 7- map the value of angle and rotate the motor
STEP 8- Stop
Result: Put screenshot of serial monitor for each Tasks given i.e., for each of the Aim A), &B).
28
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Experiment No. 12
Components: Arduino UNO Development Board, USB Cable, Breadboard, LED, Resistor (1 k
ohm), Connecting Wires, Potentiometer 10K, DC Motor etc.
Theory:
DC motor converts electrical energy in the form of Direct Current into mechanical energy in the
form of rotational motion of the motor shaft. The DC motor speed can be controlled by applying
varying DC voltage; whereas the direction of rotation of the motor can be changed by reversing the
direction of current through it. For applying varying voltage, we can make use of PWM technique.
For reversing the current, we can make use of H-Bridge circuit or motor driver ICs that employ the
H-Bridge technique. PWM wave generated on the Arduino UNO is used to provide a variable
voltage to the motor through L293D. In Arduino, analog. Write function is used to generate PWM
wave.
29
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
1. digitalPinToInterrupt(pin)
• This function is used to configure the mode of interrupt event and declare the ISR for that
interrupt. The interrupt event and ISR is for the interrupt pin declared by the function
digitalPinToInterrupt(pin).
• ISR in this function is the name of the ISR that will be used for this interrupt.
• mode defines when the interrupt will be triggered. There are four modes available to
choose from:
- LOW: trigger the interrupt whenever the pin is low.
- CHANGE: trigger the interrupt whenever the pin changes value.
- RISING: trigger when the pin goes from low to high.
- FALLING: trigger when the pin goes from high to low.
• Example, attachInterrupt(digitalPinToInterrupt(2), motor, FALLING) configures digital
pin 2 as an interrupt pin with ISR named motor and which generates interrupt for every
falling edge event on pin 2.
• This function is used for generating PWM on PWM digital pins (3,5,6,9,10,11 for Arduino
UNO).
• value can be any number between 0 to 255. 0 being 0% duty cycle and 255 being 100%
duty cycle.
30
Vishwakarma Institute of Technology
Department of Engineering, Sciences and Humanities
FY: 2021-2022:Semester II
ES1024: Mechatronics and Robotics
Interfacing Circuit diagram: (Draw Connections between Arduino Uno and the Sensors as
well as other components )
Algorithm: Write (Type) detailed steps of algorithm for each Tasks given i.e., for each of the Aim
A), & B).
Result: Put screenshot of serial monitor for each Tasks given i.e., for each of the Aim A), & B).
31