0% found this document useful (0 votes)
4 views

Robot Programming Using Arduino E

Uploaded by

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

Robot Programming Using Arduino E

Uploaded by

btadmouri
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 70

Robot programming using

Arduino
Robot programming using
Arduino

1 Contents

2 Introduction
............................................................................................................................................. 4

3 Program
Guide........................................................................................................................................ 5

4 Trainee Guidelines
................................................................................................................................. 6

5 Section I: Required Equipment


............................................................................................................ 7

5.1 Hardware and software used


........................................................................................................... 8

5.1.1 Registration on the TankerCAD


website................................................................................ 8

5.1.2 How to download a program Arduino IDA


............................................................................ 9

6 Section II: Introduction to the world of robotics

............................................................................11 6.1 What is a robot?

.................................................................................................................................. 12

6.1.1 First activity:.................................................................................................................................


12

6.2 Types of robots....................................................................................................................................


13

6.3 Science related to robotics


.............................................................................................................. 14

6.4 Robot components


............................................................................................................................. 15

6.4.1 Inputs..............................................................................................................................................
15

6.4.2 Outputs...........................................................................................................................................
15

6.4.3 Controller ......................................................................................................................................


15

6.5 Arduino Microcontroller:


.................................................................................................................. 16

7 Section III: Lighting and


Motors.........................................................................................................17

7.1 First Session: Lighting and Sound


(Alarm).................................................................................18
1
7.1.1 element LED ‫ ؟‬............................................................................................................................
18

7.1.2 How it works ................................................................................................................................


18
Robot programming using Arduino

7.3.2 How it works ................................................................................................................................ 23

7.3.3 Fourth Activity: Lighting Spear............................................................................................... 24

7.3.4 Fifth Activity: Lighting Programming for a Certain Number of Times

.......................26 7.4 Lighting element RGB LED

.............................................................................................................. 28 7.4.1 What is an

element RGB LED ‫ ؟‬.............................................................................................. 28 7.4.2

How it works ................................................................................................................................ 28

7.4.3 Activity 6: Lighting Control RGB LED

....................................................................................29

7.5 Electric
buzzer..................................................................................................................................... 31

7.5.1 What is an electric buzzer


....................................................................................................... 31

7.5.2 How it works


................................................................................................................................ 31

7.5.3 Activity 7: Ambulance Warning


.............................................................................................. 32

7.6 Session II: Electric Motors


............................................................................................................... 33

7.6.1 What is an electric


motor......................................................................................................... 33

7.6.2 Types of electric


motors........................................................................................................... 33

7.6.3 Activity 8: Servo Motor


Programming..................................................................................35

7.6.4 Circuit connection


....................................................................................................................... 35

7.7 Session III: Digital Inputs


.................................................................................................................. 38

7.7.1 Signals (digital) Digital


.............................................................................................................. 38

7.8 Electric button pushbutton


.............................................................................................................. 39

7.8.1 What is an element Pushbotton


............................................................................................. 39

7.8.2 How it works


................................................................................................................................ 39

7.8.3 Activity 9: Button 2


Programming............................................................................................. 40

7.9 Quiz
......................................................................................................................................................... 42
Robot programming using Arduino

8.2.1 What is variable resistance ..................................................................................................... 47

8.2.2 How it works ................................................................................................................................ 47

8.2.3 First activity: control of the speed and intensity of lighting

..........................................48 8.3 Optical Resistance

LDR..................................................................................................................... 50 8.3.1 What is

the optical resistance ................................................................................................ 50 8.3.2

How it works ................................................................................................................................ 50

8.3.3 Second activity: Lighting control by lighting

sensor........................................................51

8.4 Distance sensor


(Ultrasonic)........................................................................................................... 53

8.4.1 What is the distance sensor


.................................................................................................... 53

8.4.2 How the sensor works


.............................................................................................................. 53

8.4.3 Third Activity: Distance Sensor Programming


..................................................................54

8.5 Digital Editing Function


PWM.......................................................................................................... 57

8.5.1 What is a property PWM


........................................................................................................... 57

8.5.2 Fourth activity: lighting intensity using PWM


....................................................................57

6. Session II: Sending commands and data from Arduino to the


computer.........................58

