Introduction To Arduino Environment and Sensors
Introduction To Arduino Environment and Sensors
Source: https://www.zibtek.com/blog/iot-architecture/ 2
CONTENTS
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
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
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.
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.
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.