Sei sulla pagina 1di 46

ARDUINO ADVANCED TRAINING

Connectivity, Control & Communication


Class Requirements
■ Completed Arduino Basic Class
- LCD SETUP
- TEMPERATURE SENSOR
- ARDUINO PROGRAMMING
- SERIAL MONITOR

■ Familiar with Arduino IDE & libraries


installation

■ Basic knowledge of electronics

■ Basic knowledge of programming

■ Willing to experiment/learn/explore
Training Outline
• DC Motor & Stepper Motor Control
– Control Motor Forwards and Reverse

• Bluetooth
– Bluetooth communication

• How to use SIM900 GSM Shield


– Make a call to Mobile Phone
– Send_ SMS to Mobile Phone
– Receive Incoming Call
– Receive Message from Mobile Phone
1. How to use DC Motor Control

• DC Motor Forwards and Reverse

• Control Speed by using Ultrasonic sensor


DC Motor Forward and Reserve
• In order to control DC motor by Arduino, a Motor Driver is
needed
DC Motor Forward and Reverse

• 2 Channels DC Motor Driver Module is able to use in controlling 2 DC


brush motors neither rotate direction nor speed of motor.

• Beside 2 DC brush motor, it may use to control a single stepper motor

• Its driving current is up to 2a per motor


Motor Driver

Motor +

Motor -

• High voltage, high current dual full-


bridge driver

• Two enable inputs


UNO: UNO:
• Driver power supply: +5V GND 5V
UNO:
5v

SeeedStudio L298 Dual


H-Bridge Motor Driver
Circuit

MOTOR
DRIVER
MOTOR

UNO + MOTOR DRIVER + DC MOTOR


DC Motor Forward and Reverse

Pin Description Function


5V Logic Voltage Input Power supply to the module, connect to 5V
GND Common Ground Connect to ground
VCC Drive Voltage Input Power supply to the motor, 4.8V to 16V
IN1, IN2, IN3, IN4 Motor Control Pin Control motors rotate direction, either
clockwise or anticlockwise
OUT1, OUT2, OUT3, Motor Terminal Connect to the motors
OUT4
L1, L2, L3, L4 Motor status LED Indicate the status of the motor
SW1 Share Power Source selected ON: share the drive power to logic power
Switch OFF: Logic power isolated from drive power
ENA, ENB Motor PWM Control Pin Control PWM (speed) of the motor
DC Motor Forward and Reverse
Motor 1
IN1 IN2 Motor Rotation
0 0 Stop rotate
Motor 1/ Motor 2
0 1 Clockwise
1 0 Anticlockwise ENA / ENB PWM (%) Motor’s Speed

1 1 Stop rotate 100% or 5V Maximum speed

Motor 2
increase Increase
IN1 IN2 Motor Rotation
0 0 Stop rotate
0 1 Clockwise 0% or 0V Zero speed or stop
1 0 Anticlockwise
1 1 Stop rotate
Hands-On 6
• Build a system which include Arduino UNO,
Motor Driver, Motor and a button.
• When
Button is pressed for first time, motor runs in one
direction .
Button is pressed for second time, motor runs in
another direction.
Button is pressed for third time, motor stop.
The sequence is repeated
• You may use any speed for the motor
Motor Driver

Motor +

Motor - UNO:
Pin 10

UNO: UNO:
Pin 9 Pin 8

UNO: UNO:
GND 5V
UNO:
5v

SeeedStudio L298 Dual


H-Bridge Motor Driver
Stepper Motor Control
• Control Stepper Motor Forward and Reverse.
Introduction
Hands-On 8
• Build a Arduino System which consists of a button, Motor
Driver and a stepper motor
• When
 Button is pressed for first time, stepper motor runs in one
direction .
 Button is pressed for second time, stepper motor runs in
another direction.
 Button is pressed for third time, stepper motor stop.
 The sequence is repeated
Connection
• IN1  Arduino Pin 9
• IN2  Arduino Pin 8
• IN3  Arduino Pin 7
• IN4  Arduino Pin 6
• Button  Arduino Pin A0
2. How to use Bluetooth HC-05
Introduction

• HC-05 Bluetooth Module is an easy to use Bluetooth SPP ( Serial


Port Protocol ) module, designed for transparent wireless serial
connection setup.

• Use to transfer data wireless


Introduction

Pin Description Function


VCC +5V Connect to +5V
GND Ground Connect to Ground
TXD UART_TXD, Bluetooth serial Connect with the MCU’s (Microcontroller and
signal sending PIN etc) RXD PIN
RXD UART_RXD, Bluetooth serial Connect with the MCU’s (Microcontroller and
signal receiving PIN etc) TXD PIN
KEY Mode switch input If it is input low level or connect to the air, the
module is at paired or communication mode. If
it’s input high level, the module will enter to AT
mode.
Practical 5

 By using Bluetooth HC-05, Button, LCD and Arduino, build a