1. Fifth Activity: Reading the Sensor Value of the Lighting Sensor


.................................60

2.Sixth Activity: Sending data to Arduino and lighting control

........................................62 8.7 Display LCD 16*2

............................................................................................................................... 64 8.7.1 What is

a display......................................................................................................................... 64

8.7.2 How it works


................................................................................................................................ 64

8.7.3 Activity VII: Word printing Hello World On screen

...........................................................65 8.8 Quiz

......................................................................................................................................................... 67
3
8.9 Challenges
............................................................................................................................................ 68

8.9.1 First Challenge:


Robot programming using
Arduino

2 Introduction

Praise be to Allah alone, and prayers and peace be upon those after
whom there is no prophet, Muhammad, and upon the machine and
all his companions. And after:

We also know that education is one of the most important magazines


that elevate societies and we as a team believe that construction
begins from a young age and that the impact when it comes at an
early age , its impact is great on the behavior, thinking and culture of
individuals.

In this bag, we seek to deliver some scientific concepts that help the
trainee to understand the basic principles in the design and
programming of the robot, as the stages of designing the robot
depend on multiple sciences, for example, when building any robot, the
structure of the robot must be formed, and in order to design the
structure, it is necessary to deal with the principles of mechanical
design such as (determining dimensions, determining cutting weights,
determining the center of gravity, gears, pulleys, etc.), and in order for
this mechanical model to move, it must be Adding electronic
elements to it from sensors and motors and then we program them in
order to perform the required functions.

4
Robot programming using Arduino

3 Program Guide
 Software Name: Robot Programming Using Arduino Microcontroller

 The general objective of the program: To identify the basics of


robot programming and related scientific concepts
 Detailed objectives:

• Enhance participants' awareness of the use of modern


technologies
• Participants' ability to understand the basics and
components of the robot
• Identify the concept of programming and the functions and
commands
related to it
• Employing the trainee's mathematical and engineering
knowledge using the robot
• Learn about the most common types of sensors and controllers
and how
to use them
• Understand the principles of variables, conditional sentences,
and iterative functions in programming

 Target Audience: Male and female students aged 15 to 18 years.


 Program Duration:

(3) days, at a rate of (8) training hours


per day.

 Program Implementation Requirements:

• Computer.
• Internet
• ZOOM
• Register for a CAD Mask
account
• Register on Onshape

5
Robot programming using
Arduino

4 Trainee Guidelines

Brother trainee, we hope to take into account the following guidelines


for their importance in achieving the objectives of the training program:

1- Commitment to attend

all sessions 2- Apply all

activities in the bag

3 Interact with the group when


assigning you a task

4 Work on practical application and link it to

reality 5- Relying on yourself in building

projects

6- Try and confirm each step before moving


on to the next step

6
Robot programming using
Arduino

5 Section I: Required Equipment

Session Title: What Do I Need

Session time: 30

minutes Objectives:
- Register on
Tankrickad
- Download Arduino
IDA
- Recognize the
Tinkercad
Session
encountered
Requirements:

 Laptop
 Internet
 Register on
Tankrickad

7
Robot programming using Arduino

1. Hardware and software used

In order to understand the content, training and practical application,

you must first: 1- Register on Tankrickad


2- Download Arduino IDA

1. Register on Tankrickad

1 Go to the https://www.tinkercad.com/ website


2 Click on the Join Now icon at the top of the page

3- Click on the Create a personal


account icon

4- Choose the method of


subduction

5- Complete the application until you reach the


home page
8
Robot programming using Arduino

2. How to download Arduino IDA

1 Go to the https://www.arduino.cc/en/software website


2 Browse the site down until you arrive Choose your
device version

3- Click on the Just


Download icon

4- When the file is finished downloading to the device, click on it and proceed
with the installation and please allow the driver installation process when
you receive a warning from the operating system.

9
Robot programming using
Arduino

- You can watch the video clip to learn how to install the program and how to
register on the CAD disguise site

https://youtu.be/2CbNabqbwyE

10
Robot programming using
Arduino

6 Section Two: Introduction to the World of Robotics

Session Title: Introduction to the World of Robotics Programming

Session time: 45

