Professional Documents
Culture Documents
LEARNING MODULE
IN
ROBOTICS
(FRELEC103)
FINAL TERM
1ST SEMESTER A.Y. 2021-2022
Rex M. Ramirez
Subject Instructor
Final Examination------------------------------------------------------------------------------------------58
Pre-Assessment 12
Answer the following questions. Write your answers on a separate sheet of long bond
paper.
Scoring Rubric:
Content/Idea: 5pts.
Coherence: 3pts.
Handwriting: 2pts.
Total Score: 10pts.
Course Content
Arduino is the open-source platform used for making custom electronics projects.
Before learning about the Arduino Sensors, lets first understand the sensors as a general
term.
The sensors are used to measure the physical quantities, such as pressure, temperature,
sound, humidity, and light, etc.
An example of sensors is Fire Alarm, a detector present on the fire alarm detects the
smoke or heat. The signal generated from the detector is sent to the alarming system,
which produces an alert in the form of alarm.
The types of detectors are smoke detectors, heat detectors, carbon monoxide detectors,
multi-sensors detectors, etc.
The data signal runs from the sensor to the output pins of the Arduino. The data is further
recorded by the Arduino.
o Ultrasonic sensor
The ultrasonic sensor is used to determine the distance of the object using
SONAR.
o Temperature sensor
The temperature sensor is used to detect the temperature around it.
o Knock Sensor
The knock sensor is used to pick the vibrations of the knocking. It is a
common category of a vibration sensor.
o Object Detection Sensor
It is used to detect the object by emitting infrared radiations, which are
reflected or bounced back by that object.
o Tracking Sensor
It allows the robots to follow a particular path specified by sensing the marking or lines on
the surface.
o Metal Touch Sensor
It is suitable for detecting the human touch.
o Water Level Sensor
It is used to measure the water or the depth of the water level. It is
also used to detect leaks in containers.
o Vibration Sensor
The vibration sensor is used to measure the vibrations.
o Air Pressure sensor
It is commonly related to meteorology, biomedical fields. It looks like the below
image:
o Pulse Sensor
The pulse sensor is used to measure the pulse rate. It looks like the below image:
Learn more
o Magnetic field sensor
The magnetic field sensor measures the magnetic field strength and produces a varying
voltage as the output in Arduino.
Arduino LDR
Arduino LDR (Light Dependent Resistor) project uses the photoresistor to light an LED.
The LED will light up whenever there is dark or no light over the sensor.
Hardware Required
o 1 x red LED
o 1 x 220 Ohm Resistor
o 1 x 10K Ohm Resistor
o Arduino UNO R3 board
o Jump wires
o 1 x photoresistor
Vin = 5V
Here, R2 is the resistance connected in series with the photoresistor = 10K Ohm.
Note: The resistance decreases with increasing light. Hence, the output voltage will
increase. It means that the output voltage calculated at the light will be higher than the
output voltage calculated at dark.
Here, dark and light specify the light falling on the sensor.
Connection
o Connect the positive leg of the LED in series with the resistor to the pin number 12
of the Arduino board.
o Connect the negative leg of the LED to the Ground.
o Connect one edge of the photoresistor to the 5V pin on the Arduino board.
o Attach a 10K ohm resistance in series with another edge of the photoresistor and
connect it to the GND.
o Connect the edge of the photoresistor to the analog pin A0.
Note: We have connected the LED only to enhance the project. We can also create the
project without using the LED. It will not impact the output.
void setup() {
// initializing the serial communication:
Serial.begin(9600);
pinMode(photoPIN, INPUT);
pinMode(LEDpin, OUTPUT);
}
void loop() {
// read the sensor:
int sensorStatus = analogRead(photoPIN);
// now, it will check the reading or status of the sensor is < 200
// if it is, LED will be HIGH
if (sensorStatus <200)
{
digitalWrite(LEDpin, HIGH); // LED is ON
Serial.println(" LED is ON, status of sensor is DARK");
Connection Diagram
Output
Arduino Accelerometer
In this topic, we will discuss a project based on an accelerometer. The value will be read
from the series of accelerometer and received in the Arduino IDE's
serial monitor. It means the data will be read and received over the serial port.
We will use a three-axis accelerometer that gives acceleration for each Axis as an analog
voltage for separate pins.
The accelerometer is the device capable of detecting changes in motion in the form of
acceleration. It can also measure the vibration of a structure.
The acceleration (change in motion) or the vibration generates the force that causes the
piezoelectric material to be stressed. The microscopic crystals structure present in it
creates the voltage from the stress. The accelerometer interprets this voltage. The voltage
is further used to determine the orientation and velocity.
Usage of Accelerometer
ADXL335 Accelerometer
The position of the three axis (X-axis, Y-axis, and Z-axis) will change according to the
ADXL335 accelerometer's position.
If we hold the board in a different position, the direction of the three-axis will also change.
Moving the board in a particular direction will cause a change in the voltage of the
respective axis. We can measure the changed voltage on the Arduino
When we hold the board up and flat, the measured acceleration of 9.8m/s^2 will appear
on the Z-axis.
1.0G = of 9.8m/s^2
where,
s = 0.33V/G.
The accelerometer at rest will read half of its maximum analog voltage.
Note: Some accelerometers work at 5V while some at 3.3V. We need to make sure about
the voltage because the 3.3V accelerometer may be damaged with a 5V supply.
Hardware Required
o 1 x ADXL335 accelerometer
o 1 x Arduino UNO R3
Principle
We can directly plugged-in the accelerometer onto the Arduino. It is because the
accelerometer operates on minimal current.
has six analog pins. The three analog pins will be connected to the Vcc, Self-Test, and the
Ground pin. The other three analog pins will be used to read the analog output of the
accelerometer.
Structure
Connection
Sketch
We will upload the code on the Arduino connected with the accelerometer. The output can
be clearly seen on the Serial Monitor in the Arduino IDE
The Ultrasonic sensor or HC-SRO4 is used to measure the distance of the object using
SONAR.
It emits the Ultrasound at a frequency of 40KHZ or 40000 Hz. The frequency travels
through the air and strikes the object on its path. The rays bounce back from the object
and reach back to the module.
The four terminals of HC-SRO4 are VCC, TRIG, ECHO, and GND. The voltage supply or
VCC is +5V. We can connect the ECHO and TRIG terminal to any of the digital I/O pin on
the specific Arduino board.
The medium ranges of the sensor are 10cm to 3m. It works best at this duration.
o When samples strike the object, it bounces back from the object.
Example
An object is 40cm away from the Ultrasonic sensor. The speed of sound in air is
340m/s. We need to calculate the time (in Microseconds).
Solution:
time = distance/speed
time = 40/0.034
The speed of sound from the echo pin will double because the wave travels forward and
backward (bounces).
We will set the TRIG pin to HIGH for some time (about 3 to 100 microseconds). As soon
the TRIG pin is LOW, the Ultrasonic sensor sends the pulses and sets the ECHO pin to
HIGH. When the sensor gets the reflected pulses, it sets the ECHO pin to LOW. We need
to measure the time for which the ECHO pin was HIGH.
Hardware Required
o Arduino UNO R3 board (We can also use any Arduino board)
o Jump wires
o Ultrasonic sensor HC-SRO4
o Breadboard
Principle
We need to first set the TRIG (triggered) pin at HIGH. It will send out the burst of 8 cycles
called the sonic burst, which will travel at the sound speed. It will be further received by
the ECHO pin. The time traveled by the sound wave is considered the ECHO pin's output
time in microseconds.
We will use the PulseIn() function to read the time from the output of the ECHO pin. It will
wait for the specified pin to go HIGH and LOW. The function would return the timing at the
end.
The TRIG pin is set LOW for 4 microseconds and then HIGH for 15 microseconds.
Procedure
Sketch
1. #define ECHOpin 5 // it defines the ECHO pin of the sensor to pin 5 of Arduino
2. #define TRIGpin 6
3. // we have defined the variable
4. long duration; // variable for the duration of sound wave travel
5. int distance; // variable for the distance measurement
6. void setup()
7. {
8. pinMode(TRIGpin, OUTPUT); // It sets the ECHO pin as OUTPUT
9. pinMode(ECHOpin, INPUT); // It sets the TRIG pin as INPUT
10. Serial.begin(9600); // // Serial Communication at the rate of 9600 bps
11. Serial.println("Test of the Ultrasonic Sensor HC-
SR04"); // It will appear on Serial Monitor
12. Serial.println("with the Arduino UNO R3 board");
13. }
14. void loop()
15. {
16. // It first sets the TRIG pin at LOW for 2 microseconds
17. digitalWrite(TRIGpin, LOW);
18. delayMicroseconds(4);
19. // It now sets TRIG pin at HIGH for 15 microseconds
20. digitalWrite(TRIGpin, HIGH);
21. delayMicroseconds(15);
22. digitalWrite(TRIGpin, LOW);
23. // It will read the ECHO pin and will return the time
24. duration = pulseIn(ECHOpin, HIGH);
25. // distance formula
26. distance = duration*(0.034/2); // (speed in microseconds)
27. // Speed of sound wave (340 m/s)divided by 2 (forward and backward bounce)
28. // To display the distance on Serial Monitor
29. Serial.print("Distance: ");
30. Serial.print(distance);
31. Serial.println(" cm"); //specified unit of distance
32. }
Connection Diagram
We will use a temperature sensor (TMP 36) of low voltage. Such sensors are also stable
while dealing with large capacitive loads. It is also suitable for automotive applications.
The temperature sensors TMP 35, TMP 36, and TMP 37 are the sensors with the same
features.
The operating voltage of the TMP 36 sensor ranges from 2.7V to 5.5V.
o Pin 1: DC voltage
Here, we will connect the DC voltage pin to 5V on the Arduino UNO board.
o Pin 3: GND
We will connect the GND pin to Ground on the Arduino UNO board.
Hardware Required
Principle
We need to open the URL: Arduino LCD display for details about LCD display.
Connection
Sketch
1. #include <LiquidCrystal.h>
2. // initialize the library with the pins on the Arduino board
3. LiquidCrystal lcd(13, 12, 6, 4, 3, 2);
4. const int temperature = A0; //A0 is the analog pin
5. const int D = 8; // Vo of LCD is connected to pin 8 of the Arduino
6. void setup()
7. {
8. lcd.begin(16, 2);
9. Serial.begin(9600);
10. pinMode(D, OUTPUT);
11. }
12. void loop()
13. {
14. digitalWrite(D,LOW);
15. int Temp = analogRead(temperature);
16. float volts = (Temp / 965.0) * 5;
17. float celcius = (volts - 0.5) * 100;
18. float fahrenheit = (celcius * 9 / 5 + 32);
19. Serial.println(fahrenheit);
20. lcd.setCursor(5, 0);
21. lcd.print(fahrenheit);
22. delay(2000);
23. // time delay of 2000 microseconds or 2 seconds
24. }
We will show the connection using the Simulator because the connections become clearer
and more precise.
For better understanding, let's consider the output on the Serial Monitor.
We will use a PIR motion sensor in this project. All objects (having temperature higher
than absolute zero) emit radiations from the generated heat. These radiations cannot be
detected by a human eye. Hence, electronic devices such as motion sensors, etc. are
used for the detection of these radiations.
The Passive Infra-Red sensors or PIR sensors detect motion or movement of an object
that detect infrared radiations, such as the human body. Hence, the use of sensors is very
common.
o Inexpensive
o Adjustable module
o Efficient
o Small in size
o Less power consumption
o It can detect motion in the dark as well as light.
The PIR sensor has three terminals, which are listed below:
o VCC
o Digital Output
o GND (Ground)
We will connect the Vcc terminal of the sensor to the 5V on the Arduino board. The PIR's
sensor output can be connected to any of the digital pins on the Arduino board.
The applications of the PIR sensor are automation, security systems, etc. Such sensors
work great in detecting the entrance of a person in an area and leaving it.
The working of the PIR sensor is entirely based on detecting the IR (Infra-Red) radiations,
which are either emitted or reflected by the objects.
Consider a person passing in front of the background like a wall, etc. The temperature
changes from room to body temperature and vice-versa within the sensor field. Changes
arising in the arrival infrared radiations are converted by the sensor to the output voltage.
It later detects the human body or object.
A round metal can is mounted on the center with the rectangular crystal that detects the IR
radiations.
A ball like a lens present on some sensors helps in enhancing the viewing angle.
The bottom part of the sensor contains many circuits mounted on it, which is shown
below:
Hardware Required
Principle
The movement of jumper present on the sensor on the L side will cause a change in the
state of the sensor whenever the motion is detected. Such a condition is defined as a
single trigger mode.
When the sensor resets the timer after every detection of motion, it is defined as repeated
trigger mode.
The two potentiometers present on the sensor are called as Sensitivity Potentiometer
and Time Potentiometer. We can adjust both the parameters (time and sensitivity)
accordingly.
It should be restricted for atleast 15 seconds in front of the PIR sensor for proper
calibration in the output. After 15 seconds, the sensor can easily detect movements.
Connection
o Connect the Vcc terminal of the PIR sensor to the 5V pin of the Arduino board.
o Connect the Output terminal of the PIR sensor to pin 8 of the Arduino board.
o Connect the GND terminal of the PIR sensor to the Ground pin of the Arduino
board.
o Connect the positive leg of the LED in series with 220 Ohm resistor to pin 13 of the
Arduino board.
o Connect the negative terminal of the LED to the Ground pin of the Arduino board.
Sketch
Connection Diagram
We will show the connection using the Simulator so that the connections become clearer
and more precise.
2) ________ used to determine the distance of the object using SONAR. Ultrasoni
3) ________ allows the robots to follow a particular path specified by sensing the marking or
lines on the surface. Tracking Sensor. Tracking Sensor
4) ________ It is commonly related to meteorology, biomedical fields. It looks like the below
image:
5) ________ sensor is used to monitor weather conditions. humidity sensor
6) ________ It is commonly related to meteorology, biomedical fields Air Pressure sensor
7) ________ produces a varying voltage as the output in Arduino. humidity sensor
8) ________ are defined as a machine, module, or a device that detect changes in the
environment. sensors
9) _________ electronic devices always work together. The output signal is easily readable
by humans. sensors
10) ________ The sensor is a device, which is made up of ____________Single Crystal Sil
11) ________ is used to detect the temperature around it. Temperature Sensor
12) .________ emitting infrared radiations, which are reflected or bounced back by that object.
13) ________ LDR stands for__________.
14) ________ It is suitable for detecting the human touch. Metal Touch Sensor
15) ________It is also used to detect leaks in containers.Water Level sensors
16) ________ The vibration sensor is used to measure the vibrations.
17) ________ is suitable to detect the sound of the environment.
18) ________ The sensor in Arduino measures the pressure and displays it on the small LCD
screen. Presure senso
19) ________It is used to measure the moisture level of the soil. Capacitive soil moisture
sensor
20) ________ The analog and digital are the two outputs of this module. Mcrophone sensor
LEARNING TASK 13
(Week 8, October 25-30, 2021 Week 9 November 2-6, 2021)
PRE- ASSESSMENT 13
Answer the following questions.
1. What is Arduino Stepper Motor and how it work?
2. What is a Potentiometer ?
3. What is Arduino DC Motor?
Scoring Rubric:
Content/Idea: 5 pts
Coherence: 3 pts
Handwriting: 2 pts
------------------------------------
Total: 10 pts
The stepper motor does not require any feedback for its operation. It can be controlled
with high accuracy due to its design.
The series of magnets mounted on the shaft of the stepper motor are controlled by the
electromagnetic coils. These coils are negatively and positively charged in a sequence,
which makes the shaft to move in forward and backward in little steps.
We can also hold the position of the motor at any step during rotation. It has a simple,
accurate open-loop system.
The Stepper is categorized into two types, which are listed below:
o Unipolar
o Bipolar
Unipolar
The Unipolar stepper motor consists of one winding that operates with a center tap per
phase. There are three leads per phase in the motor. For the regular two-phase stepper
motor, there are six leads per phase.
The Unipolar stepper motor has five leads when both the phases are joined internally.
Bipolar
The bipolar stepper motor consists of a single winding per phase. There are two leads per
phase in the motor.
The bipolar stepper motors do not have any center tape connections. Such devices are
used when we require high torque popularly at low speeds.
The stepper motor can control the angular position of the rotor without a closed feedback
loop.
For example,
Consider a motor with six stator teeth and a rotor. It is shown below:
A stepper motor with six stator teeth can be triggered with three different DC power
sources. The rotor in the stepper motor is made up of a stack of steel laminations. It has
different teeth compared to the rotor, which is four.
It is done so that one pair of rotor teeth at a time can be aligned easily with the stator.
If we trigger or energize the coil A and B, the rotor would rotate. The above figure signifies
the step size is 30 degrees. We will energize coil B and C. After that, the coil A will
energize again. It means that the rotor moves to the position with the least reluctance.
When both the coils are excited, the position of the rotor (in between) is shown below:
The energizing of both the coils change the accuracy of the rotor from 30 degrees to 15
degrees.
In this project, we will use the hybrid motor type. It looks like the image shown below:
Hardware Required
Connection diagram
Sketch
Procedure
o Connect the negative and positive terminal of the battery to the GND and 5V pin of
the Arduino board.
o One outer pin of the potentiometer is connected to ground (GND), and the other
external pin is connected to 5V of the Arduino board.
o The middle pin of the potentiometer is connected to the analog input pin A1 of the
board.
o Connect the 8 to 11 digital pins of the Arduino board to the U2004 Darlington
Array, which is further connected to the motor.
o Connect other pins of the U2004 Darlington Array to the stepper motor, as shown
in the connection diagram.
The principle of the servo motor is based on Pulse Width modulation (PWM). It means that
the duration of pulses applied to the specific control pin controls the angle of rotation of
the motor.
The construction of the servo motor is similar to a DC motor. It means that it has a rotor,
stator, and control assemblies. It has closed-loop feedback for controlling the torque and
speed.
o High efficiency
o High output power
o Small size
o Good power
o High precision
o rapid acceleration of loads
The applications of servo motors are machinery, automated manufacturing, robotics, radio
controller airplanes, etc. The controller is considered as an essential part of the servo
motor.
The movement in a servo motor is determined by an electric signal that can be either
digital or analog.
The Servo library is the library that permits the Arduino to work with servo motors.
The servo library allows controlling the integrated shaft and gears. We can also position
shaft at different angles between 0 and 180 degrees. The servo library on Arduino
boards can support upto 12 motors, while on Arduino Mega board, it can support upto 48
motors.
It is because servos do not interfere with the functionality of PWM pins on the Arduino
Mega board. On other Arduino boards, the servo library disables the PWM pin 9 and 10
even if the servo is connected to these pins.
The use of motors on Mega is also limited. It means we can use 12 motors on Arduino
Mega. But, using 12 to 23 motors on the Mega board can disable the PWM functionality
on the pin number 11 and 12.
The difference between regular motor and servo motor are listed below:
o The output shaft of the servo motor can be moved to a specific velocity, position,
and angle while regular motors cannot.
o The feedback from the motor is used by the servo motor control loop, which helps
the motor to reach the desired velocity and position.
The difference between stepper motor and servo motor are listed below:
o The servo motor requires a control loop feedback. The control loop is used to
monitor the current distance and velocity. Due to this, it is more reliable than the
stepper motor.
o Servo motors usually have a low pole count while the stepper motors have high.
o The speed curve of the servo motor is more flexible compared to the stepper
motor.
o The stepper motor has low speed and accuracy than the servo motor.
Project
Hardware Required
Mini Servo Motor: It is defined as a tiny motor that can approximately rotate upto 180
degrees. It works similar to the usual servo motor, but smaller in size.
We can also use any servo motor. The connection and procedure would be the same.
Principle
The project allows us to control the shaft at angles between 0 and 180 degrees. We can
also set the rotation of the shaft at different speeds.
Servo motor has three terminals signal, power, and ground. The signal terminal is usually
connected to the 5V pin of the Arduino board with the help of a wire.
The ground, power, and signal wire are represented by black, green, and red colors.
o Connect the signal terminal of the servo motor to the 5V pin of the Arduino board.
o Connect the power terminal of the servo motor to pin 5 of the Arduino board. We
can connect the power terminal of the motor to any digital PWM pin on the Arduino
board.
o Connect the ground terminal of the servo motor to the GND pin of the Arduino
board.
Sketch
1. #include <Servo.h>
2. int POSservo = 0;
3. Servo servo_5;
4. void setup()
5. {
6. servo_5.attach(5); // power pin connected to pin 5 of Arduino board
7. // Here, the pin of the Arduino board connected to the servo should be a PWM pin
8. }
9. void loop()
10. {
11. // It will sweep the servo from 0 to 180 degrees
12. for (POSservo = 0; POSservo <= 180; POSservo=POSservo+1)
13. {
Connection Diagram
We will show the connection using the Simulator so that the connections become clearer
and more precise.
Output
The shaft will rotate 90 degree in each direction i.e. approx. 180 degrees.
The Potentiometer will be used to control the position of the servo motor. The connection
will be similar to the last servo motor project, except the added Potentiometer.
Mini Servo Motor: It is defined as a tiny motor that can approximately rotate up to 180
degrees. It works similar to the usual servo motor, but smaller in size.
Principle
The project allows us to control the shaft at angles between 0 and 180 degrees. We can
also set the rotation of the shaft at different speeds.
The power pin of the servo motor is connected to the PWM pin of the Arduino board.
Here, we have connected the power terminal to pin 9 of the Arduino UNO R3 board.
Sketch
1. #include <Servo.h>
2.
3. Servo myservo;
4. // It creates a servo object, which is used to control the servo
5.
6. int potentioPIN = A0; // specified analog pin used to connect the potentiometer
We can also modify the code to modify the performance of the servo motor accordingly.
Connection
o Connect the signal terminal of the servo motor to the 5V pin of the Arduino board.
o Connect the power terminal of the servo motor to pin 9 of the Arduino board. We
can connect the power terminal of the motor to any digital PWM pin on the Arduino
board.
o Connect the ground terminal of the servo motor to the GND pin of the Arduino
board.
o One outer pin of the Potentiometer is connected to the ground (GND), and other
external pin is connected to 5V of the Arduino board.
Connection Diagram
We will show the connection using the Simulator so that the connections become clearer
and more precise.
Output
The shaft will rotate at angles between 0 and 180 degrees and again in the reverse
direction.
We can also modify the code by specifying it only in one direction from 0 to 180 degrees.
Hence, we can make changes according to the requirements.
Arduino DC motor
The DC motor is considered as the simplest motor, which has various applications ranging
from households to industries. Example includes an electric window in cars, electric
vehicles, elevators, etc.
The principle of the DC motors is based on Electromagnetic Induction. It means that the
rotation of the motor depends on the force generated by the magnetic fields. It converts
electrical energy into mechanical energy. Such motors can be powered from the direct
current.
Working of DC Motor
The DC motor consists of a stator, rotor, armature, and a commutator. The commutator
comes with brushes. There are two stationary magnets in the stator that are responsible
for producing the magnetic field.
The armature present in the DC motor carries the alternating current. Electrical energy is
converted into mechanical energy in the form of torque by the armature. It further transfers
this mechanical energy via shaft.
The commutator is defined as the electrical switch. It can also reverse the direction of the
current between the external circuit and the motor. The brushes act as an intermediate
between the external power supply and the rotating coils.
The wire ends are connected to the commutator. The commutator further energizes the
armature coils and connects the power supply and the rotating coils through brushes.
Advantages of DC motors
o Low cost
o Easy motor speed control
o High reliability
o Minimal Maintenance
o High starting torque
o Quick starting
o Variable speeds
o Harmonics free
Project 1:
Hardware Required
Connection
o Connect one end of the resistor to pin 10 (PWM) of the Arduino board.
o Connect the other end of the resistor to the middle pin of the transistor.
Connection Diagram
We will show the connection using the Simulator so that the connections become clearer
and more precise.
Project 2:
Here, we will discuss the connection of a DC Gear motor with the Arduino board using the
L293D H-Bridge motor driver.
Let's discuss the need to use the L293D H-Bridge motor driver with the DC motor.
L293 is defined as the motor driver IC that permits the DC motor to drive in any direction.
It can also simultaneously control two DC motors. It is a 16-pin Integrated Circuit (IC).
It receives signals from the microprocessor present on the Arduino board and transmits
this signal to the motor. It has two VCC or voltage pins, where one pin draws current for its
working and another is used to provide voltage to the DC motor.
The motor usually requires high current for its operation. We can use
the microcontroller present on the Arduino, but high current might damage the
microcontroller. To overcome this, the motor driver is used.
L293D is one of the most popular motor drivers used to drive the DC motors. It can run
DC motors up to 1 Ampere current load.
The four outputs present on the L293D driver makes it suitable for driving the 4-wire
stepper motor as well. We can also drive servo motors using the L293D driver.
L293D Pinout
Sketch
1. #define MOTOR_1 11
2. // PWM pin 11
3. #define MOTOR_A 10
4. // PWM pin 10
5. // we can also connect it to the other PWM pins of the Arduino
6. #define MOTOR_B 8
7. // digital I/O pin
8.
9. #define slow 64
10. #define normal 128
11. #define fast 255
12.
13. int Speed; // initialization of speed variable
14.
15. // created functions
16. void Forward_Rev(void)
17. {
18. analogWrite(MOTOR_1, Speed);
19. digitalWrite(MOTOR_A, HIGH);
20. digitalWrite(MOTOR_B, LOW);
21. }
22. void Backward_Rev(void)
23. {
24. analogWrite(MOTOR_1, Speed);
25. digitalWrite(MOTOR_A, LOW);
Connection
o Connect the red terminal of the power supply to the VCC of L293D.
o Connect the black terminal of the power supply to the GND of the L293D.
Connection Diagram
We will show the connection using the Simulator so that the connections become clearer
and more precise.
The 'Slow' mode of speed will cause the motor to rotate at a slow speed. We can also
change the mode to fast or normal, as explained in the code.
We can also add more speed parameters to the code as per our requirements.
POST- ASSESSMENT 13
Write TRUE if the statement is correct. Write FALSE if the statement is incorrect and
underline the word/group of words that made the statement incorrect.
1) ________ The stepper motor can control the angular position of the rotor without a open
feedback loop.
2) _________ The principle of the servo motor is based on Pulse Width modulation (PWM).
3) ________ It is defined as a tiny motor that can approximately rotate upto 180 degrees is
mini servo motor.
4) ________ Servo motor has three terminals signal, power, and ground.
5) ________ The ground, power, and signal wire are represented by black, green, and red
colors.
6) ________ he output shaft of the servo motor can be moved to a specific velocity, position,
and angle while regular motors cannot.
7) ________ Servo motors usually have a low pole count while the stepper motors have
high.
8) .________ The speed curve of the servo motor is more flexible compared to the stepper
motor.
9) ________ The stepper motor has low speed and accuracy than the servo motor.
10) ________ The use of motors on Mega is also limited. It means we can use 12 motors on
Arduino Mega.
Scoring Rubric:
Correct answers 20 pts
------------------------------------
Total: 20 pts
PRE- ASSESSMENT 14
Answer the following questions. Write your answers on a separate sheet of long bond
paper.
1. What is LED(Light Emitting Diode) Explain the importance of LED in our projects?
2. Write a simple code using Blinking an LED?
Scoring Rubric:
Content/Idea: 5 pts
Coherence: 3 pts
Handwriting: 2 pts
------------------------------------
Total: 10 pts
CONTENT DEVELOPMENT 14
Blinking an LED
It is the simple basic project created using Arduino. LED (Light Emitting Diode) is an
electronic device, which emits light when the current passes through its terminals. LED's
are used in various applications. It is also used as an ON/OFF indicator in different
electronic devices.
In this project, we will connect the LED to the digital pin on the Arduino board.
The LED will work as a simple light that can be turned ON and OFF for a
specified duration.
Structure of LED
An LED is a two-terminal device. The two terminals are called as Cathode and
Anode.
It is shown below:
The long terminal is called Anode, and the shorter terminal is called Cathode.
Here, cathode is the negative terminal and anode is the positive terminal.
Sketch
We need to install the Arduino IDE, to begin with the
coding, which is already discussed.
Open the IDE and start with the coding, which is given
The sketch will be uploaded to the board after the correct compiling, as shown below:
Procedure
The procedure to join the components of the project is shown below:
Learn more
o Attach an LED on the breadboard. We need to plug-in the two terminals of an LED
into the holes of the breadboard.
We can plug-in the LED anywhere on the breadboard.
o Connect the left leg of the resistor (connected in series with red LED) to the digital
output pin of the UNO board, i.e., PIN 8.
o Connect the negative/shorter terminal (Cathode) of the LED to the GND pin of the
UNO board using the wire, as shown below:
The shorter terminal indicates the negative. So, we will connect the shorter terminal to the
Ground (GND).
o Connect the USB cable.
o Select the board and serial port in the Arduino IDE.
o Upload the sketch or code on the board.
o The LED will dim and light for the specified duration.
Important points
The important points to be considered in this project are listed below:
o The resistor must be connected in series with the LED.
The resistor prevents the excess current from reaching the LED. The excess current in the
connection can burn the LED. Hence, a resistor in series with the LED is used in the
connection.
o We can use any pin as the OUTPUT pin. For example, 8, 13, 7, 4, and 3. The
other pins are PWM and analog pins.
o One terminal of the LED is connected to the Ground while the other terminal is
connected to the digital pin. The digital pin has only two values 0 or 1.
o HIGH = 1
o LOW = 0
o Arduino UNO board is recommended for all basic projects because it is easy to
understand and implement. It is also the standard Arduino board from all types of
boards used. It supplies power and also acts as a serial port.
We have already discussed a project of blinking an LED. Here, we will discuss a project of
blinking two LED's.
The concept of blinking two LED's is similar to the blinking of a single LED. As we know,
we can use the resistance of any value, so let's take the resistors of 470 Ohms. The
resistors reduce the amount of current reaching the LED, which saves the LED from being
burnt.
We can also use other resistors depending on the circuit limit and requirements.
The long terminal is called Anode (positive charged), and the short terminal is called
Cathode (negative charged).
Components
Here, we will use the digital output pin number 13 and 7. The positive terminal of the red
LED is connected to the PIN 13, and the negative terminal (anode) is connected to the
ground.
Similarly, the positive terminal (cathode) of the green LED is connected to PIN 7 and the
negative terminal is connected to the ground.
As mentioned, two resistors each of 470 Ohms, will be connected in series to the two
LEDs in the project.
The structure will represent the pinout diagram of the project. It is shown below:
(Integrated Development Environment) and start with the coding, which is given below:
1. void setup ()
2. {
3. pinMode ( 13, OUTPUT); // to set the OUTPUT mode of pin number 13.
4. pinMode ( 7, OUTPUT); // to set the OUTPUT mode of pin number 7.
5. }
6. void loop ()
7. {
8. digitalWrite (13, HIGH);
9. digitalWrite (7, LOW);
10. delay(1500); // 1.5 second = 1.5 x 1000 milliseconds
11. digitalWrite (13, LOW);
12. digitalWrite (7, HIGH);
13. delay(1000); // 1 second = 1 x 1000 milliseconds
14. }
We can modify the delay duration according to our choice or as per the requirements.
The sketch will be uploaded to the board after the correct compiling, as shown below:
The RX and TX LED on the board will light up after the successful uploading of the code.
Procedure
We need to check that the plug-in is performed correctly, as shown above. For any
confusion, check the pin diagram shown above in the heading-
Structure of project.
Here, the red wire is connected to the PIN 13, and the blue wire is connected to the GND.
Similarly, the green wire is connected to the PIN 7, and the orange wire is connected to
the GND.
The shorter terminal indicates the ground. So, we will connect the shorter terminal to the
Ground (GND).
It means when the red LED will be ON, the green LED will be OFF and vice versa.
Arduino Switch
Switches are used to turn ON/OFF devices and to connect different parts of a circuit. The
slide-switch in Arduino moves the slider of the switch from the open position (ON) to the
closed position (OFF).
It allows the flow of current in the circuit without the need for splice wire. The slide
switches are widely used in small circuits applications.
o Closed circuits
The closed circuits have closed loop. Electrons can easily flow in a closed circuit and light
up an LED.
o Open circuits
The open circuits have open ends, due to which electrons cannot flow through the circuit.
We can use an electronic component switch, to open and close circuits without the need
to disconnect the wires by hand again and again.
Types of Switches
There are major four types of switches in Arduino, which are listed below:
It is a three-terminal switch. It has a single input, which can switch between two outputs.
It is a switch with one input and three outputs, where each input corresponds to any of the
output in a circuit.
It is a switch with two inputs and four outputs. Each input of a switch in Arduino can be
connected to either of the two outputs.
Throw: It signifies the number of positions in which each pole of the switch can connect to
it.
Code Example
Let's discuss an example to light an LED using a Switch. Here, we will use the SPDT
(Single Pole Double Throw) Switch.
If we leave one side of the switch, it can work as SPST (Single Pole Single Throw) switch.
Learn more
Learn more
5. Connect the positive terminal of LED in series with the resistor to PIN 8.
6. Connect the common terminal or the middle terminal to pin number 3. It is because the
middle terminal is the input terminal.
7. Connect one end of slide switch to Ground and another end to 5V.
Arduino button
The buttons are similar to switches that create and break electrical connections in the
circuits. The button plays a transition between ON and OFF state. A single press turns the
state ON, while another press turns the state OFF. It means that the button connects the
two points in a circuit when we press them.
o NO (Normally Open)
We mostly use NO types of buttons. In such type, the state of the button is in rest. It
means that a terminal in such a condition is not connected.
It is shown below:
o NC (Normally Closed)
It is defined as the working state of the button. It connects the terminals of the circuit and
allows current to flow through the load.
It is shown below:
Due to the open ends of the circuit, the current cannot flow through it. The state of the
circuit is in rest.
The current can easily flow through the circuit due to its connected ends. The LED
Another type of button is pushbutton, which is widely used in projects and circuits.
Structure of pushbutton
The pushbutton is a square shape button with four terminals, as shown below:
The two pins are next to each other on one side and another two pins on the other side.
The pins across to each other are connected. The pins next to each other can only be
connected, when we press the button.
FRELEC103 PROPERTY OF NORZAGARAY COLLEGE
ROBOTICS 47
We can also connect two opposite terminals of the pushbutton, as shown below:
Code Example
Here, we will light an LED by pressing the pushbutton. When we press the push button, it
turns ON the LED connected to the PIN 13 on the Arduino UNO board
Components Required
Output
When we continuously press the button, LED will light. The message 'LED is ON' will print
on the Serial Monitor after every 500 milliseconds.
The potentiometer is a device that is used to measure the voltage or electric potential. It
provides a variable resistance when the shaft of the device is turned.
Here, we will measure the amount of resistance as an analog value produced by the
potentiometer. We will connect the potentiometer to the Arduino UNO board and will
measure the state of the potentiometer. The required code will be uploaded from our
computer to the Arduino board.
The variable resistance measured by the potentiometer can be easily read as an analog
value into the Arduino board.
What is Potentiometer?
The potentiometer is a three-terminal device. It has a rotating contact that acts as an
adjustable voltage divider.
Working: The fixed input voltage is applied across the two ends terminal of a
potentiometer, which further produces the adjustable output voltage at the wiper or slider.
As the slider moves from one end to another, the divider can vary the output voltage from
maximum to Ground.
The connection of potentiometer with Arduino board is shown below:
The middle terminal of potentiometer is connected to the analog pin to read the analog
data.
Potentiometer with LED
In this example, we will use a potentiometer that controls the value at which LED blinks.
Hardware Required
Learn more
The required components are listed below:
o 1 x red LED
o Arduino UNO R3 board
o 10K Ohm Potentiometer
o Jump wires
o 220 Ohm resistor
Connection
o One outer pin of the potentiometer is connected to ground (GND), and other
external pin is connected to 5V of the Arduino board.
o The middle pin of the potentiometer is connected to the analog input pin A2 of the
board.
o The positive terminal of the LED is connected in series with 220 Ohm resistor to
pin number 13 of the board, and the negative terminal is connected to the GND.
Procedure
The analog input will turn the LED ON and OFF, which is connected to the pin number 13
of the Arduino UNO board. The time (delay time) at which LED is ON/OFF depends on the
When the shaft is turned, the amount of resistance on either side of the potentiometer
changes. The distance between the pin connected to 5V and GND gives the analog input.
We read input 0 when the shaft is turned in one direction, while we read input 1023 when
the shaft is turned in another direction.
In between the turning input between 0 and 1023, we get the desired value returned by
the analogRead( ). It is proportional to the voltage being applied to the pin.
Code
Arduino Simulator
The Arduino simulator is a virtual portrayal of the circuits of Arduino in the real world.
We can create many projects using a simulator without the need for any hardware.
The Simulator helps beginner and professional designers to learn, program, and create
their projects without wasting time on collecting hardware equipments.
Types of Simulator
There are various simulators available. Some are available for free, while some require a
license to access the simulators.
Java Try Catch
Some types of simulators are listed below:
o Autodesk Tinkercad
o Emulator Arduino Simulator
o Autodesk Eagle
o Proteus Simulator
o Virtronics Arduino Simulator
o ArduinoSim
Autodesk Eagle is an advanced simulator, which is used to design 2D and 3D models of
PCB, modular designs, multi-sheet schematics, real-time synchronization, etc.
How to access simulator?
Here, we are using the Autodesk Tinkercad Simulator.
The steps to access the TINKERCAD are listed below:
1. Open the official website of tinkercad. URL: https://www.tinkercad.com/
A window will appear, as shown below:
2. Click on the three horizontal lines present on the upper right corner.
3. Click on the 'Sign in' option, if you have an account in Autodesk. Otherwise, click on
the 'JOIN NOW' option if you don't have an account, as shown below:
We can select any sign-in method. Specify the username and password.
We already have an account in Autodesk, so we will sign-in directly with the username
and password.
Select the preference according to the requirements and sign-in using Gmail, etc.
6. We are now ready to start with the Autodesk Tinkercad. We can start creating our
projects.
Autodesk Tinkercad Simulator
It is also a simulator that is used to design virtual circuits.
Features of Tinkercad
The features of Tinkercad are listed below:
o Glow and move circuit assembly. It means we can use the components of a
circuit according to the project requirement. Glow here signifies the glowing of
LED.
o Integrated product design. It means the electronic components used in the
circuitry are real.
o Arduino Programming. We can directly write the program or code in the editor of
the simulator.
o We can also consider some ready-made examples provided by the tinkercad for
better understanding.
o Realtime simulation. We can prototype our designs within the browser before
implementing them in real-time.
How to use a simulator?
Sign-in on the Autodesk Tinkercad, as explained above. Now, follow the below steps:
o Click on 'Create new circuit' option, as shown below:
o A window will appear. We need to drag and drop the desired components in the
project screen. It is shown below:
o Click on the drop list of components and select the 'All' option.
The drop list will appear as:
Let's understand with an example to blink an LED. We can use both ( blinking an LED in
basic projects and the one specified below) methods to blink an LED.
The steps are listed below:
o Search UNO R3 and drag-drop the board on the project screen. We can select any
board according to the requirements.
o Search a LED, and 1 resistor of 220 ohms and drag-drop them on the project
screen.
After selecting the resistor, a box to set the resistance will appear, as shown below:
Here, we have selected the red color for LED. We can also choose other colors.
After selecting the LED, a box to set the color will appear, as shown below:
o Now, connect the wires. For wiring, just select the point on the board to the
terminal of the component. We are not required to search for wires in the search
box.
o The circuit will now appear as:
The LED will light up for 1 second and dim for 1 second.
The lighting LED is shown below:
Serial Monitor
The serial monitor is present on the bottom of the coding screen.
It will look like the below image:
3 Pole 1 Switches
4 Buttons 6 potentiometer
2 DPDT 7 ground (GND)
5 Normally Open 8 Sliding wiper
10analog pin 9 three-terminal device
1) ________ used to turn ON/OFF devices and to connect different parts of a circuit.
2) ________ It is a switch with two inputs and four outputs.
3) ________ It signifies the number of circuits the switch can control.
4) ________ are similar to switches that create and break electrical connections in the
circuits.
5) ________ We mostly use NO types of buttons. In such type, the state of the button is in
rest. It means that a terminal in such a condition is not connected.
6) ________ is a device that is used to measure the voltage or electric potential. It provides a
variable resistance when the shaft of the device is turned.
7) ________ One outer pin of the potentiometer is connected to_________, and other
external pin is connected to 5V of the Arduino board.
8) ________The potentiometer structure consists of a sliding contact ________ a resistive
element, electrical terminals, and a housing.
9) _________ The potentiometer is a ___________.
10) ________ The middle terminal of potentiometer is connected to the _______to read the
analog data.
Scoring Rubric:
Content/Idea: 5pts.
Coherence: 3pts.
Handwriting: 2pts.
Total Score: 10pts.