Lecture 3a Mechatronics - Arduino
Lecture 3a Mechatronics - Arduino
4215Q
Kỹ thuật
công nghệ
ME4215Q
KỸ THUẬT CÔNG NGHỆ
Kỹ thuật
công nghệ
Objectives
4215Q
Kỹ thuật
công nghệ
Sensor Motor
ME
Introduction
4215Q
Kỹ thuật
công nghệ
https://youtu.be/JlRPICfnmhw
ME
Introduction
4215Q
Kỹ thuật
công nghệ
Microcontroller
Vision sensor
Sound sensor
Motors
Power supply
Inertial sensor
Tilt sensor
Tactile sensor
Force sensor
Pressure sensor
ME
Applications
4215Q
Kỹ thuật
công nghệ
Sensors,
Motors, Automobiles
Microcontroller
Communications
Microcontroller Examples
4215Q
Kỹ thuật
công nghệ
• PIC Microchip
• 68HC11 of Motorola
• 8096 of Intel
• Arduino
• Raspberry Pi
•…
Different models of ‘arduino’
ME
4215Q
Kỹ thuật
công nghệ
https://www.arduino.cc/en/Main/Products
ME
Control diagram
4215Q
Kỹ thuật
công nghệ
Software
This lecture (part a) focuses on the microcontroller and software.
Part b focuses on sensors and motors (and how to connect them).
Program (‘sketch’) structure
ME
4215Q
Kỹ thuật
công nghệ
setup
• runs once
loop
• runs from top to
bottom - for ever -
until powered off
Parts of the ‘language’
ME
4215Q
Kỹ thuật
công nghệ
‘reserve’ words
show in a colour
Variables store
value – e.g. a
number or
Functions carry
out actions
Structure lets us
repeat operations
A ‘sketch’
ME
4215Q
Kỹ thuật
công nghệ
Get started
4215Q
Kỹ thuật
công nghệ
Please go to www.arduino.cc
Here you can:
• Get help
• Download software
• See examples
ME
Online or download?
4215Q
Kỹ thuật
công nghệ
• downloaded • online
ME
Is it working?
4215Q
Kỹ thuật
công nghệ
Basic structure
4215Q
Kỹ thuật
công nghệ
ME
Kỹ thuật
công nghệ
void loop()
{
analog = analogRead(0); // read voltage on pin 0 and store it in variable analog
Serial.println(analog); // display the value of analog to the monitor
digitalWrite(9,LOW); // turn on the LED
delay(analog); // delay based on the analog reading
digitalWrite(9,LOW); // turn on the LED
delay(analog); // delay based on the analog reading
}
ME
Your turn
4215Q
Kỹ thuật
công nghệ
Variables
4215Q
Kỹ thuật
công nghệ
Basic types:
• byte = 8 bit unsigned number (0 to 255)
• int = (integer) 16 bit number (n -32768 to +32767)
• unsigned int = positive integers only (0 to 65535)
• A float = 32 bit floating-point numbers (3.4028235E+38 to -3.4028235E+38); numbers
that have a decimal point with decimal precision of up to 6 digits
Functions
4215Q
Kỹ thuật
công nghệ
Functions are used to control the Arduino project board and for carrying out
computations.
pulse width
ME
More Functions
4215Q
Kỹ thuật
công nghệ
Time:
delay(), delayMicroseconds() micros(), millis() put the value wanted in
the brackets)
Maths:
abs(), max(), min(), sq(), sqrt() etc. for calculations
Trigonometry:
cos(), sin(), tan() for trig calculations
Control structures
4215Q
Kỹ thuật
công nghệ
Kỹ thuật
công nghệ
Kỹ thuật
công nghệ
• Structure of if/else:
while
4215Q
Kỹ thuật
công nghệ
Kỹ thuật
công nghệ
Kỹ thuật
công nghệ
Kỹ thuật
công nghệ
Worksheets
4215Q
Kỹ thuật
công nghệ
ME
Do the Worksheets
4215Q
Kỹ thuật
công nghệ