minutes Objectives:
- Learn about the
concept of robot and
the sciences related
to robot building
- Know the basic
components of any
robot
- Identify the concept
of inputs and outputs
and differentiate
between them
- Identify the Arduino
controller

Session Requirements:

 Laptop
 Internet
 Register on
Tankrickad

11
Robot programming using Arduino

6.1 What is a robot?

There is no single definition adopted in the definition of a robot, as there are


several definitions, but we may summarize the definition that a robot is a
programmable mechanical machine that performs a certain function.

Another definition:

It is any device that replaces a human to perform a certain function

Example:

- E-Portal

Replaced the security man to do


his job

6.1.1 First Activity:

From the previous definition, can you cite examples of robots in our daily
lives?

.....................................................................................................................................................................................
......
...................................................................................................................................................................................
........
............................................................................................................................. .................................

12
Robot programming using Arduino

6.2 Types of robots

Our daily lives are hardly devoid of watching many examples of robots, and
here we will divide some of the types of robots based on applications

Military Medical Aquatic


robot Robot robot

Industri
Android
al
Tutorial

13
Robot programming using Arduino

3. Science related to robotics

There are three basic related sciences related to robot construction and design:

 Mechanics
 Electronics & Electrical
 Programming

‫ﻣﯿﻜﺎ ﻧ ﯿﻜﺎ‬ ‫ﺔﺠ اﻣ ﻟﺮﺒ‬

‫ت‬
‫اﻻﻟﻜﺘﺮوﻧ ﯿ ﺎ‬

Where when building any robot you will need a team specialized in these
sciences, we need mechanics at the beginning of the design you need to design
the structure of the robot and calculate and distribute loads and also you may
need to build mechanical mechanisms to implement a specific project and then
comes the science of electronics and electricity and after the implementation and
selection of the appropriate design for the robot begins the stage of choosing the
appropriate sensors and motors for the implementation of the project and also the
design of electrical circuits and the selection of the appropriate power source and
then comes the programming stage where we program the robot Using sensors
and motors for the required important implementation.

14
Robot programming using Arduino

4. Robot components

A robot generally consists of three basic things in order to be controlled.

 Input
 Output
 Control

6.4.1 Input

Input: It is any element that sends information to the controller, such as


sending the temperature or the intensity of lighting, and this information
is usually through sensors.

6.4.2 Output

Outputs: It is any element that receives commands from the controller, such as
electric motors, where the outputs run out of movement or reaction commands
for the robot

6.4.3 Control

The controller is considered as the brain of the robot, as it contains a number


of entrances that receive electrical signals resulting from sensors, through
which it will be able to identify and explore the surrounding environment and
thus be able to interact with this data according to the pre-integrated program.
The controller also has a number of outputs that enable it to send electrical
signals, whether to the engine or any other receiver.

Example:
The human body, the human mind is in control of his body, so it is equivalent
to the controller (controller) and to interact with man and take his decisions,
there must be inputs to his mind so that he interprets what is around him, if we
take the relationship of the eye with the mind, we know that the eye sends
certain nerve signals to the brain, which interprets them and the mind takes the
decision on them, so the eye provides the mind with information, so we call it
inputs.
If we take an example of the opposite, which is the muscles of the forearm,
they do not send the mind any information, but they take information from the
mind in the form of commands and move, so we call them outputs, meaning that
the information comes out of the mind to them.

15
Robot programming using Arduino

6.5 Arduino Microcontroller:

It is an open source electronic board designed to develop many ideas and projects
related to self- control in an easy and simple way by using open source programs
Arduino C, which is available for free.

1- Digital Pins and


ports 2- Analog
Pins input
3- USB connectivity
port 4- Rest
Button
5- Power Outlets
5V 6- Power input
7-12V

16
Robot programming using
Arduino

7 Section Three: Lighting and Motors

Session Title: Portal

Session time: 5

hours Objectives:

 Identification of
electronic
elements:
 LED
Lighting
 Buzzer
Electrop
horesis
 Identify the
types of electric
motors and the
difference
between them
 Learn how to
connect
electric motors
 servo
servo
motor
 DC
Motor
 Stepper
step
motor
 Programming:
Session
 Output
Requirements:
Program
 Laptopming
(LED,
 Register on
Buzzer)
Tankrickad
 Delay
