Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
158 views

Contents Motor Control Projects

This document outlines seven motor control projects using Arduino and Raspberry Pi. It begins with an overview of different types of electric motors and factors to consider when selecting a motor. It then describes the circuit diagrams and code for each project, which involve tasks like controlling motor speed and direction. The projects range from simple on/off control to more complex implementations using an H-bridge integrated circuit and rotary encoder.

Uploaded by

Mi Ms
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views

Contents Motor Control Projects

This document outlines seven motor control projects using Arduino and Raspberry Pi. It begins with an overview of different types of electric motors and factors to consider when selecting a motor. It then describes the circuit diagrams and code for each project, which involve tasks like controlling motor speed and direction. The projects range from simple on/off control to more complex implementations using an H-bridge integrated circuit and rotary encoder.

Uploaded by

Mi Ms
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Motor Control

Projects with Arduino


&
Raspberry Pi Zero W

Dogan Ibrahim

an Elektor Publication
LEARN DESIGN SHARE

Motor Control Projects UK 171004.indd 3 18-10-17 13:16


Content

PREFACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

CHAPTER 1 • ELECTRIC MOTORS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

1.2 Types Of Electric Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

1.3 Brushed DC Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

1.3.1 Permanent Magnet BDC Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

1.3.2 Series Wound BDC Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

1.3.3 Shunt Wound BDC Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

1.3.4 Compound Wound BDC Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

1.3.5 Separately Excited BDC Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

1.3.6 Servo Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

1.3.7 Stepper Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

1.4 Brushless DC Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

1.5 Motor Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

1.5.1 Torque . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

1.5.2 Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

1.5.3 Accuracy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

1.5.4 Operating voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

1.5.5 Cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

1.5.6 Physical size and weight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

1.6 Transfer Function of a Brushed DC Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

1.7 Torque – Speed Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

1.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

CHAPTER 2 • SIMPLE DC MOTOR PROJECTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

2.2 PROJECT 1 – Motor ON/OFF Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

2.2.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

2.2.2 Circuit Diagram – Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

2.2.3 Circuit Diagram – Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

2.2.4 Program Listing – Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

2.2.5 Program Listing – Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

2.2.6 Using a MOSFET Transistor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

●5

Motor Control Projects UK 171004.indd 5 18-10-17 13:16


Motor Control - Projects with Arduino & Raspberry Pi Zero W

2.2.7 Using a Relay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

2.3 PROJECT 2 – Two Speed Motor Speed Control . . . . . . . . . . . . . . . . . . . . . . . . . . 37

2.3.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

2.3.2 Circuit Diagram – Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

2.3.3 Circuit Diagram – Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

2.3.4 Program Listing – Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

2.3.5 Program Listing – Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

2.4 PROJECT 3 – Varying the Motor Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

2.4.2 Circuit Diagram – Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

2.4.3 Circuit Diagram – Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

2.4.4 Program Listing – Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

2.4.5 Program Listing – Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

2.5 PROJECT 4 – Changing the Motor Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

2.5.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

2.5.2 Circuit Diagram – Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

2.5.3 Circuit Diagram – Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

2.5.4 Program Listing – Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

2.5.5 Program Listing – Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

2.6 PROJECT 5 – Using H Bridge Integrated Circuit . . . . . . . . . . . . . . . . . . . . . . . . . 63

2.6.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

2.6.2 Circuit Diagram – Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

2.6.3 Circuit Diagram – Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

2.6.4 Program Listing – Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

2.6.5 Program Listing – Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

2.7 PROJECT 6 – Motor Speed and Direction Control Using H Bridge Integrated Circuit . 70

2.7.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

2.7.2 Circuit Diagram – Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

2.7.3 Circuit Diagram – Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

2.7.4 Program Listing – Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

2.7.5 Program Listing – Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

2.8 PROJECT 7 – Using a Rotary Encoder - Displaying the Speed of a Motor


2.8 (Arduino Uno) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

●6

Motor Control Projects UK 171004.indd 6 18-10-17 13:16


Content

2.8.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

2.8.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

2.8.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

2.9 PROJECT 8 - Displaying Motor Speed on LCD (Arduino Uno) . . . . . . . . . . . . . . . . . 83

2.9.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

2.9.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

2.9.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

2.10 PROJECT 9 - Identification of the DC Motor (Arduino Uno) . . . . . . . . . . . . . . . . 89

2.10.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

2.10.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

2.10.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

2.11 PROJECT 10 – Closed Loop PID Speed Control of a DC Motor . . . . . . . . . . . . . . . 92

2.11.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

2.11.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

2.12 PROJECT 11 – Using a Rotary Encoder - Displaying the Speed of a Motor


2.12 (Raspberry Pi Zero W) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

2.12.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

2.12.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

2.13 PROJECT 12 - Displaying Motor Speed on LCD (Raspberry Pi Zero W) . . . . . . . . 101

2.13.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

2.13.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

2.14 PROJECT 13 – Using Timer Interrupts to Calculate the Motor Speed


2.14 (Arduino Uno) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

2.14.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

2.14.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

2.8.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

2.15 PROJECT 14 – Mobile Robot Basic Control (Arduino Uno) . . . . . . . . . . . . . . . . . 109

2.15.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

2.15.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

2.15.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

2.16 PROJECT 15 – Obstacle Avoiding Robot (Arduino Uno) . . . . . . . . . . . . . . . . . . . 117

2.16.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

2.16.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

●7

Motor Control Projects UK 171004.indd 7 18-10-17 13:16


Motor Control - Projects with Arduino & Raspberry Pi Zero W

2.16.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

2.17 PROJECT 16 – Line Following Robot (Arduino Uno) . . . . . . . . . . . . . . . . . . . . . 123

2.17.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

2.17.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

2.17.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

