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

Introduction To Arduino Environment and Sensors

Uploaded by

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

Introduction To Arduino Environment and Sensors

Uploaded by

sampreeti sahana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Introduction to IoT: Hands-on Session 2

IoT Architecture (Recap)

Source: https://www.zibtek.com/blog/iot-architecture/ 2
CONTENTS

● Arduino commands to configure I/O direction and


data
● Basic connections on breadboard
● Digital output
● Digital Read
● Analog Read
● Introduction to sensors
Arduino commands to configure I/O direction and
data

pinMode()
Syntax: pinmode(pin,mode)
Parameters:
pin: the esp32 pin number to set mode of
mode: INPUT,OUTPUT
Basic connections on breadboard
Digital Output
Hardware Required
● NodeMCU ESP-32S
● Breadboard
● LED
● 220 Ω resistor
● Connecting wires

Steps
1. Connect the positive (longer) pin of the LED to the pin D5 on ESP32 and the other end to one
end of the resistor.
2. Connect the other end of the resistor to the Ground Pin on ESP32.
3. Watch the LED and the Serial Monitor.
Image source:https://esp32io.com/tutorials/esp32-led-blink
analogRead()
Syntax

analogRead(pin)

Parameters

pin: the name of the analog input pin to read from.

Returns

The analog reading on the pin. Although it is limited to the resolution of the analog to digital converter
(0-1023 for 10 bits or 0-4095 for 12 bits). Data type: int.
Example Code

The code reads the voltage on analogPin and displays it.

int analogPin = 34; // potentiometer wiper (middle terminal) connected to analog pin 3
// outside leads to ground and +5V
int val = 0; // variable to store the value read

void setup() {
Serial.begin(9600); // setup serial
}

void loop() {
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
}
Introduction to Sensors
A sensor is a device that produces an output signal for the purpose of detecting a physical phenomenon

zz.

Image Source: https://www.electricaltechnology.org/2018/11/types-sensors-applications.html


Analog and Digital Sensors

Feature Analog Sensors Digital Sensors

Signal Type Continuous range of values Discrete binary values (0 or


1)

Output Range Typically 0 to 1023 (for a Either 0 (LOW) or 1 (HIGH)


10-bit ADC)

Voltage Range Varies within the operating Typically 0V (LOW) or


voltage (e.g., 0V to 5V) operating voltage 5V/3.3V
(HIGH)

Examples LDR (Light Dependent DHT11 (Temperature &


Resistor), Potentiometer, Humidity), HC-SR04
Thermistor (Ultrasonic Distance), Push
Button
Feature Analog Sensors Digital Sensors

Microcontroller Functions analogRead(pin): Reads the digitalRead(pin): Reads


analog value from a pin (returns the digital value from a pin
a value between 0 and 1023 for (returns 0 or 1).
a 10-bit ADC). digitalWrite(pin, value):
analogWrite(pin, value): Sets a digital pin to either HIGH
Outputs a PWM (Pulse Width (1) or LOW (0).
Modulation) signal to simulate an
analog output.

ADC Requirement Requires ADC to convert the No ADC needed, as the sensor
analog signal into a digital value output is already in digital form.
the microcontroller can
understand.

Precision Can measure a wide range of Provides simple, binary


values with finer precision. information (e.g., ON/OFF,
detected/not detected).

Use Cases Ideal for measuring varying Ideal for detecting states like
quantities like light intensity, presence/absence, button press,
temperature, and sound levels. or distance measurement.
1. Introduction to LDRs
● What is an LDR?
○ LDR stands for Light Dependent Resistor, also known as a Photoresistor or PhotoCell.
○ It is an electronic component that changes its resistance based on the light intensity it
detects.

2. How LDRs Work


● Light Sensitivity:
○ LDRs are made from semiconductor materials that are sensitive to light.
○ In darkness, the resistance is very high (up to several megaohms).
○ In bright light, the resistance drops significantly (close to zero).
● Basic Principle:
○ When light hits the LDR, it frees up electrons in the semiconductor, reducing resistance
and allowing more current to pass through.
3. Application of LDRs
● Where to Use LDRs:
○ LDRs can be used in projects to detect the presence or absence of light.
○ Common applications include automatic street lights, light-sensitive alarms, and
brightness control in displays.

4. Working with Microcontrollers


● Connecting to Microcontrollers:
○ LDRs produce an analog signal that represents light intensity.
○ To read this signal using a microcontroller, an Analog to Digital Converter (ADC) is
needed.
○ Most modern microcontrollers, like Arduino or ESP32, come with built-in ADC pins,
making it easy to read LDR data.
Light Dependent Resistor(LDR) interfacing with ESP32

Image Source: https://www.donskytech.com/wp-content/uploads/2022/03/esp32-ldr-wiring-1.png


Code
#define LDR_Pin A0 void loop()
int LDR_Value = 0; {
LDR_Value = analogRead(LDR_Pin);
void setup() Serial.println(LDR_Value);
{ delay(100);
Serial.begin(115200); }
}

You might also like