Program
ming
comman
d
 Finite
frequenc
y
function
 Continuo
us
repetitio 17
n
function
 Output
Robot programming using Arduino

1. First Session: Lighting and Sound (Alarm)

1. LED element ?

 It is a light source made of semiconductor materials


that emit light when an electric current passes
through it.
 Available in different colors (red - green - blue -
yellow)
 It has a positive pole and a negative pole where the
tall leg Hess is the positive side and the short leg is
the negative side

7.1.2 How it works

The passage of electric current through the light-emitting diode raises atoms in
the semiconductors used in the manufacture of the valve, which produces a ray of
light

18
Robot programming using Arduino

3. The first activity: turning on the lighting with the Arduino

1. Required

In this activity, we will connect the lighting directly with the Arduino positive
pole with 5V and the negative pole with without programming and then we will
run

7.1.3.2 Circuit
connection

7.1.3.3 Conclusion

What happened?

............................................................................................................................................................................
......
............................................................................................................................................................................
...............
......................................................................................................................................
.....................................................

- In order to connect the LED we need a resistor in order to lower the current
to the LED so that it does not burn out

19
Robot programming using Arduino

4. Second Activity: Measuring the current and voltage

1. Required

Through the previous activity, the multimer was used to measure the current
and voltage value of the LED

7.1.4.2 Circuit
connection

7.1.4.3 Conclusion

Write the value of the current

voltage Top of the

current: .....................

Voltage value: ................................

20
Robot programming using Arduino

2. Electrical Resistance

1. What is electrical resistance?

 Resistance in electrical science is one of the


characteristics and advantages of the electrical
circuit, which is based on converting electrical
energy into thermal energy opposite and different
from the direction of the electric current
 Resistors are available in different values
according to your need

7.2.2 How it works

The most important task of resistance within an electrical circuit is to regulate


the amount and quantity of potential difference (volts) and electric current.

21
Robot programming using Arduino

3. Third Activity: Resistance Calculation

1. Required

Through the previous activity using Ohm's law and the millimeter, calculate
the appropriate resistance value for LED operation if you know that the
appropriate current value for LED is 20 mA

7.2.3.2 Circuit
connection

7.2.3.3 Conclusion

Write the appropriate resistance

value The pinnacle of

resistance: ..................... Current

value: ................................

22
Robot programming using Arduino

3. Experiment board

1. What is the experiment board?

 It is a flat board used as a base for connecting


electronic components to build electronic circuits
 It does not need to be welded and is reusable and
this makes it easy to use to create temporary models

7.3.2 How it works

This board consists of several sectors and the holes of these holes serve as
connection points where the ends of the various electronic parts can be installed
where they are connected respectively to the surrounding holes horizontally in the
two sectors on the edge of the board, while for the sectors in the middle, the holes
are connected respectively vertically.

23
Robot programming using Arduino

3. Fourth activity: with a light shaft

1. Required

We will program the lighting so that it lights up for a second and closes for a
second and repeats that continuously

7.3.3.2 Circuit
connection

24
Robot programming using
Arduino

7.3.3.3 Programming

7.3.3.4
Conclusion

Here the port


number and also
its type are

This line is
responsible for
applying an
electrical voltage of
either 5 V (HIGH)
or 0 V (LOW) where
we write the port
number
This line is used to
tell the controller
how long you have
to wait before
executing the next

25
Robot programming using Arduino

4. Fifth activity: programming lighting for a certain number of times

1. Required

We will program the lighting so that it lights up for a second and closes for a
second and repeats it 3 times

2. Circuit connection

26
Robot programming using
Arduino

7.3.4.3 Programming

7.3.4.4
Conclusion

Here we used the iteration function to repeat the commands for the
required

27
Robot programming using Arduino

4. RGB LED lighting element

1. What is an RGB LED element ?

 The term RGB itself means a lighting system based on the


three main basic colors of the computer, which are red,
blue and green, available in different colors (red - green -
blue - yellow)
 Each RBG LED strip has a series of RGB LEDs that are
somehow
interconnected together. You can use RGB LED light strips
to create all kinds of colorful lighting for your home and
office

7.4.2 How it works

The passage of electric current through the light-emitting diode raises atoms in
the semiconductors used in the manufacture of the valve, which produces a ray of
light

