Programming with IoT
Topic: Arduino Simulation Environment
Unit 2: Arduino Simulation Environment:
⮚ Arduino Uno basics
⮚ Its architecture
⮚ Pin configuration
⮚ Setup the Arduino IDE
⮚ Arduino libraries
⮚ Communication Protocols
⮚ Sketches for Arduino, sketch description
⮚ Introduction to TinkerCad, creating TinkerCad
account
What is a Microcontroller
• A small computer on a single chip
• containing a processor, memory, and input/output
• Typically "embedded" inside some device that they control
• A microcontroller is often small and low cost
What is a Development Board
• A printed circuit
board designed to
facilitate work with a
particular
microcontroller.
• Typical components include:
• power circuit
• programming interface
• basic input; usually buttons and LEDs
• I/O pins
The Arduino Development Board
Arduino Uno
• Arduino Uno is a microcontroller board based on
the ATmega328P.
Arduino Uno
• It's a "mini-system" based on an AVR. AVR stands for Alf
and Vegard’s Risc processor, named after its creators, Alf-
Egil Bogen and Vegard Wollan.
• It’s a family of microcontrollers developed by Atmel
Corporation
• Open source software.
• Hardware abstracted programming language.
• Arduino Uno is a "development board" rather than a
microcontroller.
• It is a versatile board for beginners.
ARDUINO UNO
ARDUINO UNO
Arduino Microcontroller: Pin
configuration
Arduino Microcontroller
How to power on Arduino ?
Barrel Jack Adaptor: 9V, 1A
Voltage Regulator
The 5V supply is
produced by a low
drop-out (LDO)
voltage regulator.
Voltage regulators
take in input, step
it down and give
stable DC output.
Power Pins
❑ VIN: The input voltage to the Arduino
board when it's using an external power
❑ 5V: The regulated power supply used to
power the microcontroller and other
components on the board. This can
come either from VIN via an on-board
regulator, or be supplied by USB or
another regulated 5V supply.
❑ 3V3: A 3.3 volt supply generated by the
on-board FTDI chip.
❑ GND. Ground pins.
Analog and Digital Pins
Analog pins: A0 – A5
Digital Pins: 0-13
17
Analog and Digital Pins
1. Digital I/O Pins:
1. It has 14 digital input/output pins, with 6 of them supporting PWM output.
2. It can be used for general purpose input and output via the pinMode(),
digitalRead(), and digitalWrite() commands.
3. 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.
4. The maximum current per pin is 40 mA.
5. These pins allow you to connect various sensors, actuators, and other
components.
2. Analog Inputs:
1. There are 6 analog input pins, useful for reading data from sensors like
temperature sensors and potentiometers.
2. The analog input pins support 10-bit analog-to-digital conversion (ADC) using
the analogRead() function.
3. I2C Communication:
4 (SDA) and 5 (SCL) and uses wire Library.
18
Other Digital Pins
• Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL
serial data. (UART Communication)
• 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.
• 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.
• 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. (SPI
Communication)
• LED: 13. Builtin LED, When the pin is HIGH value, the LED is on, when
the pin is LOW, it's off.
19
Reset
Reset
button
External
Reset
option
As restart button in your PC restarts the system. In the same manner reset
button restart the Arduino. It means that the program memory ROM set to
the starting position or address. Your code starts from the beginning, and
hardware resets.
Clock signal
• Crystal oscillator soldered
on Arduino development
board provide a clock signal
to microcontroller Atmega
328 .
• This provides a square wave
signal which determine the
time required for each T
state.
• As in general Arduino board
has 16Mhz frequency
crystal hence takes 1/16
micro-sec to run 1 T state.
Memory
1. Flash Memory (Program Space):
1. The Arduino sketch (code) is stored in Flash memory.
2. Flash memory is non-volatile, meaning it retains data even when the
system is powered off.
3. The Uno has 32 KB of Flash memory for storing your programs.
2. SRAM (Static Random Access Memory):
1. SRAM is where sketch creates and manipulates variables during
runtime.
2. It’s volatile, so data is lost when the system is turned off.
3. It has 2 KB of SRAM (volatile memory) for temporary storage.
3. EEPROM (Electrically Erasable Programmable Read-Only Memory):
1. EEPROM is a special type of memory that programmers can use to
store long-term information.
2. It’s also non-volatile and retains data even after power loss.
3. It has 1 KB of EEPROM (non-volatile memory).
Other Component
FTDI chip on
FTDI Chip
Arduino boards that
have a USB
connector. It's used to
handle the USB
communications on
one side, and TTL
serial communications
on the other. The serial
pins from the chip are
mapped to the UART
on the AVR chip, and
in turn they appear on
the pin headers for
easy connections
Arduino
• Arduino is a great tool for collecting data.
• An Arduino can collect data from sensors, store it, and
send it to another device for further analysis.
• Use sensors to record data from the environment.
• Analyse the collected data.
• Draw conclusions from the data by visualizing data and taking
decisions.
Arduino IDE
Arduino is an electronic prototyping platform.
IDE software that
runs on your
Microcontroller
computer
(physical circuit
(Integrated
board)
Development
Environment)
Arduino IDE
• The Arduino IDE (Integrated Development Environment) is a
powerful tool for writing and uploading code to Arduino boards.
• Arduino Cloud Editor allows you to save sketches in the cloud,
accessible from any device. Available at: www.arduino.cc
Digital Communication protocol
Digital communication in the context of Arduino involves establishing connections between
devices using various protocols.
1. Universal Asynchronous Receiver-Transmitter (UART):
• UART is a widely used serial communication protocol for sending data between an
Arduino board and other devices.
• It allows asynchronous communication, where data format and transmission speed are
configurable.
• The default TX/RX pins on an Arduino board are D0 (RX) and D1 (TX).
2. Serial Peripheral Interface (SPI):
• SPI is a synchronous protocol for high-speed communication between microcontrollers
and peripherals.
• It requires four wires: SCK (Serial Clock), MOSI (Master Out Slave In), MISO (Master In
Slave Out), and SS (Slave Select).
• SPI.h library simplifies SPI communication.
3. Inter-Integrated Circuit (I2C):
• I2C allows connecting multiple peripheral devices (sensors, displays, etc.) with minimal
wiring.
Arduino Libraries
Arduino libraries are essential for extending the functionality of Arduino
sketches. They provide pre-written code that allow to interact with
external modules and boards. Common Libraries:
1. Standard Libraries: These come pre-installed with the Arduino IDE
For eg Servo: For controlling servo motors
2. Contributed Libraries: The Arduino IDE features a Library Manager
that facilitates installing third-party libraries submitted to Arduino.
3. Communication protocol Libraries:
• SPI: Communicates with devices using the Serial Peripheral
Interface (SPI) Bus.
• Wire (I2C): Sends and receives data over a network of devices or
sensors.
• SoftwareSerial: Enables serial communication on any digital pins.
Arduino Libraries
4. Connectivity Libraries
• WiFi, WiFi101, WiFiNINA: Libraries for Internet connections
via Wi-Fi.
• Ethernet: Connects to the Internet via Ethernet.
• ArduinoBLE: For Bluetooth Low Energy connectivity.
• MKRWAN, MKRGSM, MKRNB, SigFox: Libraries for various
IoT connectivity options.
• ArduinoIoTCloud: connects to Arduino cloud
5. Embedded sensors Libraries:
• ArduinoAPDS9960: Gesture, color, ambience illumination, and
proximity sensor.
• Arduino_LSM6DS3, Arduino_LSM9DS1, Arduino_LSM6DSOX:
IMUs (6-axis and 9-axis).
• ArduinoLPS22HB: Barometer and temperature sensor.
Getting started
1. Download & install the Arduino environment (IDE) from www.arduino.cc
2. Connect the board to your computer via the UBS cable
3. If needed, install the drivers
4. Launch the Arduino IDE
5. Select your board
6. Select your serial port
7. Open the blink example
8. Upload the program
Arduino Sketch
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run
repeatedly:
}
• setup : called only when the Arduino is powered on or reset. It is
used to initialize values.
• loop : runs continuously till the device is powered off. The main
logic of the code goes here.
• Arduino programs (sketches) are written in IDE and saved
with .ino extension
‘loop’ in sketch
• Example:
You want to sense the air temperature every minute.
Sequence of instructions:
START-> sense air temperature (TIME = 10:00:00)
• Wait one minute
• sense air temperature(TIME = 10:01:00)
• Wait one minute
• sense air temperature (TIME = 10:02:00)
• Wait one minute
• sense air temperature(TIME = 10:03:00)
• Wait one minute
• sense air temperature(TIME = 10:04:00)
• Wait one minute
• ……..
Arduino Pin Mode
• A pin on arduino can be set as
input or output by using
pinMode function.
• pinMode(13, OUTPUT); // sets Pass instructions to
an actuator
pin 13 as output pin
connected to pin 13
• pinMode(13, INPUT); // sets
pin 13 as input pin Take data from a
sensor connected to
33
pin 13
Arduino Constants
• Arduino constants are pre-defined values that never
change.
• Pin modes: INPUT, OUTPUT
Changing a pin with pinMode() changes the electrical behavior of the pin.
• Pin levels: HIGH & LOW
• built-ins: LED_BUILTIN
Most Arduino boards have a pin connected to an on-board LED in series with a resistor. The constant LED_BUILTIN is the
number of the pin to which the on-board LED is connected. Most boards have this LED connected to digital pin 13.
Writing digital values
• digitalWrite(13, HIGH); // Makes the output voltage
on pin 13 , 5V
• digitalWrite(13, LOW); // Makes the output voltage
on pin 13 , 0V
TinkerCad
www.tinkercad.com
Create TinkerCad Account
TinkerCad Circuit Designs
Arduino on TinkerCad
To Glow Built in LED
• Arduino introduction: https://www.youtube.com/watch?v=nL34zDTPkcs
• Arduino pins:
https://www.youtube.com/watch?v=Se2WXK98P2c&list=PLVl__93X7ZlxnDtEY1_ibH-fECYEAKAQC