You are on page 1of 17

Activity Number: ACTIVITY 2.

1 Title: Interfacing Analog Sensors


Course Code: CPE 006 Course Title: Microprocessor Systems
Date Performed: Date Submitted:
Section: EE32S1
May 17, 2021 May 17, 2021
Student Name: Nagum, Carl Joseph, B. Instructor: Engr. Arriane D. Cabreros

“I affirm that I have not given or received unauthorized help on this activity and that this work my own”
I. OBJECTIVES/LEARNING OUTCOMES
→To demonstrate the functionality of different analog sensors in Arduino.
→To implement the pulseln( ) function in determining distance.
→To use calibration and smoothing with analog signals.
→To introduce the concept of inputs in an embedded system for both analog and digital inputs.
→To implement circuits with analog and digital input components and the microcontroller.
→To write a program that can read inputs for analog and digital inputs.
II. RESULTS AND SCREENSHOTS OF OUTPUTS
A.) Better Debounce
CODE:

OUTPUT:

ACTUAL PICTURE OF TILT SENSOR


B.) Ultrasonic distance
CODE:

OUTPUT:

ACTUAL PICTURE OF ULTRASONIC DISTANCE SENSOR:


C.) Motion Detection
CODE:

OUTPUT:

ACTUAL PICTURE OF MOTION SENSOR:


D.) Gas Detection
CODE:

OUTPUT:

ACTUAL PICTURE OF GAS SENSOR:


E.) Signal Calibration
CODE:

OUTPUT:

ACTUAL PICTURE OF PHOTORESISTOR:


F.) Digital Inputs
CODE:

OUTPUT:
G.) Pull-Down and Pull-Up Resistors
CODE:

OUTPUT:
H.) Analog Inputs
CODE:

OUTPUT:
I.) Pulse Width Modulation
CODE:

OUTPUT:
III. OBSERVATIONS FOR EACH RESULT
A.) Observations for Better Debounce
In this simulation, I noticed that the built-in LED in the Arduino board turns on when the tilt sensor almost reaches the
maximum value and it turns off when the tilt sensor is approaching its minimum value. The circuit was able to detect the
changes in motion. Specifically, the code is programmed with an if-else function wherein it states that if the tilt sensor does
not detect any changes in motion, the built-in LED will remain off, otherwise the LED will turn on to indicate that the tilt sensor
detects a change in motion.
B.) Observations for Ultrasonic distance
In this simulation, I first observed that the connection of the circuit and code must be in sync to avoid errors. It is
because, during my first attempt, I accidentally interchanged the connection of pins 6 and 7 to the trigger and echo pin of the
ultrasonic distance sensor resulting in an error in the setup. The sensor has a limited range when detecting the distance and
once the distance is not within the range, the ultrasonic distance sensor can’t indicate the specific distance. I also noticed that
the delay time is specified at 10 microseconds, which is almost negligible. The unit of distance is also declared in the code.
That is why inches and centimeters are being displayed on the serial monitor.
C.) Observations for Motion Detection
In this simulation, I observed that the built-in LED in the PIR motion sensor turns on when a motion is detected and
immediately turns off when the motion is terminated. I also noticed that the PIR motion sensor can only detect the motion
within its range. The code also uses the if-else function wherein the if function states that when the PIR sensor detects motion,
the built-in LED will turn on, otherwise the else function will be executed wherein the built-in LED will remain off.
D.) Observations for Gas Detection
During the execution process, I observed that the two LEDs and piezo buzzer serve as an indicator when the gas
sensor senses the smoke. The red LED turns on if the smoke is within the range of the gas sensor and the piezo buzzer
makes a sound. On the other hand, the green LED turns on if there is no smoke within the range of the gas sensor and the
piezo buzzer does not make any sound. The sensor value is displayed on the serial monitor is to see if the gas sensor senses
more than its threshold value, which is the stimulus in the code that causes the LED and piezo buzzer to react concerning the
value sensed by the gas sensor.
E.) Observations for Signal Calibration
In this simulation, I observed that the LED brightness depends on the light sensed by the photoresistor. The LED
remains off with a value of zero in the serial monitor, but as the photoresistor senses the presence of light, the value in the
serial monitor increases and the LED turns on. It is because the LED serves as an indicator if there is an absence or presence
of light. During the coding process, I noticed that a map function is used to change one range of values to another range of
values. The main purpose of the map function is to convert the analog input that ranges from 0 to 1023 to byte, so the output
would range from 0 to 255.
F.) Observations for Digital Inputs
In this simulation, I observed that the LED has a direct relationship to the push button. I noticed that the code also
uses the if-else function wherein in the if section of the command it states that when the button state is 1, the LED will turn
on, otherwise the else section of the command will be performed. That is why the LED turns off when the button is not pushed.
Through this simulation, I verified that the digital inputs and outputs of Arduino can read logic values, specifically the binary
which is 0 and 1.
G.) Observations for Pull-Down and Pull-Up Resistors
In this simulation, I observed that the circuit is almost similar to the circuit of digital inputs. I noticed that terminal 2a
of the push button is connected directly to the ground and terminal 1b is connected to PIN 2 of the digital input and output of
the Arduino. In the code, it also uses the if-else function wherein in the if section of the command it states that when the button
state is 1, the LED will turn on, otherwise the else section of the command will be performed. I noticed that the use of pull-up
and pull-down resistors is used to change the default digital state to the desired state. For instance, in the simulation it is a
pull-down resistor since the default state is low because the LED is off, then the LED will only turn on when the push button
is pressed, which changes the low state to a high state.
H.) Observations for Analog Inputs
In this simulation, I observed that the speed of the blinking LED changes as the potentiometer reaches the maximum
value. The potentiometer is declared as the analog input while the LED is the output. During the code execution, I noticed that
the delay time is dependent on the potVal, which is the value produced by the potentiometer. The delay time in the previous
setup of blinking LED is always the same and does not vary, but in this setup, because the delay time is dependent on the
value of the potentiometer, the LED blinking can also be varied by adjusting the potentiometer. The LED does not blink at the
minimum value of the potentiometer since the delay time is zero and the blink started to occur while the potentiometer is being
adjusted to the maximum value.
I.) Observations for Pulse Width Modulation
In this simulation, I observed that the LED brightness varies when the potentiometer is being adjusted. I noticed that
the potentiometer is declared in the setup as an analog input while the LED is declared as the output. In the execution process,
the potVal controls the brightness of the LED because the analogRead can take the analog input from the potentiometer. The
LED will remain off as the potentiometer is at the minimum value, then the LED brightness relatively increases as the
potentiometer is being adjusted to its maximum value.