28
Robot programming using Arduino

3. Sixth Activity: RGB LED Lighting Control

1. Required

We will do a project to control the RGB LED element and the color
control method

7.4.3.2 Circuit
connection

29
Robot programming using
Arduino

7.4.3.3 Programming

7.4.3.4
Conclusion

Here we used a function to control the desired color by changing


the value that can combine more than one color to get
other colors

30
Robot programming using Arduino

5. Electric Buzzer

1. What is an electric buzzer?

 A device that converts electrical energy into


audible sound
 It is used for sound notification in cars,
microwave ovens and others.

7.5.2 How it works

The electric buzzer has a positive and negative electrode The buzzer operates
at a voltage of 6-12 volts and carries a direct current of about 25 mA

31
Robot programming using Arduino

3. Seventh Activity: Ambulance Alarm

1. Required

We will do a project that simulates the voice of the


ambulance

2. Circuit connection

7.5.3.3
Programming

7.5.3.4
Conclusion

Here we used the sound control function and it consists of two


parts, the first part is to determine the port and the second part is
to determine the frequency

32
Robot programming using Arduino

7.6 Second Session: Electric Motors

7.6.1 What is an electric motor?

Since the invention of the first electric motor, interest in the manufacture of
electric motors of all kinds began throughout history, and their use in abundance
in the field of technology and engineering, and electric motors (in English: electric
motors) depend in their work on the principle of electromagnetic induction in
converting electrical energy into kinetic energy managed to accomplish a job.

2. Types of electric motors

Electric motors are divided into 3

famous types: 1- DC Motor


2 Servo motor
3 Stepper motor

1. Electric Motors (DC Motor)

1. How it works
 The movement of the electric motor is rotational
movement either clockwise or counterclockwise
 Operates on 6V DC power
 Its speed is 200 rpm

Can you cite examples of the uses of the electric motor?

............................................................................................................................................................................
......
............................................................................................................................................................................
...............

33
Robot programming using Arduino

2. Servo motor

1. How it works
 It is similar to a conventional electric motor in addition to the presence of
a resistance
and an electronic board that works to translate the
transmitted signal to determine the desired turning
angle.
Servo is used in many small and large industrial
applications. This engine can be used to power
remote- controlled toy cars, robots, airplanes, parts
of robots, production lines, and food industries
The servo motor contains 3 wires red expresses the
positive terminal, black expresses the negative
terminal, and
orange expresses the signal terminal

3. Stepper
Motor

1. How it It is used in small machines that need


works
accurate control of their engines, such as the
printer and the laser cutter
The number and speed of its cycles and
stopping angle can be controlled accurately
It is widely used in digital devices (such as a
three- dimensional printer)

34
Robot programming using Arduino

3. Eighth Activity: Servo Motor Programming

1. Required

We will program the servo for movement from zero angle to


90 to 180

7.6.4 Circuit connection

35
Robot programming using
Arduino

7.6.4.1 Programming

36
Robot programming using
Arduino

7.6.4.2 Conclusion

Here we have added


a library for the servo
motor

Here we have defined


a name for the servo
motor,

In this line the port


number connected to
the engine is

In this line, the angle of


the servo motor
controlled andcan be
can be

37
Robot programming using Arduino

7. Session Three: Digital Inputs

1. Digital signage

Arduino boards have 10-bit multi-channel digital ports, meaning that when a
voltage is read via the Arduino's analog-digital converter, the read voltage will be
stored as a value between 0 and 1023 . If we assume that the input voltage range
is between 0 and 5 volts, this means that when a voltage value of 5 volts is read
on the sewer of the analog-digital converter, a value of

1023 will be
saved.

38
Robot programming using
Arduino

8. pushbutton electric button

1. What is the pushbotton ingredient?

One of the most commonly used components in automatic control circuits or


PLC is push buttons , so you must understand how they work well so that we can
deal with automatic control

Used in starting or stopping one or more engines. It can also be used in


other things depending on the application

There are two types of buttons

1 Type NO any normally opened: and it is always open and when


pressed it turns into closed and when you raise the hand it returns to
open

2NC type, i.e. normally closed: It is always closed and when pressed it opens
and when the hand is raised, it turns again into closed

