EIOT Unit-3
EIOT Unit-3
Year/Semester : III/VI
UNIT-III
IoT and Arduino Programming
Introduction to the Concept of IoT Devices - IoT Devices Versus Computers - IoT Configurations -
Components Introduction to Arduino Types of Arduino Arduino Toolchain - Arduino Programming
Structure - Sketches-Pins - Input/Output from Pins Using Sketches - Introduction to Ano Shields-
Integration of Sensors and Actuators with Arduino.
Digital pins
In addition to the specific functions listed below, the digital pins on an Arduino board can be used
for general purpose input and output via the pinMode(), digitalRead(), and digitalWrite()
commands.
Each pin has an internal pull-up resistor which can be turned on and off using digitalWrite(), when
the pin is configured as an input. The maximum current per pin is 40 mA.
Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. On the
Arduino Diecimila, these pins are connected to the corresponding pins of the FTDI USB-to-TTL
Serial chip. On the Arduino BT, they are connected to the corresponding pins of the WT11
Bluetooth module. On the Arduino Mini and LilyPad Arduino, they are intended for use with an
external TTL serial module (e.g. the Mini-USB Adapter).
External interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low value,
a rising or falling edge, or a change in value. See the attachInterrupt() function for details.
PWM : 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function. On
boards with an ATmega8, PWM output is available only on pins 9, 10, and 11.
BT reset: 7. (Arduino BT-only) Connected to the reset line of the bluetooth module.
SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication, which,
although provided by the underlying hardware, is not currently included in the Arduino language.
LED: 13. On the Diecimila and LilyPad, there is a built-in LED connected to digital pin 13. When
the pin is HIGH value, the LED is on, when the pin is LOW, it's off.
Analog pins
In addition to the specific functions listed below, the analog input pins support 10-bit analog-to-
digital conversion (ADC) using the analogRead() function.
Most of the analog inputs can also be used as digital pins: analog input 0 as digital pin 14 through
analog input 5 as digital pin 19. Analog inputs 6 and 7 (present on the Mini and BT) cannot be used
as digital pins.
I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication.
Power pins
VIN (sometimes labelled "9 V"). The input voltage to the Arduino board when it's using an
external power source.
You can supply voltage through this pin, or, if supplying voltage via the power jack, access it
through this pin. Note that different boards accept different input voltages ranges, please see the
documentation for your board. Also note that the LilyPad has no VIN pin and accepts only a
regulated input.
3.5.2 Pins
To use the Arduino pins, you need to define which pin is being used and its functionality. A
convenient way to define the used pins is by using:
define pinName pinNumber' #
The functionality is either input or output and is defined by using the pinMode() method in the
setup section.
The pins on the Arduino can be configured as either inputs or outputs. Arduino (Atmega) pins
default to inputs, so they don't need to be explicitly declared as inputs with pinMode() when we are
using them as inputs.
Pins configured this way are said to be in a high-impedance state. Input pins make extremely small
demands on the circuit that they are sampling, equivalent to a series resistor of 100 M2 in front of
the pin.
This means that it takes very little current to move the input pin from one state to another and can
make the pins useful for such tasks as implementing a capacitive touch sensor, reading an LED as a
photodiode, or reading an analog sensor with a scheme such as RCTime.
}
void loop() // The loop function runs again and again
{
digitalWrite (LED, HIGH); //Tum ON the LED
delay(1000); //Wait for 1 sec
Prepared by :T.Manochandar, AP/ECE
digitalRead (LED, LOW); // Tum off the LED
delay(1000); // Wait for 1 sec
}
Here, LED is declared globally and is set to pin number 13. This will reduce the number of
iterations required to update the pin number in the program when we connect the LED to the other
digital pin.
A pin on Arduino can be set as input or output by using pinMode function.
pinMode(13, OUTPUT); // sets pin 13 as output pin
pinMode(13, INPUT); // sets pin 13 as input pin
Reading/Writing digital values
digitalWrite(13, LOW); // Makes the output voltage on pin 13, 0 V
digitalWrite(13, HIGH); // Makes the output voltage on pin 13, 5 V
intbuttonState-digitalRead(2); // reads the value of pin 2 in buttonState
A component of a machine that is responsible for A device that detects events or changes in the
moving and controlling mechanism. environment and send that information to another
electronic device.
It helps to control the environment or physical It helps to monitor the changes in the
changes. environment.