SlideShare a Scribd company logo
Basic Mechatronics
Basic Tutorial for Arduino
By,
Manas Shrivastava
MNNIT, Allahabad
Contents
● Control systems - open loop and closed loop
● Structure of Arduino
● What can I do with Arduino?
● Open loop control system with Arduino
● Closed loop control system with Arduino
● Sensors
● Devices
● Coding
● Examples
● Troubleshooting
Control Systems
● Any system that controls a process based on inputs given to it is a control
system.
● In our everyday life, we are surrounded by various control systems.
● For example, the maintenance of a definite temperature inside a refrigerator
is achieved through a control system.
● A simple cam-follower mechanism is an example of a control system.
● Touch screen of phone functions through a control system.
● As we can see, there are infinite control systems all around us.
● Control systems are not just mechanical or electrical, even the facing of a
sunflower towards the sun and the entire operation of the human body are
also a few examples of controls systems.
A broad classification of control systems
There are broadly two kinds of control systems - Open loop control and Closed
loop control systems.
Open loop control systems - These systems do not take any feedback from the
output conditions. We just give an input and get an output. Easy and cheap :)
Closed loop control systems - These systems take their job seriously and check
whether the system is producing the desired output or not? This requires feedback
from the output conditions and thus, increases the complications and cost of the
system.
Depending upon our application, we choose open or closed control system.
Basics of mechatronics - Arduino tutorial
Examples of open loop control systems
● Cam-follower pair
● Induction Cooker
● Air conditioner in a car
● Remote of TV
● Manual Washing machine
● Regulator of fans
● Spring damper system
● Water taps
● Shells from cannons
Examples of closed loop control systems
● Valve opening in IC Engines by camshaft.
● Air conditioners/ Refrigerators
● Guided bombs and missiles
● Autopilot in aircrafts
● Adaptive brightness in smartphones
● Automatic doors in buildings
● Automatic electric iron
● Water level control through balloon in tanks
Structure of Arduino
What can we do with an Arduino?
● A wide range of operations is possible by making use of the Arduino IDE.
● Project examples-
1. Remote controlled Quadcopter drone
2. Theft detector
3. Home automation circuit
4. Automatic sweet dispenser
5. Sorting machines
6. Bomb defuser (and the bomb as well)
7. Spyware
8. Robots carrying out various functions
9. Robotic Arm
10.Health tracker
Open loop and closed loop control system with
Arduino
Open loop - Arduino is the microcontroller, we give input through the code, and
anything like a motor, LED, buzzer, can be used as an actuator to give motion,
rotation, sound, light, etc as outputs.
Closed loop - We add sensors to the above mentioned system for feedback, and
change the input accordingly. Sensors include resistive, inductive or capacitive
transducers, ultrasonic distance sensors, IR sensors, gas sensors, etc.
Sensors
● For measuring distance:
○ Ultrasonic Distance sensors
■ Ultrasonic waves are triggered, and the time that they take to reflect back is measured to
calculate distance of object.
■ Used for a range of 3cms to 4m.
■ Cheap and easily available.
○ Laser Distance sensors
■ Very accurate with high range and fast response time
■ Costly
● For differentiating between light and dark colours:
○ IR sensors: Emit Infrared rays, dark surfaces absorb them, light surfaces reflect them. A
reverse biased diode receives the reflected rays and detects bright surfaces. These are cheap
and can detect only dark or white surfaces.
○ Colour sensors: They can detect any colour depending upon the wavelength of light reflected
back, they are costly and can detect any distinct colour.
● For measuring Rotation:
○ Potentiometers: They are cheap and easy to use.
○ Rotary Encoders: They are more precise, and more complex than potentiometers.
● For measuring presence of gas: Various gas sensors use chemicals whose
conductivity varies with concentration of particular gas around them.
● For measuring magnetic field intensity: Hall sensors use Hall effect to detect
magnetic field variation around them.
● Miscellaneous sensors and combinations:
○ Many other sensors are used according to applications like vibration sensors, flow sensors,
temperature and humidity sensors, etc.
○ Combination of transducers can be used to make more applications like joystick, which uses a
combination of two potentiometers to detect rotation in X and Y axis.
Devices
● Once the Microcontroller processes the input, we need actuators and devices
to get an output.
● Just like sensors, we have many devices according to our applications. Some
of them are:
○ Motors - DC, Servo, Stepper, etc
○ Linear actuators
○ LED’s, LCD Displays, OLED displays, LED Matrix, etc
○ Buzzers
○ Relays
○ Various Modules
Coding
● Arduino IDE’s coding is a mixture of C and Java.
● The basic structure of a code comprises of two parts: Setup and Loop
● Setup is the part of the code which just runs once when the Arduino is
started, it defines which pins are we using and what do we want from the
board to do in this code.
● Loop is where you put your main code to run it throughout the time period of
the Arduino being switched on.
Input Output commands
● As we already know, there are two kinds of pins - digital and analog
● The input commands are:
○ digitalRead(pin_number);
○ analogRead(pin_number);
● The output commands are:
○ digitalWrite(pin_number, state); //State can be ‘HIGH’/1 or “LOW”/0
○ analogWrite(pin_number, value); //Value can be anything between 0 to 1023 (1024 values)
● // is used for writing single line comments, /* is used to write multi line
comments */
● To define the mode of pins (Input or Output) in setup, pinMode(mode); is
used. //mode = INPUT or OUTPUT
● To hold the looping code for some time at any instance, we use
delay(milliseconds); //milliseconds of the delay that we want
Variables, control statements, loops, arrays,
functions
● The above mentioned commands are same as in C, the only difference is that
instead of using “||”, we use “or”, and instead of “&&”, we use “and”.
We will be seeing some examples for more clarity now..
Example #1
A program to flash a LED connected to digital pin 9 when a button on digital pin 3
is pressed.
Connections:
Basics of mechatronics - Arduino tutorial
Example #2
A program to make a tune Beepbeep….beepbeep… through a buzzer at pin 8.
Connection:
Basics of mechatronics - Arduino tutorial
Example #3
A program to rotate a motor connected to pin 3 and 4 in a certain direction when a
button at pin 7 is pressed, and in opposite direction when a button at pin 8 is
pressed.
Connection:
Basics of mechatronics - Arduino tutorial
Example #4
A program to make basic line follower robot using three infrared sensors and two
motors.
Line follower robot:
On a white surface, there is a black line. Our robot will follow that line. We use
three IR sensors here, if the surface under the IR sensor is black, it will return low
analog values. When the left IR sensor show black line under it, we stop the left
motor, and keep rotating the right motor, so that the robot takes a turn. For
smoother motion, we can also slow down the left motor instead of stopping it using
analog output through PWM pins. We perform the same action for right turn and
thus, follow the black line.
● Since Arduino can not provide sufficient current for operation of motors, we
use an IC called L293D, which is a motor driver IC.
● Motor driver IC’s use external power supply source to drive motors, and they
take signal from Arduino to determine where and when to supply the voltage
to the motor.
● The connections of L293D can be seen in the connection diagram shown in
next slide...
Basics of mechatronics - Arduino tutorial
2
1
3
Troubleshooting
Here are the steps to perform troubleshooting in the system:
● Check for loose connections, if any.
● Check for proper shorting and voltage supply to each component.
● Check for connections you actually made and connections that you coded in
Arduino.
● Use serial monitor to check code and sensor values:
○ Serial monitor is a special facility in Arduino where you can print anything that goes on with the
sensors or the code on your laptop screen.
○ Use Serial.begin(9600); in setup function of the code to start Serial monitor at 9600 baud rate.
//Baud rate is the rate of data transmitted per second, it depends on level of our application.
○ We will explore Serial Monitor in upcoming slides...
Serial Monitor
● Serial monitor can be accessed through tools menu of Arduino IDE or by
pressing Ctrl+Shift+M.
● Serial.print(variable); command is used to print a variable, generally this is
used to check sensor output values or to calibrate sensors.
● Serial.println(variable); prints the value and moves to the next line.
● Serial.print(“Hey!”); can be used to print strings whenever required.
● The upcoming examples show how to use serial monitor...
Serial monitor example #1
● Suppose you are using analog input pins to get values from an IR sensor to
detect black and white lines.
● In a particular lighting condition, the IR sensor returns values below “500” for
black surface, and above “500” for white.
● So we code that if(analogRead(3) <= 500){ line = 0; /*0 for black*/ }.
● Now the lighting conditions change, and this time “700” below means black.
● So we need to calibrate the sensor and replace the 500 with 700.
● Now, how do we know about these values that the sensor is returning. This
500, 700, how do we determine these values?
● This is where the Serial monitor comes up!
Basics of mechatronics - Arduino tutorial
Basics of mechatronics - Arduino tutorial
Serial monitor example #2
Suppose you write a conditional code (using if else) in loop function and it doesn’t
work! :(
What could have happened! There’s no response from the code, so it might be
that the conditional command is false, and hence the code is not going further.
To check the state of the conditional command, we can use Serial monitor here!
Basics of mechatronics - Arduino tutorial
● Now, we knew that the code wasn’t working since pin 5 was at LOW state.
So, to check which if condition if not working, we used the above mentioned
code.
● If serial monitor shows that only component at A2 satisfies the condition, we
will know that component at A4 is faulty, or if serial monitor doesn’t show
anything, then component at A2 may be faulty.
● In this way, the Serial monitor is used to reach the point of error very
accurately and eliminates the need of checking each and every component or
each and every part of the code.
Back to troubleshooting
● After we are done checking each and every part of the code with Serial
monitor, we will be able to find in which part the code goes wrong.
● After debugging the part, we check the functioning of the functions again, till it
works perfectly.
Conclusion
● After this basic part of the Arduino tutorial, we have reached the stage from
where we can control motors, buzzers, and many more devices using
buttons, sensors, or any input devices that we wish to use with Arduino.
● Next up: Using EEPROM memory of Arduino to store data even when it is not
working, using advanced Modules like the GPS, GSM, Wifi, etc; Using
displays such as OLED, LCD, SSD module, etc; Using Serial communication
and much more!
● Have fun exploring the new stuff now!
Get the Arduino IDE at: https://www.arduino.cc/en/Main/Software
Basics of mechatronics - Arduino tutorial

More Related Content

What's hot (20)

SERVO MOTOR CONTROLLER
SERVO MOTOR CONTROLLER
JITENDRA SUWASIYA
 
El microcontrolador PIC16F877
El microcontrolador PIC16F877
SANTIAGO PABLO ALBERTO
 
Arduino Microcontroller
Arduino Microcontroller
Shyam Mohan
 
PLC Basic
PLC Basic
Sankar Kanagaraj
 
Control systems engineering
Control systems engineering
Anisur Rahman
 
Actividad sentido de embobinado en un motor
Actividad sentido de embobinado en un motor
Jorge Ivan Ospina Mejia
 
plc-basics.pptx
plc-basics.pptx
AyyarKandasamy1
 
Sensors
Sensors
Rishikesh Borse
 
Introduction to Arduino
Introduction to Arduino
Omer Kilic
 
A Report on Bidirectional Visitor Counter using IR sensors and Arduino Uno R3
A Report on Bidirectional Visitor Counter using IR sensors and Arduino Uno R3
Abhishekvb
 
Clap Switch Using Arduino
Clap Switch Using Arduino
Home
 
programmable logic controller presentation
programmable logic controller presentation
Ashutosh Verma
 
Arduino اردوينو
Arduino اردوينو
salih mahmod
 
Pid control
Pid control
AB Rizvi
 
Interfacing bluetooth with arduino
Interfacing bluetooth with arduino
Jairaj Jangle
 
Arduino Based Project.pptx
Arduino Based Project.pptx
Abhishek Sharma
 
Control Systems servo mechanisms.pdf
Control Systems servo mechanisms.pdf
GopalakrishnaU
 
Arduino presentation by_warishusain
Arduino presentation by_warishusain
student
 
Keyence plc programming course1
Keyence plc programming course1
Winai Jan
 
Speed checker on highway using 8051
Speed checker on highway using 8051
Rkrishna Mishra
 
Arduino Microcontroller
Arduino Microcontroller
Shyam Mohan
 
Control systems engineering
Control systems engineering
Anisur Rahman
 
Actividad sentido de embobinado en un motor
Actividad sentido de embobinado en un motor
Jorge Ivan Ospina Mejia
 
Introduction to Arduino
Introduction to Arduino
Omer Kilic
 
A Report on Bidirectional Visitor Counter using IR sensors and Arduino Uno R3
A Report on Bidirectional Visitor Counter using IR sensors and Arduino Uno R3
Abhishekvb
 
Clap Switch Using Arduino
Clap Switch Using Arduino
Home
 
programmable logic controller presentation
programmable logic controller presentation
Ashutosh Verma
 
Arduino اردوينو
Arduino اردوينو
salih mahmod
 
Pid control
Pid control
AB Rizvi
 
Interfacing bluetooth with arduino
Interfacing bluetooth with arduino
Jairaj Jangle
 
Arduino Based Project.pptx
Arduino Based Project.pptx
Abhishek Sharma
 
Control Systems servo mechanisms.pdf
Control Systems servo mechanisms.pdf
GopalakrishnaU
 
Arduino presentation by_warishusain
Arduino presentation by_warishusain
student
 
Keyence plc programming course1
Keyence plc programming course1
Winai Jan
 
Speed checker on highway using 8051
Speed checker on highway using 8051
Rkrishna Mishra
 

Similar to Basics of mechatronics - Arduino tutorial (20)

02 Sensors and Actuators Understand .pdf
02 Sensors and Actuators Understand .pdf
engsharaf2025
 
Arduino-workshop.computer engineering.pdf
Arduino-workshop.computer engineering.pdf
AbhishekGiri933736
 
teststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptx
ethannguyen1618
 
Arduino slides
Arduino slides
sdcharle
 
Arduino Workshop Slides
Arduino Workshop Slides
mkarlin14
 
Arduino_Beginner.pptx
Arduino_Beginner.pptx
shivagoud45
 
Arduino and Circuits.docx
Arduino and Circuits.docx
Ajay578679
 
introductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdf
HebaEng
 
arduino
arduino
murbz
 
Arduino comic v0004
Arduino comic v0004
DO!MAKERS
 
Arduino Comic-Jody Culkin-2011
Arduino Comic-Jody Culkin-2011
ΚΔΑΠ Δήμου Θέρμης
 
Arduino Slides With Neopixels
Arduino Slides With Neopixels
sdcharle
 
Arduino course
Arduino course
Ahmed Shelbaya
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
SAURABHKUMAR892774
 
arduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdf
ssusere5db05
 
arduino and its introduction deep dive ppt.pptx
arduino and its introduction deep dive ppt.pptx
SruSru1
 
What is Arduino
What is Arduino
SKUGme
 
Arduino Programming Basic
Arduino Programming Basic
LITS IT Ltd,LASRC.SPACE,SAWDAGOR BD,FREELANCE BD,iREV,BD LAW ACADEMY,SMART AVI,HEA,HFSAC LTD.
 
Syed IoT - module 5
Syed IoT - module 5
Syed Mustafa
 
13223971.ppt
13223971.ppt
SuYee13
 
02 Sensors and Actuators Understand .pdf
02 Sensors and Actuators Understand .pdf
engsharaf2025
 
Arduino-workshop.computer engineering.pdf
Arduino-workshop.computer engineering.pdf
AbhishekGiri933736
 
teststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptx
ethannguyen1618
 
Arduino slides
Arduino slides
sdcharle
 
Arduino Workshop Slides
Arduino Workshop Slides
mkarlin14
 
Arduino_Beginner.pptx
Arduino_Beginner.pptx
shivagoud45
 
Arduino and Circuits.docx
Arduino and Circuits.docx
Ajay578679
 
introductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdf
HebaEng
 
arduino
arduino
murbz
 
Arduino comic v0004
Arduino comic v0004
DO!MAKERS
 
Arduino Slides With Neopixels
Arduino Slides With Neopixels
sdcharle
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
SAURABHKUMAR892774
 
arduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdf
ssusere5db05
 
arduino and its introduction deep dive ppt.pptx
arduino and its introduction deep dive ppt.pptx
SruSru1
 
What is Arduino
What is Arduino
SKUGme
 
Syed IoT - module 5
Syed IoT - module 5
Syed Mustafa
 
13223971.ppt
13223971.ppt
SuYee13
 
Ad

Recently uploaded (20)

Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Ad

Basics of mechatronics - Arduino tutorial

  • 1. Basic Mechatronics Basic Tutorial for Arduino By, Manas Shrivastava MNNIT, Allahabad
  • 2. Contents ● Control systems - open loop and closed loop ● Structure of Arduino ● What can I do with Arduino? ● Open loop control system with Arduino ● Closed loop control system with Arduino ● Sensors ● Devices ● Coding ● Examples ● Troubleshooting
  • 3. Control Systems ● Any system that controls a process based on inputs given to it is a control system. ● In our everyday life, we are surrounded by various control systems. ● For example, the maintenance of a definite temperature inside a refrigerator is achieved through a control system. ● A simple cam-follower mechanism is an example of a control system. ● Touch screen of phone functions through a control system. ● As we can see, there are infinite control systems all around us. ● Control systems are not just mechanical or electrical, even the facing of a sunflower towards the sun and the entire operation of the human body are also a few examples of controls systems.
  • 4. A broad classification of control systems There are broadly two kinds of control systems - Open loop control and Closed loop control systems. Open loop control systems - These systems do not take any feedback from the output conditions. We just give an input and get an output. Easy and cheap :) Closed loop control systems - These systems take their job seriously and check whether the system is producing the desired output or not? This requires feedback from the output conditions and thus, increases the complications and cost of the system. Depending upon our application, we choose open or closed control system.
  • 6. Examples of open loop control systems ● Cam-follower pair ● Induction Cooker ● Air conditioner in a car ● Remote of TV ● Manual Washing machine ● Regulator of fans ● Spring damper system ● Water taps ● Shells from cannons
  • 7. Examples of closed loop control systems ● Valve opening in IC Engines by camshaft. ● Air conditioners/ Refrigerators ● Guided bombs and missiles ● Autopilot in aircrafts ● Adaptive brightness in smartphones ● Automatic doors in buildings ● Automatic electric iron ● Water level control through balloon in tanks
  • 9. What can we do with an Arduino? ● A wide range of operations is possible by making use of the Arduino IDE. ● Project examples- 1. Remote controlled Quadcopter drone 2. Theft detector 3. Home automation circuit 4. Automatic sweet dispenser 5. Sorting machines 6. Bomb defuser (and the bomb as well) 7. Spyware 8. Robots carrying out various functions 9. Robotic Arm 10.Health tracker
  • 10. Open loop and closed loop control system with Arduino Open loop - Arduino is the microcontroller, we give input through the code, and anything like a motor, LED, buzzer, can be used as an actuator to give motion, rotation, sound, light, etc as outputs. Closed loop - We add sensors to the above mentioned system for feedback, and change the input accordingly. Sensors include resistive, inductive or capacitive transducers, ultrasonic distance sensors, IR sensors, gas sensors, etc.
  • 11. Sensors ● For measuring distance: ○ Ultrasonic Distance sensors ■ Ultrasonic waves are triggered, and the time that they take to reflect back is measured to calculate distance of object. ■ Used for a range of 3cms to 4m. ■ Cheap and easily available. ○ Laser Distance sensors ■ Very accurate with high range and fast response time ■ Costly ● For differentiating between light and dark colours: ○ IR sensors: Emit Infrared rays, dark surfaces absorb them, light surfaces reflect them. A reverse biased diode receives the reflected rays and detects bright surfaces. These are cheap and can detect only dark or white surfaces. ○ Colour sensors: They can detect any colour depending upon the wavelength of light reflected back, they are costly and can detect any distinct colour.
  • 12. ● For measuring Rotation: ○ Potentiometers: They are cheap and easy to use. ○ Rotary Encoders: They are more precise, and more complex than potentiometers. ● For measuring presence of gas: Various gas sensors use chemicals whose conductivity varies with concentration of particular gas around them. ● For measuring magnetic field intensity: Hall sensors use Hall effect to detect magnetic field variation around them. ● Miscellaneous sensors and combinations: ○ Many other sensors are used according to applications like vibration sensors, flow sensors, temperature and humidity sensors, etc. ○ Combination of transducers can be used to make more applications like joystick, which uses a combination of two potentiometers to detect rotation in X and Y axis.
  • 13. Devices ● Once the Microcontroller processes the input, we need actuators and devices to get an output. ● Just like sensors, we have many devices according to our applications. Some of them are: ○ Motors - DC, Servo, Stepper, etc ○ Linear actuators ○ LED’s, LCD Displays, OLED displays, LED Matrix, etc ○ Buzzers ○ Relays ○ Various Modules
  • 14. Coding ● Arduino IDE’s coding is a mixture of C and Java. ● The basic structure of a code comprises of two parts: Setup and Loop ● Setup is the part of the code which just runs once when the Arduino is started, it defines which pins are we using and what do we want from the board to do in this code. ● Loop is where you put your main code to run it throughout the time period of the Arduino being switched on.
  • 15. Input Output commands ● As we already know, there are two kinds of pins - digital and analog ● The input commands are: ○ digitalRead(pin_number); ○ analogRead(pin_number); ● The output commands are: ○ digitalWrite(pin_number, state); //State can be ‘HIGH’/1 or “LOW”/0 ○ analogWrite(pin_number, value); //Value can be anything between 0 to 1023 (1024 values) ● // is used for writing single line comments, /* is used to write multi line comments */ ● To define the mode of pins (Input or Output) in setup, pinMode(mode); is used. //mode = INPUT or OUTPUT ● To hold the looping code for some time at any instance, we use delay(milliseconds); //milliseconds of the delay that we want
  • 16. Variables, control statements, loops, arrays, functions ● The above mentioned commands are same as in C, the only difference is that instead of using “||”, we use “or”, and instead of “&&”, we use “and”. We will be seeing some examples for more clarity now..
  • 17. Example #1 A program to flash a LED connected to digital pin 9 when a button on digital pin 3 is pressed. Connections:
  • 19. Example #2 A program to make a tune Beepbeep….beepbeep… through a buzzer at pin 8. Connection:
  • 21. Example #3 A program to rotate a motor connected to pin 3 and 4 in a certain direction when a button at pin 7 is pressed, and in opposite direction when a button at pin 8 is pressed. Connection:
  • 23. Example #4 A program to make basic line follower robot using three infrared sensors and two motors. Line follower robot: On a white surface, there is a black line. Our robot will follow that line. We use three IR sensors here, if the surface under the IR sensor is black, it will return low analog values. When the left IR sensor show black line under it, we stop the left motor, and keep rotating the right motor, so that the robot takes a turn. For smoother motion, we can also slow down the left motor instead of stopping it using analog output through PWM pins. We perform the same action for right turn and thus, follow the black line.
  • 24. ● Since Arduino can not provide sufficient current for operation of motors, we use an IC called L293D, which is a motor driver IC. ● Motor driver IC’s use external power supply source to drive motors, and they take signal from Arduino to determine where and when to supply the voltage to the motor. ● The connections of L293D can be seen in the connection diagram shown in next slide...
  • 26. 2 1 3
  • 27. Troubleshooting Here are the steps to perform troubleshooting in the system: ● Check for loose connections, if any. ● Check for proper shorting and voltage supply to each component. ● Check for connections you actually made and connections that you coded in Arduino. ● Use serial monitor to check code and sensor values: ○ Serial monitor is a special facility in Arduino where you can print anything that goes on with the sensors or the code on your laptop screen. ○ Use Serial.begin(9600); in setup function of the code to start Serial monitor at 9600 baud rate. //Baud rate is the rate of data transmitted per second, it depends on level of our application. ○ We will explore Serial Monitor in upcoming slides...
  • 28. Serial Monitor ● Serial monitor can be accessed through tools menu of Arduino IDE or by pressing Ctrl+Shift+M. ● Serial.print(variable); command is used to print a variable, generally this is used to check sensor output values or to calibrate sensors. ● Serial.println(variable); prints the value and moves to the next line. ● Serial.print(“Hey!”); can be used to print strings whenever required. ● The upcoming examples show how to use serial monitor...
  • 29. Serial monitor example #1 ● Suppose you are using analog input pins to get values from an IR sensor to detect black and white lines. ● In a particular lighting condition, the IR sensor returns values below “500” for black surface, and above “500” for white. ● So we code that if(analogRead(3) <= 500){ line = 0; /*0 for black*/ }. ● Now the lighting conditions change, and this time “700” below means black. ● So we need to calibrate the sensor and replace the 500 with 700. ● Now, how do we know about these values that the sensor is returning. This 500, 700, how do we determine these values? ● This is where the Serial monitor comes up!
  • 32. Serial monitor example #2 Suppose you write a conditional code (using if else) in loop function and it doesn’t work! :( What could have happened! There’s no response from the code, so it might be that the conditional command is false, and hence the code is not going further. To check the state of the conditional command, we can use Serial monitor here!
  • 34. ● Now, we knew that the code wasn’t working since pin 5 was at LOW state. So, to check which if condition if not working, we used the above mentioned code. ● If serial monitor shows that only component at A2 satisfies the condition, we will know that component at A4 is faulty, or if serial monitor doesn’t show anything, then component at A2 may be faulty. ● In this way, the Serial monitor is used to reach the point of error very accurately and eliminates the need of checking each and every component or each and every part of the code.
  • 35. Back to troubleshooting ● After we are done checking each and every part of the code with Serial monitor, we will be able to find in which part the code goes wrong. ● After debugging the part, we check the functioning of the functions again, till it works perfectly.
  • 36. Conclusion ● After this basic part of the Arduino tutorial, we have reached the stage from where we can control motors, buzzers, and many more devices using buttons, sensors, or any input devices that we wish to use with Arduino. ● Next up: Using EEPROM memory of Arduino to store data even when it is not working, using advanced Modules like the GPS, GSM, Wifi, etc; Using displays such as OLED, LCD, SSD module, etc; Using Serial communication and much more! ● Have fun exploring the new stuff now! Get the Arduino IDE at: https://www.arduino.cc/en/Main/Software