2. How it works

 It is an electronic element that passes electricity when pressed and cuts


off the current when it is not pressed
 There are two cases of the button, either pressing or not pressing (Pressed
– Released )
 You can also use any of the computer buttons and control it

39
Robot programming using Arduino

3. Ninth Activity: Button Programming

1. Required

We will do a project to judge lighting


using buttons

7.8.3.2 Circuit
connection

7.8.3.3
Programming

40
Robot programming using
Arduino

7.8.3.4 Conclusion

In input programming, it is necessary at the beginning to define a variable


for storage reading the sensor, and here a variable has been defined as
PUS, which stores the state of the button, is it in a state of pressure or
not?

After we used the condition function to check the status of the button if it
is in a state of pressure (and expressed in programming with the word
HIGH) the lighting works and

41
Robot programming using Arduino

7.9 Quiz

1 The best description of the definition of Arduino controller


o Open source
o Multi-species
o Suitable for beginners
o All of the above

2 Number of GND ports in Arduino controller


o 3
o 2
o 1
o 13

3 We have a robotic arm for which we want to choose the best motor
suitable for the arm is
o DC MOTOR
o SERVO MOTOR
o STEPPER MOTOR
o SERVO MOTOR & STEPPER MOTOR

4 The resistance value used with the electric button


o 220 ohms
o 10 kg 1m
o 10 ohms
o None of the above

1 What do we mean by
o Output 5V value from port No. 2 this?
o Turn on the neutral lighting in port
number 2
o Switch control
o None of the above

42
Robot programming using Arduino

10. Challenges

1. The first challenge:

Through what you learned in the activities, add 2 LED and write a program to
turn on the lighting No. 1 and close the light No. 2 for a second and then work the
opposite Light No. 2 and close the light No. 1 for a second (note Use the
experiment board to connect the electrical circuit)

7.10.2 Second Challenge:

From what you learned in the activities make a project that simulates the work
of the traffic light in addition to the pedestrian signal

7.10.3 Third Challenge:

Through what you learned in the activities in this section, make a program to
control the speed of the servo controller to move from an angle of 0 to 180 and
then return from 180 to 0

43
Robot programming using
Arduino

8 Section IV: Sensors

Session Title: Electric Motors

Session time: 120

minutes Objectives:

 Identify input types


 Identify the
following electronic
elements
 Electrical
switch
 Distance
sensor
 Lighting
sensor
 Addressing
and sending
data
 Programming:
Session
 Input
Requirements:
programming
 Laptop(– distance
sensor –
 Register on
lighting
Tankrickad
sensor)
 Condition
function
 Using
variables in
programmin
g

44
Robot programming using Arduino

1. First Session: Analog / Digital Inputs

When talking about signals, we always distinguish between

two areas: Analog

Digital Signage

1. Analog

Signals propagate in the world around us symmetrically (when we say signal


here, the point is voltage) which means that they have a different value at each
moment in time, and the value of the signal can be negative, positive or equal to
zero. If we take as a simple example temperature, we can express its value at a
given moment in time as 25 degrees Celsius, 25.1 degrees Celsius,
25.13 degrees Celsius, 25.138 degrees Celsius, 25.1384 degrees Celsius, and
so on. The temperature can also be zero, and the temperature can be -1, -2
degrees, or another negative
value.

- Examples of analogue signals Temperature, current, voltage, speed, sound intensity or


light intensity

45
Robot programming using
Arduino

46
Robot programming using Arduino

2. Variable resistance Potentiometer

1. What is the variable resistance?

It is a simple electrical element, the value of which changes by applying a


physical change (displacement, rotation, temperature, lighting, ... etc).

The resistance that we will explain is the variable resistance with an arm, the
value of which changes with the angle of the arm in it

8.2.2 How it
works

The diagram above shows the formation of the


variable resistance with an arm, which is an ohmic
resistance with three sides. The two external sides
represent the total nominal value of the resistance,
and the middle end is the end that changes the
reading value by moving it over the entire field,
according to the principle of voltage divider, and thus
gives different analog (analogue) values at each
change in the position of the middle end.

When the arm is fully rotated in one direction, the


