lab 2: arduino - u-m personal world wide web serverfrankxu/chinese/images/job/engr... · 2017. 12....

Post on 26-Aug-2021

1 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Lab 2: Arduino

Zhentao Xu

Today’s schedule

• Lecture 1: Arduino

• Install Arduino driver

• Lab 1: use Arduino UNO to control LED.

• Lecture 2: Sensor and Feedback

• Lab 2: use Arduino UNO and ultrasonic distancesensor to measure distance

• Lecture 3: Minimum system

• Lab 3: Building minimum system using AVR chip.

What is Arduino?

• Official definition: A combination of hardware, software, development team, design philosophy.

• From Ivrea, Italy.(意大利的艾维里)

• Hardware include Arduino UNO and Arduino Mega, Software include Arduino IDE.

• Arduino UNO: Development board of AVR chips.

• Arduino UNO is announced in 2011.

• UNO Punto Zero (1.0)

What can Arduino UNO do?

Self-balanced Car

What can Arduino UNO do?

LED-Cubic

Arduino Components

Processor

USB

PortsPower

Supply power & Serial Communicate

Connection with outside world

Supply power

Process information & Make decision

Real Circuit Diagram

Install Arduino driver

Refer to the PDF file from the announcement on SAKAI.

For Windows 7 Operating Systen:

• Step 1: Download Arduino IDE and unzip it.• http://arduino.googlecode.com/files/arduino-1.0.5-r2-

windows.zip

• Step 2: Plug in Arduino UNO board.

• Step 3: Right-click This PC Manage Other device Right-click Unknown deviceUpdatedriver Scan the driver folder in Arduino IDE.

For Windows 8/8.1, please refer to PDF file.

For Mac OS/Linux, Skip this slides.

Arduino IDE

Arduino IDE

• An integrated development environment designed for Arduino hardware.

• The language is C++ - like.

• Process of doing Arduino Project:• Connect hardware with Arduino UNO

• Write program on Arduino IDE.

• Download it onto Arduino UNO.

• Power Arduino UNO on and enjoy it.

Arduino IDE

• Structure: two necessary functions:

1. void setup(){}

2. void loop(){}

• The relationship between Arduino Language andC++ Language.

• Important sentence:pinMode (PinNumber,Mode); (general in setup(){};)

digitalWrite (PinNumber, DigitalVoltage);

delay (MiliSeconds);

Lab #1: Light up LED

• Requirement:• Light up LED and keep 3 seconds, than power it off and

keep 3 seconds.

• Repeat the procedure.

• DIY

Quite easy, right?

void setup()

{

//Connect LED resistor on pin 13.pinMode(13,OUTPUT);

}

void loop()

{

digitalWrite(13,HIGH);

delay(5000);

digitalWrite(13,LOW);

delay(5000);

}

Quick Review

• You have controlled the On and Off of LED by control the output voltage of a certain port.

• The voltage on pin 13 is called digital signal, which can be either 1 (logical-high voltage) or 0 (logical-low voltage).

• Actually, Arduino UNO can output/input digital/analog signals.

Sensor(传感器)

• Arduino is like a brain. It also needs ears, eyes, nose, etc. to measure quantities in outside environment.

• Sensor serves as the connection between Arduino and the outside environment.

• So called Feed back control

Temp. Sound

Light …

Environment

Velocity Sensor -- Tachometer

Velocity sensor –Tachometers

Where K is the back EMF constant.

Every car has a tachometer so as to measurer to measure speed.

(t) K (t)t vwV

Temperature Sensor

• Three classes f temperature sensors:• Thermometers and bimetallic strips ---- Sensors which

change physical dimension as a function of temperature.

• RTDs and thermistors ----Sensors which change resistance as a function of temperature.• RTD:

• Thermistor:

• Thermocouples ----Sensors which work based on thermoelectric phenomena

0 0(1 (T T ))R R

0

1 1( )

0

T TR R e

Ultrasonic sensor

• Ultrasonic sensors are used to measure distance.

• An impulse of ultrasonic wave is emitted from the sensor. The wave will reflect when reaches some obstacles. The time between emission and receiving will be calculated.

• Use formula to calculate the distance.

/ 2L Vt

HC-SR04 ultrasonic sensor

• Four pins (GND, VCC, Trig, Echo)

• GND and VCC is the power supply to this module.

• Arduino UNO send message to Trig, and read message from Echo.

Serial Ports (COM,串口) Communication• Serial is one way in which information is transferred

between computer & Arduino.

• Information can also be transferred using Parallel Ports.(并口)

• Two important sentence of serial communication.• Serial.begin(BaudRate); (must be in setup())

• Serial.write(message);

Lab 2: Use ultrasonic sensor to measure distance

Electronic components Number Note

Arduino UNO 1 With USB wire

HC-SR04 Sensor 1

Wires 4

Arduino UNO HC-SR04 Note

GND GND

VCC VCC

A1 (Pin 15) Trig

A0(Pin 14) Echo

Lab equipment:

Wire connection

Program

void loop(){digitalWrite(TrigPin, LOW); delayMicroseconds(2); digitalWrite(TrigPin, HIGH); delayMicroseconds(5); digitalWrite(TrigPin, LOW); cm = int(pulseIn(EchoPin, HIGH) / 58.0);Serial.println(cm);

}

const int TrigPin = 15; const int EchoPin = 14; float cm; void setup(){Serial.begin(9600);pinMode(TrigPin, OUTPUT); pinMode(EchoPin, INPUT);

}

Quick Review

• Sensor: connection between Arduino and outside environment.

• Serial: one way in which information is transferred.

AVR

• AVR is a family of MCU chips which are produced by ATMEL Company.

• The AVR chip on Arduino UNO is Atmega328.

• The AVR chip on Arduino MEGA is Atmega2560

• Working environment:• Stable 5V power supply

• Time reference input

• (RESET)

Atmega328P-PU

• Pin number and counting order.

• Significant pin for working.• Power supply: PIN7,

PIN8, PIN20, PIN22.

• RESET: PIN1

• Timing: PIN9, PIN10

• Serial Ports: PIN2, PIN3

Min. Sys. Of Atmega328P-PU

• Minimum system: MCU chip with simplest peripheral circuit. (外围电路).

• Below is the circuit for min. sys. of Atmega328P.

Lab 3: Min. Sys. Of Atmega328P

• Step 1 Remove the MCU chip on Arduino.

Step 2. Build the minimum system

Step 3 Connect LED and download program• Connect the series of LED and resistor to pin GND

and pin 19.

• Connect the Arduino PCB and your computer as is done in Lab 1.

• Write exactly the same program as in Lab 1 without any change.

• Click the Download button.

• See what happen~~^_^

Step 3 Connect LED and download program• When the download process has been down, you

can remove the RESET line and RX TX line, just leaving the VCC and GND so as to give power to the Atmega328.

A Quick Review

• In the lab 3, we connect the LED to pin GND and Pin 19, but actually in the program we define the Port 13, why?

Reference

• [1] Arduino Internal, Wheat, Dale.

• [2] Slides of Dr. Huang Peisen.

• [3] www.arduino.cc

top related