Top Banner
Arduino and Matlab for prototyping and manufacturing Enrique Chacón Tanarro 11th - 15th December 2017 UBORA First Design School - Nairobi Enrique Chacón Tanarro [email protected]
29

Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

Nov 21, 2018

Download

Documents

dangthuy
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

Arduino and Matlab for prototyping and manufacturing

Enrique Chacón Tanarro

11th - 15th December 2017 UBORA First Design School - Nairobi Enrique Chacón Tanarro

[email protected]

Page 2: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

Index

1. Arduino

2. Arduino programming

3. Matlab controlling arduino

11th - 15th December 2017 UBORA First Design School - Nairobi 2

Page 3: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1. Ardunio

Arduino is an open-source electronic platform based on easy to use hardware and software (https://www.arduino.cc/ )

11th - 15th December 2017 UBORA First Design School - Nairobi 3

ENVIROMENT

Sensors:

• Temperature • Pressure • Light • Proximity • Acceleration • …

Actuators:

• Motors • Relays • Valves • Piezoelectrics • Diode led • …

ARDUINO ENVIROMENT INTERACTION

Page 4: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.1. Enviroment

Arduino is an open-source electronic platform based on easy to use hardware and software (https://www.arduino.cc/ )

11th - 15th December 2017 UBORA First Design School - Nairobi 4

ENVIROMENT

Sensors:

• Temperature • Pressure • Light • Proximity • Acceleration • …

Actuators:

• Motors • Relays • Valves • Piezoelectrics • Diode led • …

ARDUINO ENVIROMENT INTERACTION

Page 5: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.1. Enviroment

Arduino can receive environment information from 2 ways:

A) USER

• Physical: switches, buttons, potentiometers,…

• Virtual

11th - 15th December 2017 UBORA First Design School - Nairobi 5

Arduino PC - Matlab

Page 6: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.1. Enviroment

Arduino can receive environment information from 2 ways:

B) SENSORS

11th - 15th December 2017 UBORA First Design School - Nairobi 6

Temperature

Termoresistance

Light

Fotoresistence

Pressure

Piezoelectric

Fluids Mechanical contact

Position /

Velocity

Encoder

Aceleration

Accelerometers

Movement

Movement

sensor Sound

Microphone

Gas

Page 7: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.1. Enviroment

EXAMPLE: How can we measure the luminosity of this room?

11th - 15th December 2017 UBORA First Design School - Nairobi 7

LDR resistance varies its resistance as a function of light

A0 pin voltage depends on the LDR resistance

Light Ω

Page 8: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.2. Arduino board

What does ARDUNIO do with the information from sensors, touchscreens, etc.

11th - 15th December 2017 UBORA First Design School - Nairobi 8

ENVIROMENT

Sensors:

• Temperature • Pressure • Light • Proximity • Acceleration • …

Actuators:

• Motors • Relays • Valves • Piezoelectrics • Diode led • …

ARDUINO ENVIROMENT INTERACTION

Page 9: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.2. Arduino board

11th - 15th December 2017 UBORA First Design School - Nairobi 9

https://www.robomart.com

Arduino ONE board

Digital Information

Programmable integrated circuit

Fundamental parts: • CPU (calculation speed) • Memory (code complexity) • Input and output peripherals

(number of signals to be controlled

Analogical Information

Arduino board selection

Page 10: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.2. Arduino board

11th - 15th December 2017 UBORA First Design School - Nairobi 10

Arduino board selection

• Arduino Uno

• Arduino ProMini

• Arduino Nano

• Arduino Micro

• Arduino Mega 2560

• Arduino Mega ADK (android)

• Arduino Gemma

• Arduino Leonardo

• Arduino Yún (ethernet)

• Arduino Cactus (WiFi)

Page 11: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.2. Arduino board

11th - 15th December 2017 UBORA First Design School - Nairobi 11

Arduino UNO board

Analogical input Digital input/output

• 6 input pins A0,A1,A2,...

• Voltage range: 0 - 5V

• Precision: 5V / 1024 values = 5mV

• 14 pins 0-13

• Sensors and actuators are connected in these pins. They must declared (software) is INPUT or OUTPUT.

• Voltage: 5V (HIGH) - 0V (LOW).

• Max. pin current: 40 mA. Max. total pins current: 200 mA.

Page 12: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.2.1. Electronic components

What does ARDUNIO do with the information from sensors, touchscreens, etc.?

11th - 15th December 2017 UBORA First Design School - Nairobi 12

ENVIROMENT

Sensors:

• Temperature • Pressure • Light • Proximity • Acceleration • …

Actuators:

• Motors • Relays • Valves • Piezoelectrics • Diode led • …

ARDUINO ENVIROMENT INTERACTION

ELECTRONIC COMPONENTS

Pro

tob

oar

d

Page 13: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.2.1. Electronic components

11th - 15th December 2017 UBORA First Design School - Nairobi 13

Transistors

Generate an output signal in response to an input signal

Functions: switch, amplifier, oscillator or rectifier

Diodes

Current circulation is only allowed in one direction

Many types:

Resistences

Correct resistance selection:

Cathode Anode

Current direction

base

collector

emitter

power

Great output signal

power

Low input signal Switch

application

Zener

Used as a constant voltage source

LED

(light emitting diode)

Photodiode

Allows reverse current

when light falls on it

Generic

Mostly used as rectifier for

converting AC to DC and

motor protection

I = V/R

1, 2 or 3 red or yellow LED (1,8-2,1V)

Page 14: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.3. Environment interaction

What does ARDUNIO do with the information from sensors, touchscreens, etc.

11th - 15th December 2017 UBORA First Design School - Nairobi 14

ENVIROMENT

Sensors:

• Temperature • Pressure • Light • Proximity • Acceleration • …

Actuators:

• Motors • Relays • Valves • Piezoelectrics • Diode led • …

ARDUINO ENVIROMENT INTERACTION

Page 15: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.3. Environment interaction

11th - 15th December 2017 UBORA First Design School - Nairobi 15

Movement

• Relays

• Valves

• Motors

• Etc.

Signal

• Display

• Leds

• Buzzer

• Etc.

Servomotor

or

Light, valve, etc.

open-close control

Page 16: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.3.1. PWM outputs

11th - 15th December 2017 UBORA First Design School - Nairobi 16

¿Are there analogical outputs in ARDUINO? Digital PWM

PWM pins allows us to simulate an analog behaviour applying a continuous value. Arduino ONE board pins 3, 5, 6, 9, 10 ,11

How does it work?

Instead of a continuous signal

Pulses of square signals (490Hz)

We can varied pulse duration

Desired analog voltage = voltage average

Period

Pulse width

Average

Average

Page 17: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

1.3.1. PWM outputs

11th - 15th December 2017 UBORA First Design School - Nairobi 17

EXAMPLE: How can we vary the DC electric motor speed?

Motor speed varies dependidng on the voltage applied to pin 9

Transistor with protection resistance

Motor con diodo de protección

External power supply

Page 18: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

2. Arduino programming

1) Install the free software from arduino.cc/en/Main/Software