middle seam takes a very small value (not equal to zero) or a maximum value
(nominal value of resistance) and vice versa in the opposite direction of rotation.
For example, if the nominal value is 10 kOhm, the resistance value read on the
middle contact is confined to the range [0 – 10 kOhm]

47
Robot programming using Arduino

3. The first activity: controlling the speed and intensity of lighting

1. Required

We will use variable resistance to control the lighting. We will make the light
light light up and off quickly. It depends on the resistance value.

2. Circuit connection

8.2.3.3
Programming

48
Robot programming using
Arduino

8.2.3.4 Conclusion

Here we controlled the


delay estimator using the
variable resistor and the
analogue

49
Robot programming using Arduino

3. LDR optical resistance

1. What is the optical resistance

Light Dependent Resistor LDR means light-dependent resistance, as its name


suggests, it is a photoresistor, its value depends on the light falling on it, the
value of the resistance decreases with increasing light intensity, and its value
increases with its decrease. That is, it is inversely proportional to the intensity of
light. It is also called photoresistor.

LDR optical resistance is made of semiconductor and light-sensitive materials


such as cadmium sulphide (CdS) and is zigzag as in the picture in order to
increase the resistance value and reduce current when dark, and two metal
contacts are connected on both ends of the zigzag strip, representing the
resistance terminals that are connected with electrical circuits.

8.3.2 How it works

Optical resistance works according to the principle of photoconductivity When


light falls on the conductive material, it absorbs light energy and excites electrons
in the last orbital (valence band) of the conductive material,

Free electrons therefore conduct and therefore increase their conductivity as


the light intensity increases. The energy of the incident light must be greater than
the energy of the band gap so that electrons in the valence range are excited and
conduct.

50
Robot programming using
Arduino

3. Second activity: Lighting control through a lighting sensor

1. Required

We will make a project to control the lighting through the light sensor in the
event of darkness the lighting works and in the case of lighting the light goes out

8.3.3.2 Circuit
connection

51
Robot programming using
Arduino

8.3.3.3
Programming

8.3.3.4
Conclusion

In input programming, it is necessary to first define a variable for storage


reading the sensor, and here a variable has been defined as LIGHT, which
stores the value of lighting

After we used the condition function to check the value of the lighting if it
is dark (and we express it in programming that it is less than 800) the
lighting works and if in the

52
Robot programming using Arduino

4. Ultrasonic

1. What is the distance sensor

•It is a sensor through which we can calculate the distance between the robot
and any obstacle in front of it

•The distance sensor is used in our daily lives, and one of the most famous
examples is its use in the car, through which the driver is alerted to the presence
of an obstacle behind him if he moves backwards

2. How the sensor works

It contains a transmitter and a receiver, where an ultrasonic


wave is sent from the transmitter, and in case of colliding
with a barrier, there is a rebound to the receiver, through
which he calculates the distance through a mathematical
equation

The area of capture of objects is approximately 3 cm


to 4 meters with a wrong margin of 1 cm.
 The angle of capture is approximately 30
degrees.

53
Robot programming using Arduino

3. Third Activity: Distance Sensor Programming

1. Required

We will do a project if the reading of the distance sensor is less than 20 the
lighting works and if it is bigger the light turns off

8.4.3.2 Circuit
connection

54
Robot programming using
Arduino

8.4.3.3 Programming

55
Robot programming using
Arduino

8.4.3.4 Conclusion

The function of these lines of code is to activate the work of


the distance sensor, where it is necessary in the beginning to
activate the sensor and send rays

In input programming, it is necessary to first define a variable for storage


reading the sensor, and here a variable named D has been defined ,
which stores the value of the distance