2.18 PROJECT 17 – Mobile Robot Basic Control (Raspberry Pi Zero W) . . . . . . . . . . . 131

2.18.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

2.18.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

2.18.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

2.19 PROJECT 18 – Obstacle Avoiding Robot (Raspberry Pi Zero W) . . . . . . . . . . . . . 137

2.19.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

2.19.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

2.19.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

2.20 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

CHAPTER 3 • SIMPLE STEPPER MOTOR PROJECTS . . . . . . . . . . . . . . . . . . . . . . . . 144

3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

3.1.1 Unipolar Stepper Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

3.1.2 Bipolar Stepper Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

3.1.3 Speed of a Stepper Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

3.1.4 Movement of the Motor Shaft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

3.1.5 Motor Rotation Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

3.2 PROJECT 1 – Basic Stepper Motor Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

3.2.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

3.2.2 Circuit Diagram (Arduino Uno) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

3.2.3 Circuit Diagram (Raspberry Pi Zero W) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

3.2.4 Driving the Stepper Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

3.2.5 Program Listing (Arduino Uno) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

3.2.6 Program Listing (Raspberry Pi Zero W) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

3.3 PROJECT 2 – Thermometer With Dial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

3.3.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

3.3.2 Circuit Diagram (Arduino Uno) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

●8

Motor Control Projects UK 171004.indd 8 18-10-17 13:16


Content

3.3.3 Circuit Diagram (Raspberry Pi) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

3.3.4 Program Listing (Arduino Uno) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

3.3.5 Program Listing (Raspberry Pi Zero W) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

3.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

CHAPTER 4 • SIMPLE SERVO MOTOR PROJECTS . . . . . . . . . . . . . . . . . . . . . . . . . . 172

4.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

4.2 PROJECT 1 – Basic Servo Motor Control (Arduino Uno) . . . . . . . . . . . . . . . . . . . 172

4.2.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

4.2.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

4.2.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

4.3 PROJECT 2 – Controlling the Servo Motor with a Potentiometer (Arduino Uno) . . . 176

4.3.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

4.3.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

4.3.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

4.4 PROJECT 3 – Basic Servo Motor Control (Raspberry Pi Zero W) . . . . . . . . . . . . . 179

4.4.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

4.4.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

4.2.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

4.5 PROJECT 4 – Moving the Motor Shaft to a Given Angle (Raspberry Pi Zero W) . . . 183

4.5.1 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

4.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185

CHAPTER 5 • ARDUINO BLUETOOTH ROBOT CONTROL . . . . . . . . . . . . . . . . . . . . . 186

5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

5.2 PROJECT 1 – Bluetooth Based Remote Robot Control . . . . . . . . . . . . . . . . . . . . 186

5.2.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

5.2.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

5.2.3 Android Mobile Phone Apps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188

5.2.4 Pairing the HC-06 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

5.2.5 Controlling the Robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190

5.2.6 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192

5.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198

●9

Motor Control Projects UK 171004.indd 9 18-10-17 13:16


Motor Control - Projects with Arduino & Raspberry Pi Zero W

CHAPTER 6 • ARDUINO WI-FI ROBOT CONTROL . . . . . . . . . . . . . . . . . . . . . . . . . . 199

6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199

6.2 PROJECT 1 – Wi-Fi Based Remote Robot Control . . . . . . . . . . . . . . . . . . . . . . . 199

6.2.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199

6.2.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

6.2.3 UDP or TCP ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

6.2.4 Android Mobile Phone Apps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

6.2.5 Controlling the Robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203

6.2.6 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204

6.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211

CHAPTER 7 • RASPBERRY PI ZERO W WI-FI ROBOT CONTROL . . . . . . . . . . . . . . . 212

7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212

7.2 PROJECT 1 – Wi-Fi Based Remote Robot Control . . . . . . . . . . . . . . . . . . . . . . . 212

7.2.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212

7.2.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212

7.2.3 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213

7.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220

CHAPTER 8 • RASPBERRY PI ZERO W BLUETOOTH ROBOT CONTROL . . . . . . . . . . 221

8.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

8.2 PROJECT 1 – Bluetooth Based Remote Robot Control . . . . . . . . . . . . . . . . . . . . 221

8.2.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

8.2.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

8.2.3 Enabling Bluetooth on Raspberry Pi Zero W . . . . . . . . . . . . . . . . . . . . . . . . . . 221

8.2.4 Python Bluetooth Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224

8.2.5 Accessing From the Mobile Phone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224

8.2.5 Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224

8.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230

APPENDIX A • RASPBERRY PI ZERO W . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231

A.1 The Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231

A.2 Setting Up the Raspberry Pi Zero W . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232

A.3 Installing the Operating System on SD Card . . . . . . . . . . . . . . . . . . . . . . . . . . 232

● 10

Motor Control Projects UK 171004.indd 10 18-10-17 13:16


Content

A.4 Applying Power to the Raspberry Pi Zero W . . . . . . . . . . . . . . . . . . . . . . . . . . . 235

A.5 Setting Up the WiFi and Remote Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

A.6 Shutting Down or Rebooting in GUI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242

A.7 Remote Access of the Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243

A.8 Enabling Bluetooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

A.9 Creating and Running a Python Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246

A.10 GPIO Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248

A.10.1 Pin Numbering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248

A.10.2 Channel (I/O port pin) Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249

APPENDIX B • LIST OF COMPONENTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252

APPENDIX C • ARDUINO UNO PIN DIAGRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253

APPENDIX D • RASPBERRY PI ZERO W PIN DIAGRAM . . . . . . . . . . . . . . . . . . . . . 254

APPENDIX E • USING THE gpiozero LIBRARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258

● 11

Motor Control Projects UK 171004.indd 11 18-10-17 13:16

You might also like