2) Conect Arduino board to the computer. Drivers will be installed automatically.

3) Open the software

11th - 15th December 2017 UBORA First Design School - Nairobi 18

Co

mp

ile

Up

load

New

Op

en

Save

code writing area

Software messages: errors and actions

Page 19: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

2. Arduino programming

Arduino is programmed in C/C++

The algorithm consist of:

11th - 15th December 2017 UBORA First Design School - Nairobi 19

• Fundamental structures

• Variables y constants

• Mathematical, logical and Boolean operators

• Control structures (conditionals, cycles)

• Functions

Page 20: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

2.1. Fundamental structures

11th - 15th December 2017 UBORA First Design School - Nairobi 20

Initial configuration code Only executed once

loop() is executed after setup () and keeps running until the Arduino is disconnected

Both functions are usually preceded by void These are functions without an output or result.

Page 21: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

2.2. Variables, constants, mathematical, logical and Boolean operators

• Variables: Boolean open=true; int conta=5; char id=‘a’;

• Constants: const float pi = 3.14

• Mathematical operators: = , - , + , / ,…

• Logical operators: == , > , != , <= ,…

• Boolean operators: && (and) , II (or) ,…

11th - 15th December 2017 UBORA First Design School - Nairobi 21

Page 22: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

2.3. Control structures

11th - 15th December 2017 UBORA First Design School - Nairobi 22

If

if (input<500) // action A else // action B

Switch/case

switch (var) case 1: // action A break; case 2: // action B break; default: // action B

For

for (int a=0; a>10; a++) // repeated action

While

while (a<10) // repeated action a++;

Page 23: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

2.4. Functions

11th - 15th December 2017 UBORA First Design School - Nairobi 23

pinMode()

Configurates a pin PinMode(pin,mode)

pinMode(13, OUTPUT);

pinMode(a, INPUT);

digitalWrite()

Writes 1 or 0 in a digital pin digitalWrite(pin,state)

digitalWrite(13, HIGH);

digitalWrite(13, LOW);

digitalRead()

Reads 1 or 0 in a digital pin digitalRead(pin)

int a = digitalRead(13);

analogRead()

Reads an analog pin (0-1023) analogRead(pin)

int a = analogRead(A0);

analogWrite() PWM

Reads an analog value (0-255) analogWrite(pin, PWM value)

analogWrite(9, 134);

Digital functions Analytical functions

Page 24: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

2.4. Functions

11th - 15th December 2017 UBORA First Design School - Nairobi 24

Advance

Random numbers

External interruptions

Time

Mathematical

Communication

Page 25: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

3. Arduino programming with Matlab

Benefits of using MATLAB for Arduino programming:

• Read/write sensor data interactively without waiting for your code to compile

• Analyze your sensor data using pre-built Matlab functions for signal processing, machine learning, mathematical modeling, …

• Quickly visualize your data (MATLAB plot types)

Disadvantage:

• Speed data trasnmision

NOTES:

• Is our arduino board compatible? https://es.mathworks.com/hardware-support/arduino-matlab.html

• Only allowed Matlab 2014 and later versions

More info: https://es.mathworks.com/discovery/arduino-programming-matlab-simulink.html

11th - 15th December 2017 UBORA First Design School - Nairobi 25

Page 26: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

3. Arduino programming with Matlab

Examples

• Mapping your surroundings using MATLAB and Arduino https://www.youtube.com/watch?v=iaF81W-l6Xg

11th - 15th December 2017 UBORA First Design School - Nairobi 26

Ultrasonic distance sensor

Servomotor

Page 27: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

4. Practical studies

11th - 15th December 2017 UBORA First Design School - Nairobi 27

Case 1: Blink led L

Aim: Arduino software/conect introduction

Steps:

1. Open arduino software

2. Open “blink” example

3. Read the code and understand it

4. Select the board and the port.

5. Load the code on the Arduino board. Few seconds after the "uploaded“ message appears, we see the LED blinking

Page 28: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

4. Practical studies

11th - 15th December 2017 UBORA First Design School - Nairobi 28

Case 2: Touch lamp

Page 29: Arduino and Matlab for prototyping and - ubora-biomedical.orgubora-biomedical.org/wp-content/uploads/2018/01/IV.-Arduino-and... · Arduino and Matlab for prototyping and manufacturing

This project has received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 731053

11th - 15th December 2017 UBORA First Design School - Nairobi 29