After we used the condition function to make sure of the value of the
distance if there is an obstacle in front of it (and we express it in
programming that it is less than 20 lighting

56
Robot programming using Arduino

5. PWM Digital Editing

1. What is PWM?

PWM (Pulse Width Modulation) is a technique used to control the proportions of


electrical energy supplied to devices. It is a digital signal made up of modified
pulses that enables you to obtain an average amount of electrical energy between
full on and off."

2. Fourth activity: lighting intensity using PWM

1. Required

We will control the intensity of the lighting using PWM so that we reduce the
lighting or increase the lighting

8.5.2.2 Circuit
connection

57
Robot programming using
Arduino

8.5.2.3 Programming

8.6 Second session: Sending commands and data from Arduino to the
computer

Most Arduino boards provide the feature of sending and receiving data directly
with the computer via the USB port , and this feature can be exploited in the
implementation of some wonderful projects

58
Robot programming using Arduino

We had used Arduino to read some sensors such as light and heat and show
the result on the lighting to illustrate this reading Now we will use the serial
interface feature to send the results of reading the sensors to the computer,
where the results can be read in numbers and perform calculations

59
Robot programming using Arduino

1. Fifth activity: reading the sensor value of the lighting sensor

1. Required

In this activity, we will read the value of the rays falling on the sensor and
lighting and display them on the screen

8.6.1.2 Circuit
connection

60
Robot programming using
Arduino

8.6.1.3 Programming

8.6.1.4
Conclusion

Here we have activated the addressing feature and set the


speed of

A variable named i was created that stores the lighting


value, and then we printed the lighting value and
displayed it on the user

61
Robot programming using Arduino

2. Sixth activity: Sending data to Arduino and controlling


lighting

1. Required

In this activity, we will send data to the Arduino and control


the lighting.
8.6.2.2 Circuit
connection

62
Robot programming using
Arduino

8.6.2.3 Programming

8.6.2.4
Conclusion

A variable named i has been created that stores the data,


and we have added a condition function to ensure the data
sent, and based on this

63
Robot programming using Arduino

7. LCD display 16*2

1. What is a display screen?

LCD 16×2, LCD term refers to liquid crystal


display, used in computer monitors and TVs,
smartphones, tablets, mobile devices
The liquid crystal display has a backlight that
provides light to each pixel arranged in a
rectangular grid

8.7.2 How it works

LCD screens 16 X216 X2 are mostly based on multi-segment LEDs. There are
different types of displays available in the market in different combinations such as
8×2, 8×1, 16×10×2, however, 16×2 LCD screen is widely used in hardware, DIY
circuits and electronic projects due to lower cost.

64
Robot programming using Arduino

3. Seventh activity: Printing the word Hello World on the


screen

1. Required

We will do a project to control the LCD screen and print the word
Hello World
8.7.3.2 Circuit connection
method

65
Robot programming using
Arduino

8.7.3.3 Programming

8.7.3.4
Conclusion

In this line, the port for the screen is defined

This command is for the beginning of the screen and the


number of

The location of the column and row from which the printing
will start has been determined and the sentence to be
printed has been selected

66
Robot programming using Arduino

8. Quiz

6 The sensor that has two TRIG & ECHO ports is


o Lighting sensor
o Distance sensor
o Screen
o None of the above

7 What meant by the code


is command on the
o Turn screen
o Acti
vat
e
the
8 A digital co signal made up of modified pulses
mm
o DC MOTOR
uni
o PWM
cati
o onAnalog pin
wit
o Digital pin
h
Ard
9 If we haveuin 2 buttons and a distance sensor how many variables do we
o
need in the program
o Dist
o 1
anc
o e 2
o sen
3
o 4 sor
ope
rati
on
10 It iso a All
simple electrical element, the value of which changes its
of
resistance to the application of a physical change
the
o Variable
abo resistance
ve
o Distance sensor
o Electrical switch
o Pwm

67
Robot programming using
Arduino

9. Challenges

1. The first challenge:

From what you learned in the activities, make a project that shows the reading
of the light sensor on the LCD screen (16,2)

8.9.2 Second Challenge:

Through what you learned in activities, make a project that simulates the work
of warning in the car about reversing and approaching a car or an obstacle

8.9.3 Second Challenge:

Through what you learned in the activities, make a project using the distance
sensor and the RGB LED element in the neighborhood If the distance is less than
80, it lights up red, if it is less than 60, it lights up green, and if it is less than 40,
it lights up blue.

68
Robot programming using Arduino

8.10 Final Project:

Make a project that simulates the work of

electronic portals 1- Use electronic elements


o Servo Motor
o Screen
o LED
o Distance sensor
o Or any element that you see suitable
for the idea
2- Clarify the electronic circuit and how to connect it to
Arduino 3- Clarify programming and explain the codes

69

You might also like