Unit 6: Introduction of Arduino and Sensors
I. Foundations of Sensor-Based Electronics
Arduino-based sensing systems connect physical quantities in the environment to electronic computation and control. A sensor detects a quantity such as light, distance, temperature, or infrared radiation; its electrical output is read by a microcontroller, processed according to a program, and used to drive an output device.
A. Defining Characteristics
The operation of every system in this unit depends on a chain from physical input to useful response.
- Measurement chain: A typical system follows
physical quantity -> sensor -> electrical signal -> Arduino -> output, where the output may be an LED, buzzer, display, motor, or transmitted data. - Transduction: A sensor is a transducer because it converts one form of energy or physical variation into an electrical quantity such as voltage, resistance, or timed pulses.
- Signal conditioning: Components such as voltage dividers, amplifiers, and comparators adapt a raw sensor output to the voltage and logic levels accepted by Arduino.
- Microcontroller role: The Arduino executes stored instructions, samples input pins, performs calculations, and changes output pins in response.
- Electrical reference: Voltage is measured relative to ground (
GND), so connected modules normally require a common ground with the Arduino. - Safe operation: On a 5 V Arduino Uno, input voltages should remain between
0 Vand5 V; excessive voltage or current can damage the ATmega328P microcontroller.
II. Electrical Signal Forms
Electrical information reaches a microcontroller mainly as continuously variable analog levels or discrete digital states.
A. Analog and digital signals
Analog signals represent a range of values, whereas digital signals use a finite set of logic states.
- Analog signals
- Continuous variation: An analog voltage can ideally take any value within a range; an LDR voltage might change from
1.2 Vto3.7 Vas illumination changes. - Arduino conversion: The Uno has a 10-bit analog-to-digital converter (ADC), so
analogRead()converts approximately0-5 Vinto integers from0to1023. - Resolution: With a 5 V reference, one ADC count represents approximately:
- Continuous variation: An analog voltage can ideally take any value within a range; an LDR voltage might change from
Resolution = Vref / 1024 = 5 V / 1024 = 4.88 mV per countHere, Vref is the ADC reference voltage.
- Digital signals
- Discrete levels: Binary signals use
LOWandHIGH, conventionally associated with logic0and logic1. - Input and output:
digitalRead(pin)detects a state, whiledigitalWrite(pin, HIGH)drives an output near the board's supply voltage. - Timed digital data: Digital information may also be encoded in pulse duration or pulse sequences, as in ultrasonic Echo pulses and DHT sensor communication.
- Contrast: Analog transmission preserves magnitude but is sensitive to noise; digital transmission gives clear states and supports encoded data but has finite resolution or timing constraints.
- Discrete levels: Binary signals use
III. Arduino Uno Board
The Arduino Uno is a development board built around the ATmega328P microcontroller, providing accessible pins, power regulation, USB communication, and a programmable environment.
A. Arduino board (pin configuration and description)
The Uno's pin groups connect sensors and actuators to a 5 V, 16 MHz microcontroller.
- Digital pins
0-13: Fourteen pins can be configured withpinMode()asINPUT,INPUT_PULLUP, orOUTPUT.- Pins
0(RX) and1(TX) support serial communication. - Pins
2and3support external interrupts. - Pins marked
~(3, 5, 6, 9, 10, 11) provide pulse-width modulation throughanalogWrite().
- Pins
- Analog pins
A0-A5: Six ADC inputs measure analog voltage; they may also be used as digital I/O.A4is SDA andA5is SCL for I2C communication. - SPI pins: Digital pins
10-13provideSS,MOSI,MISO, andSCKfunctions; these are also available through the ICSP header. - Power pins:
5Vand3.3Vsupply modules,GNDis the zero-volt reference, andVinaccepts an external input before regulation.IOREFindicates board logic voltage. - Reference and reset:
AREFcan provide an external analog reference, while pullingRESETlow restarts the program. - Board interfaces: The USB connector supports programming, serial communication, and power; the DC jack accepts a suitable external supply. The onboard
LLED is connected to pin13. - Programming pattern: Initialization belongs in
setup(), which runs once; repeated sensing and control belong inloop().
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}B. Applications and Limitations
Arduino simplifies prototyping but does not remove electrical and timing constraints.
- Applications: Common uses include data logging, alarms, automatic lighting, environmental monitoring, robotics, and basic Internet of Things nodes.
- Current limit: I/O pins are intended for small currents, commonly designed around
20 mAor less per pin; motors and high-power loads require driver circuits. - ADC limitation: The Uno ADC measures voltage, not resistance or physical quantities directly, and its 10-bit readings can fluctuate because of noise or supply variation.
- Memory and speed: The ATmega328P has limited memory and processing capacity compared with a computer, so complex imaging or large datasets need more capable hardware.
IV. Infrared Detection
An infrared sensing module detects infrared radiation, often to identify nearby objects without mechanical contact.
A. IR sensor
A common reflective IR sensor emits invisible infrared light and tests whether an object reflects part of it back.
- Emitter: An IR LED commonly radiates near
940 nm, beyond visible red light. - Receiver: A photodiode or phototransistor changes current when reflected IR reaches it; dark and shiny surfaces produce different reflection levels.
- Comparator module: Modules often use an
LM393comparator and an adjustable potentiometer to convert the receiver voltage into a digital output. - Connections: Typical pins are
VCC,GND, andOUT; some boards also expose an analog output. Many obstacle modules makeOUTLOW when an object is detected. - Arduino reading:
const int irPin = 2;
void setup() {
pinMode(irPin, INPUT);
Serial.begin(9600);
}
void loop() {
Serial.println(digitalRead(irPin));
delay(50);
}- Applications: IR sensing supports obstacle detection, line-following robots, object counters, and short-range proximity switches.
- Limitations: Sunlight, remote controls, target color, angle, and surface reflectivity can cause unreliable readings; reflective modules do not measure distance accurately.
V. Light-Dependent Resistance
An LDR is a passive light sensor whose resistance changes with incident illumination.
A. LDR
An LDR, or photoresistor, normally has high resistance in darkness and lower resistance under bright light.
- Material behavior: Incident photons create additional charge carriers in the photosensitive semiconductor, increasing conductivity.
- Nonlinear response: Resistance may fall from hundreds of kilohms or more in darkness to a few kilohms in strong light, but exact values depend on the device.
- Voltage divider: Because Arduino measures voltage rather than resistance, the LDR is paired with a fixed resistor
R:
Vout = Vcc x R / (RLDR + R)Here, Vcc is the supply voltage, RLDR is LDR resistance, R is the fixed resistor connected to ground, and Vout goes to an analog pin.
- Interpretation: In this arrangement, brighter light lowers
RLDR, increasingVoutand theanalogRead()result. Reversing the divider reverses that trend. - Applications: LDRs are used in automatic streetlights, display brightness control, light alarms, and day-night detection.
- Limitations: They respond relatively slowly, vary between units, and do not provide calibrated lux measurements without calibration.
VI. Ultrasonic Distance Measurement
An ultrasonic sensor determines distance by timing the round trip of a sound pulse whose frequency is above human hearing.
A. Basic principle of ultrasonic sensor
A module such as the HC-SR04 transmits an ultrasonic burst and measures the echo time from a target.
- Triggering: A HIGH pulse of about
10 microsecondsonTrigcommands the module to transmit a burst, typically eight cycles at40 kHz. - Echo timing: The
Echopin remains HIGH for the measured round-trip travel timet. - Distance equation:
d = v x t / 2Here, d is one-way distance, v is the speed of sound, and t is round-trip time. Division by 2 accounts for travel to the object and back.
- Practical conversion: Near room temperature,
vis approximately343 m/s, giving:
d (cm) approximately t (microseconds) / 58- Worked example: For an Echo duration of
1160 microseconds, distance is approximately1160 / 58 = 20 cm. - Applications: Ultrasonic sensors support parking aids, tank-level estimation, robot navigation, and non-contact presence detection.
- Limitations: Soft materials absorb sound, angled surfaces deflect echoes, nearby objects create false returns, and common modules have a blind zone near
2 cm. Temperature also changes sound speed.
VII. Digital Temperature and Humidity Sensing
DHT sensors combine a temperature element, humidity element, and internal controller that sends calibrated digital data to Arduino.
A. Temperature sensor (DHT11/DHT22)
The DHT11 and DHT22 measure both ambient temperature and relative humidity but differ in range, accuracy, and sampling rate.
-
DHT11
- Temperature: Typical specified range is
0-50 degrees C, with accuracy around+/-2 degrees C. - Humidity: Typical range is
20-80% RH, with accuracy around+/-5% RH. - Sampling: Readings should generally be spaced by at least
1 second.
- Temperature: Typical specified range is
-
DHT22
- Temperature: Typical specified range is
-40 to 80 degrees C, with accuracy around+/-0.5 degrees C. - Humidity: Its range extends approximately
0-100% RH, with typical accuracy around+/-2% to +/-5% RH. - Sampling: Readings should generally be spaced by at least
2 seconds.
- Temperature: Typical specified range is
- Sensing principle: A capacitive humidity element changes capacitance with absorbed water vapor, while a thermistor changes resistance with temperature.
- Digital interface: The sensor uses one data line with precisely timed pulses; it is not read with
analogRead(). A pull-up resistor, often4.7-10 kilohms, holds the data line HIGH. - Library use: A DHT library handles timing and checksum validation, returning temperature in degrees Celsius and humidity as percent relative humidity.
- Heat-index context: Temperature and relative humidity can be combined to estimate perceived heat, but this calculated value is not another direct sensor measurement.
- Limitations: DHT devices are slow, can return invalid
NaNreadings when sampled too quickly, and should be positioned away from self-heating electronics, condensation, and direct sunlight.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →