Anda di halaman 1dari 7

CENTRAL PHILIPPINE UNIVERSITY

COLLEGE OF ENGINEERING

AUTOMATIONS USING ARDUINO


“Ultrasonic Sensor & DC Motor”
ECE 4204 – MICROPROCESSOR SYSTEMS
LABORATORY NO. 5

Gelvie Lagos | ECE 4204 | January 22, 2018


LEARNING OUTCOMES
At the end of the laboratory the student will be able to:

a. Use Arduino Analog input port.


b. Create program using Ultrasonic Sensor and DC Motor
c. Demonstrate the operation of DC motor and Ultrasonic sensor
d. Solve problems in the industry and community using Arduino, ultrasonic sensor and DC motor.

MATERIALS AND EQUIPMENTS


1. A laptop or a personal computer 1 unit
2. Latest Arduino IDE installed 1 unit
3. Arduino Uno R3 microcontroller 1 unit
4. Ultrasonic Sensor 1 pc
5. DC Motor 1 pc
6. Power transistor (TIP 120) 1 pc

CONTROLLING THE DC MOTOR USING ARDUINO


A. INTERFACING MOTOR WITHOUT SPEED OR DIRECTION CONTROL
Actuators (motors, solenoids, etc) in general require a lot of current to work, but microcontrollers or
microprocessors can supply limited amount of current through their GPIOs, usually around 2 -8 mA – just
enough to drive a 3 mm LED. So we need some sort of a relay that can drive high current to the motors when it
receives a logical high/low signal from the microcontroller. Below is a simple circuit that shows how to
interface an actuator to a microcontroller, we can connect the 2.2K resistor to any digita l output pin.

Figure 1. Wiring Diagram DC motor with NO Speed and Direction Control

PAGE 1
Upload the Code Below

Figure 2. Code for DC motor with NO Speed and Direction Control

B. INTERFACING MOTOR WITH SPEED, BUT NO DIRECTION CONTROL


We might also need to control the speed of the motor rotation, in other words the speed at which the
robot moves – this is usually done by controlling the voltage supply to the motors. You can do this using the
on-chip Digital to Analog Controller (DAC), but not all microcontrollers or microprocessors have this feature,
so we generally use the concept of Pulse Width Modulation (PWM) to emulate voltage control. Below are the
instructions to control the speed of a DC motor, notice that we can connect the 2.2K resistor only to PWM (~)
output pins.

Figure 3. Wiring Diagram DC motor with Speed Control, but NO Direction Control
PAGE 2
Upload the code below

Figure 4. Code of DC motor with Speed Control, but NO Direction Control

See complete documentation here: https://create.arduino.cc/projecthub/licensedGeek/controlling-


a-dc-motor-from-an-arduino-101-board-f4954b

USING THE ULTRASONIC SENSOR


WHAT IS AN ULTRASONIC SENSOR?
An Ultrasonic sensor is a device that can measure the distance to an object by using sound waves. It measures
distance by sending out a sound wave at a specific frequency and listening for that sound wave to bounce back. By
recording the elapsed time between the sound wave being generated and the sound wave bouncing back, it is
possible to calculate the distance between the sonar sensor and the object.

Figure 5. Diagram of the basic ultrasonic sensor operation


PAGE 3
Since it is known that sound travels through air at about 344 m/s (1129 ft/s), you can take the time for the sound
wave to return and multiply it by 344 meters (or 1129 feet) to find the total round-trip distance of the sound wave.
Round-trip means that the sound wave traveled 2 times the distance to the object before it was detected by the
sensor; it includes the 'trip' from the sonar sensor to the object AND the 'trip' from the object to the Ultrasonic sensor
(after the sound wave bounced off the object). To find the distance to the object, simply divide the round-trip
distance in half.

It is important to understand that some objects might not be detected by ultrasonic sensors. This is because some
objects are shaped or positioned in such a way that the sound wave bounces off the object, but are deflected away
from the Ultrasonic sensor. It is also possible for the object to be too small to reflect enough of the sound wave back
to the sensor to be detected. Other objects can absorb the sound wave all together (cloth, carpeting, etc), which
means that there is no way for the sensor to detect them accurately. These are important factors to consider when
designing and programming a robot using an ultrasonic sensor.

USING ARDUINO AND ULTRASONIC SENSOR


1. Make a circuit as per the given diagram. In Ultrasonic Sensor there are four pins are available. Left-sided
pin VCC is connected to 5V, Trigger pin is connected to 13, Echo pin connected to 12 and GND pin is
connected to Arduino Ground.

Figure 6. Breadboard diagram and code for measuring the distance using Ultrasonic Sensor

PAGE 4
2. Shown above is the code for Ultrasonic Sensor. Here, we have declared two pins which are for trigger pin, echo pin
and two variables for storing distance and time occupied by the ultrasonic wave. In setup, the pins are defined as
input and output and the Serial Monitor is begun at 9600 Baud. In the loop, first, generate a 10-microsecond pulse to
start ranging of Ultrasonic. After this, the time occupied by Ultrasonic stored into the duration. Then converted time
into the Distance. Finally printed it to the Serial Monitor.

Figure 7. Screenshot of the output of Serial Monitor.

For full documentation please see https://iotguider.in/arduino/ultrasonic-sensor-arduino/

HANDS-ON EXERCISES
1. Perform all the activities.
2. Create a program that uses a DC motor and an Ultrasonic Sensor. See samples below:

Figure 8. Sample application of ultrasonic sensor with conveyor belt

PAGE 5
PROBLEM-BASED DESIGN LABORATORY
1. Identify a problem in your community, or schools, or at home.
2. Create a solution to the problem using your Arduino microcontroller.
3. Design and implement the solution.
4. Provide Schematic diagram, wiring diagram and breadboard diagram of your design.
5. Provide the detailed procedure of your design and testing.
6. Due after a week. Strictly no more extension and grace period.

DESIGN LAB FORMAT

A. COVER PAGE
Create your own cover page be sure you indicate PROBLEM-BASED DESIGN
LABORATORY No. X

B. INTRODUCTION
Make an introduction by describing the current situation, what should be the ideal
situation, identify the gaps, and what should be done to address the gaps.

C. PROBLEM STATEMENT
State the problem you want to solve using ARDUINO.

D. PROPOSED SOLUTION TO THE PROBLEM


State here how you are going to solve the problem by proposing a solution with block
diagrams or schematic diagram. You have to explain how the system works to solve
the problem.

E. PROCEDURES AND TESTING


Make a detailed procedures supported with pictures, schematic diagram, wiring
diagram and breadboard diagram of your design.

F. CODES AND FINAL DESIGN OUTPUT


Create a program easy to understand and put a comment on each line if possible
also provide photos of your output.

G. LEARNING EXPERIENCES
In your conclusion you should write all the learning experiences that you acquired
during and/or after the

PAGE 6

Anda mungkin juga menyukai