IV. CONCLUSION
Based on the different setups performed, I can conclude that the Arduino can be applied in various systems with its
flexibility. It can be installed in security systems, fire alarm systems, emergency systems, and many other systems. Arduino
is a programmable board that is very flexible because it has many features that can be used to develop a system. Therefore,
an Arduino can maximize its operation depending on the code that will serve as the input because, as mentioned earlier, an
Arduino is a programmable board which simply means that its operation is code dependent. This particular activity shows that
the Arduino can also handle analog sensors that continuously provide analog outputs or signals on the quantity being
measured by that specific sensor. It is due to the use of the pulseln () function in the coding, which allows the Arduino to
measure the high or low period while a signal is constantly changing. It can also be used in signal calibration because the
Arduino allows a specific system to control the variation of the signal such as in the setup E performed above. To sum up, all
the setup that was performed above shows the flexibility of how to use the Arduino board with proper coding because it can
both handle digital and analog signals. It can be used to develop other systems that can help with the advancement of
technology.
V. TINKERCAD SIMULATION LINK
A.) Better Debounce
https://www.tinkercad.com/things/kArAAoYBvuj-better-debouncer/editel
B.) Ultrasonic distance
https://www.tinkercad.com/things/jhp5wKZGcOo-ultrasonic-distance/editel
C.) Motion Detection
https://www.tinkercad.com/things/f6frh35ZMVj-motion-detection/editel
D.) Gas Detection
https://www.tinkercad.com/things/62SlnMLp8PD-gas-detection/editel
E.) Signal Calibration
https://www.tinkercad.com/things/0fLwagfUjAa-signal-calibration/editel
F.) Digital Inputs
https://www.tinkercad.com/things/bau7tjo3opV-digital-inputs/editel
G.) Pull-Down and Pull-Up Resistors
https://www.tinkercad.com/things/1BYCXetktz0-pull-down-and-up-resisitor/editel
H.) Analog Inputs
https://www.tinkercad.com/things/lgFNz85H7dm-analog-inputs/editel
I.) Pulse Width Modulation
https://www.tinkercad.com/things/hTVIKNtLFy5-pulse-width-modulation/editel

You might also like