Bluetooth system which able to transfer data and receive data
from Smart Phone.

 The LCD will display the data when data received from Smart
Phone.

 When button on system is pressed, the message “Button


Pressed” will send to smart phone via bluetooth.
connection
3. How to use SIM900 GSM Shield
Contents
 Introduction to SIM900 GSM Shield
 Make a call to Mobile Phone
 Send_ SMS to Mobile Phone
 Receive Incoming Call
 Receive Message from Mobile Phone
Introduction to SIM900 GSM Shield

 Sim900 GSM GPRS Shield provides a simple way to let


your Arduino connect to your cell phone via GSM/GPRS
network.

 You can use AT commands to


– Make a call to Mobile Phone
– Send_ SMS to Mobile Phone
– Receive Incoming Call
– Receive Message from Mobile Phone
Introduction to SIM900 GSM Shield

AT Commands via
Serial Communication
Introduction to SIM900 GSM Shield
Power On and UART Connection
Reset Button Setting

Antenna Ear Phone


Connector Connector

Mic
Connector
Introduction to SIM900 GSM Shield

Copy GSM_Shield  paste  Libraries


 To make a call to mobile phone via GSM Shield, below class
function will be used.

 void GSM::TurnOn( long baud_rate)


 Enable Serial Communication between Arduino and GSM Shield. It also
power on the SIM900 module. Use to initialize.

 Long baud_rate : set the baud rate for serial communication.

 Example :gsm.TurnOn(9600);
Make a call to Mobile Phone
• Practical 1
 Build a system which contains 2 button (Button 1 and Button 2 )
and GSM Shield.

 When Button 1 is pressed, the system make a call to mobile


phone while when Button 2 is used to hang up.

• Note
1. SIM900-POWER connect to Arduino Pin 9.
2. SIM900-RST connect to Arduino Pin 8.
3. SIM900 require Minimum 2A to operate.
Make a call to Mobile Phone
Step 1

• Insert SIM card into the GSM/GPRS Shield board.

• Before this, make sure the inserted SIM Card has enough credit and
not expiry.
Insert Sim Card
Make a call to Mobile Phone

• After uploading program to the Arduino UNO Board,


attach the GSM/GPRS Shield board on Arduino UNO.
Make a call to Mobile Phone

• Plug in external power source with minimum 2 Ampere to the


Arduino Board.

• And test run.


Send message (sms) to mobile phone

To send message to mobile phone via GSM Shield.


Send message (sms) to mobile phone
• Practical 2
 Based on [Practical 1], write a source code to have below
behaviour.

 When Button 1 is pressed, the system will send a message


“Hello World!” to the mobile phone.
Receive a call from mobile phone
 To receive call from mobile phone via GSM Shield, below function
will be used.

 byte GSM::CallStatusWithAuth (char*phone_number, byte


first_authorized_pos,byte last_authorized_pos)

 Check status of call (incoming or active) and makes authorization with


specified SIM positions range.
 char*phone_numbe : a pointer to the incoming phone number.
 byte first_authorized_pos : Initial SIM phonebook position where the
authorization process starts.
 byte last_authorized_pos : Last SIM phonebook position where the
authorization process end.
Receive a call from mobile phone
• Return:
 CALL_NONE - no call activity
 CALL_INCOM_VOICE_AUTH - incoming voice - authorized
 CALL_INCOM_VOICE_NOT_AUTH - incoming voice – not authorized
 CALL_ ACTIVE_VOICE - active voice
 CALL_INCOME_DATA_AUTH - incoming data call – authorized
 CALL_INCOM_DATA_NOT_AUTH - incoming data call – not authorized

 Example : gsm.CallStatusWithAuth(number_incoming,0,0);
Receive a call from mobile phone
• Practical 3

 Build a system by using Arduino UNO which includes GSM


Shield and LCD, when there is incoming call from mobile
phone, display incoming phone number on LCD.
Receive message from mobile phone
• To receive message from mobile phone via GSM Shield, below
function will be used.

 Char GSM::IsSMSPresent(byte required_status)


• Finds out if there is present at least one SMS with specified status
• Byte required_status:
 SMS_UNREAD - new SMS – not read yet
 SMS_READ - already read SMS
 SMS_ALL - all stored SMS

• Return:
 SMS position in SIM card memory

• Example : position = gsm.IsSMSPresent(SMS_UNREAD);


Receive message from mobile phone
• Practical 4

 Based on [Practical 3], add 3 LEDs (LED1, LED2, LED3) to the


system. The system will response upon the receiving text
message from mobile phone. The behaviour as below:

 When receiving text message from mobile


 “LED1”  LED1 turn on, else turn off, LCD display receiving message.
 “LED2”  LED2 turn on, else turn off, LCD display receiving message.
 “LED3”  LED3 turn on, else turn off, LCD display receiving message.
Receive message from mobile phone
• LED1  Analog Pin A0
• LED2  Analog Pin A1
• LED3  Analog Pin A2
THANK YOU

Potrebbero piacerti anche