Professional Documents
Culture Documents
Mechatronics Boot Camp - May2022
Mechatronics Boot Camp - May2022
Mechatronics Boot Camp - May2022
College of Engineering
Mechanical Engineering Department
Saturday 28/5
Renewable & Automotive (12:45 – 3:00 pm) Microfluidics (12:45 – 3:00 pm)
Mechatronics is a multidisciplinary field of
engineering that includes a combination
of mechanical
engineering, electronics, computer
engineering, telecommunications
engineering, systems engineering and control
engineering.
Mechatronics Fields
Machine vision
Automation and robotics
Servo-mechanics
Sensing and control systems
Automotive engineering, automotive equipment in
the design of subsystems such as anti-lock braking
systems
Computer-machine controls, such as computer
driven machines like CNC milling machines, CNC
waterjets, and CNC plasma cutters
Mechatronics System brains
Micro-Controllers
In any mechatronics system, there is a component acts
like a brain which is responsible for complex
computations and decisions making based on a
predefined program.
Some examples:
Micro-controllers
myRio PLC
Computers
programmable logic controller (PLC)
myRIO
Micro-Controller:
It is a micro-computer. As any
computer it has internal CPU,
RAM, IOs interface.
It is used for control purposes, and
for data analysis.
Famous microcontroller
manufacturers are MicroChip,
Atmel, Intel, Analog devices, and
more.
Computer vs. Microcontroller
What is Arduino?
• A microcontroller board, contains:
• on-board power supply.
• USB port to communicate with PC.
• Atmel microcontroller chip.
Atmel
MicroController
USB port
Power input
Analog input.
Power Supply
Arduino
Power pins, including:
UNO Board
1. Vin pin: this pin can be used to give power
to the Arduino.
2. GNDs.
1-setup function:
•Anything you put here will be executed
only once.
•Usually people use it to do the
configurations (defining pin modes, setting
the serial communication speed...etc).
2-loop function:
• Anything you write here will be executed
for ever.
Terminology
Some important functions related Digital I/0
pinMode(pin, mode)
Sets pin to either INPUT or OUTPUT
digitalRead(pin)
Reads HIGH or LOW from a pin
digitalWrite(pin, value)
Writes HIGH or LOW to a pin
Arduino Timing Functions
• delay(ms)
– Pauses for a few milliseconds
• delayMicroseconds(us)
– Pauses for a few microseconds
More commands:
arduino.cc/en/Reference/HomePage
Let's Start..
Blinking LED
Example
Blinking LED
Cathode
_
+
Anode
Longer leg
Circuit#1 : Blinking LED
Why we need a resistor? What is a
resistor?
A resistor is an electric device that limits and reduces the
electric current flowing in a circuit.
If we don't do this the current that goes from the Arduino pin will be
at its maximum. Maximum current from the Arduino pin is 40 mA.
This is not safe for both the Arduino and the LED (LED might burn).
Not all devices are TTL. That's why there are level converters!
Computers have serial ports that are not TTL level.
The voltage can range from -13 V to 13 V.
digitalRead(pin): is used to read digital value
on a pinDigital Read
If( digitalRead(pin) )
{ code }
https://www.youtube.com/watch?v=wxjerCHCEMg
Digital Read
digitalRead will be used to read the push button
output.
The push button can be connected to Arduino by
using
pull down resistor or pull up resistor,
5V
as follows:
Arduino Pin
GND
Syntax
pinMode(pin, mode)
Parameters
pin: the Arduino pin number to set the mode of.
mode: INPUT, OUTPUT, or INPUT_PULLUP.
Arduino has build-in pull-up resistor and you can implement it by changing the
mode in pinMode command.
Tasks
Implement a circuit by using one LED and push button.
Pressing a push button connected to a digital input will
turn the LED on and stopping the pressing will turn the
LED off. Use a pull-down resistor (use 10 kΩ).
Synatx:
AnalogWrite(pin, DutyCycle)
3
PWM Using AnalogWrite()
AnalogWrite(pin,25)
AnalogWrite(pin,127)
AnalogWrite(pin,229)
Fading LED
Cathode
_
+
Anode
Longer leg
Acquire Analog Signal
AnalogRead(pin): reads the analog
Reading Analog Signal
voltage on the pin specified.
Returns
Integer value between (0 to 1023)
0 5 volts
00000000000 1111111111
0 1023
Potentiometer
Potentiometer
A potentiometer is a 3-pin variable resistor.
When powered with 5V, the middle pin outputs a voltage between 0V and
5V, depending on the position of the knob on the potentiometer.
Internal to the trimpot is a single resistor and a wiper, which cuts the resistor
in two and moves to adjust the ratio between both halves (i.e. voltage
division)
Potentiometer are not polarized and can be installed in either direction. Note
that swapping the 5V and GND pins will reverse its behavior.
It can be used to make volume controls, speed controls, angle sensors and a
ton of other useful inputs for your projects.
Example
We will read the analog voltage on the potentiometer
and control light intensity on the LED
PWM pin
We will read the analog voltage on the potentiometer and control
Example
light intensity on the LED
PWM pin
Temperature sensor (TMP36)
Introduction to Temp. sensor
The TMP36 is a low voltage, precision centigrade temperature sensor. It
provides a voltage output that is linearly proportional to the Celsius
temperature. It also doesn’t require any external calibration to provide
typical accuracies of ±1°C at +25°C and ±2°C over the −40°C to +125°C
temperature range.
We like it because it’s so easy to use: Just give the device a ground and 2.7
to 5.5 VDC and read the voltage on the Vout pin. The output voltage can
be converted to temperature easily using the scale factor of 10 mV/°C.
https://www.youtube.com/watch?v=_B3gWd3A_SI
Hobby Servo functionality
Servos have integrated gears and a shaft that can be
precisely controlled.
Standard servos allow the shaft to be positioned at various
angles, usually between 0 and 180 degrees.
Continuous rotation servos allow the rotation of the shaft
to be set to various speeds.
Servo components
1. Small DC motor
2. Gearbox with small plastic gears to reduce the RPM and increase output torque
3. Special electronics to interpret a pulse signal and deliver power to the motor
Hobby Servo Wires
Black: GND
Red: 5V
Yellow/orange/white: Signal
Arduino Servo library:
Servo library supports up to 12 motors on most Arduino boards
Standard servos allow the shaft to be positioned at various angles,
usually between 0 and 180 degrees.
Continuous rotation servos allow the rotation of the shaft to be set to
various speeds.
From the Arduino web site:
http://www.arduino.cc/en/Reference/Servo
Arduino Servo library
https://www.arduino.cc/en/reference/servo
Create the servo object
Servo my_servo_object;
Name of the object is like a
variable name.
Attach the object
my_servo_object.attach(servo_pin);
Adjust servo position with a potentiometer and map the range from 0-5 v to 0-
180o :
Connect a potentiometer to an analog input
Connect a servo motor to the Arduino.
Use the potentiometer to control the servo position.
Additional Resources
www.arduino.cc
https://www.edx.org/course/c-programming-getting-started?index=p
roduct&queryID=edd3a96ca53684fbc9989532243ed95a&position=
1
https://www.sparkfun.com/products/15267