Unit 3-cs3691
Unit 3-cs3691
Programming
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Arduino Introduction
Embedded Systems
Arduino Basics
Arduino Architecture
Arduino board layout. What are the resources available
Arduino IDE
Programming fundamentals
Learn by Doing – Sense, Control & Actuate
Project 1: LED Blinking
Project 2: RGB LED Interfacing & PWM Control
Project 3: Interfacing Sensors (Light, Temperature, etc.,)
Project 4: Interfacing Actuators (Motor Speed Control using PWM)
27
Industry / Robot / System
Industry /
System
28
Embedded Systems
29
Components of Embedded Systems
Communication
Power Supply Processor Memory Timers & Counters
Ports
••Stable
UART
Power
Speed Supply Output
& Smooth ••Load
RS-232
Number of I/O–Pins
Regulation Fluctuation in output voltage when
•••Proper
CAN
Processor
Read-Only
UnitOutput
Price memory(RAM)
Assembler Current to Drive the Load ••load
RS-423
Power Consumption
current changes
••Perfect
SPI
Display
Random
Packaging
Emulator Device
PowerAccess Memory(ROM)
Efficiency •Efficiency
RS-485
Amount of RAM and ROM
••Stable
Buzzer
I2C
Debugger for Alert
Electrically
Performance Erasable
in Different Programmable
Temperature Range Read-Only •Input/Output
SpecializedRipple
UART Processing Units
Voltage
•••Proper
Device
Memory
Compiler
USB Drivers
Peripheral
Noise(EEPROM)
Set
Filtering ••Transient
Architecture
I2C 8-bit, 16-bit, or 32-bit
Response
••Proper
MEMS
Timer
Ethernet devices
on the Chip
Decoupling •Allowable
SPI Dissipation
•Line
Operating Voltage
Regulation changes
30
Why Arduino..?
31
Arduino Basics
arduino ( arrr- dween -oh )
32
Types of Arduino Boards
Arduino Nano
Arduino Mega
Arduino LilyPad
Arduino Uno
Arduino Mini Arduino Leonardo
33
Arduino Uno
Digital pins:
14 digital IO pins
6 are PWM pins (3, 5, 6, 9, 10, and 11).
Analog pins:
6 analog pins(A0, A1, A2, A3, A4, and A5)
Takes analog values as an input
34
35
Arduino IDE
VERIFY SERIAL
MONITOR
UPLOAD
NEW TAB
OPEN CODE GOES
SAVE HERE
BOARD &
SERIAL PORT
SELECTIONS
36
Arduino ESP32 – IoT application
37
ESP32 is the SoC (System on Chip) microcontroller which
has gained massive popularity recently. Whether the
popularity of ESP32 grew because of the growth of IoT or
whether IoT grew because of the introduction of ESP32 is
debatable
38
39
40
Basic Coding
structure
41
Settings: Tools Serial Port
42
Settings: Tools Board
44
45
46
47
To choose desired version
48
Basic Coding structure
setup() function
•Called when a sketch starts.
•To initialize variables, pin modes, start using libraries, etc.
•Will only run once, after each power-up or reset of the
Arduino board.
loop() function
•Loops consecutively.
•Code in the loop() section of the sketch is used to actively
control the Arduino board.
Commenting
•Any line that starts with two slashes (//) will not be read by
the compiler, so you can write anything you want after it.
49
pinMode()
Instruction used to set the mode (INPUT or OUTPUT) in
which we are going to use a pin.
Eg: pinMode (13, OUTPUT);
ie. setting pin13 as output.
digitalWrite()
•Write a HIGH or a LOW value to a digital pin.
•Eg: digitalWrite (11, HIGH);
•ie. setting pin 11 to high.
50
digitalRead()
•Reads the value from a specified digital pin,
either HIGH or LOW
•Eg: int inPin=7;
val = digitalRead(inPin);
•ie. reads the value from inPin and assigns it to val.
delay()
•Pauses the program for the amount of time (in milliseconds)
specified as parameter.
•Eg: delay(1000);
•ie. waits for a second (1000 ms = 1 s)
51
Arduino data types and constants.
Constants
• Floating Point Constants
• HIGH / LOW – High 5V/3.3V & Low – 1.5V / 1.0V
• INPUT/ INPUT_PULLUP/OUTPUT - pinmode
• Integer Constants
• LED_BUILTIN – inbuilt LED connected to Arduino board- mostly pin 13
• true | false - True – logic High , False – Logic Low
52
Data Types
•Array Conversion
•Bool • (unsigned int)
•Byte • (unsigned long)
•Char • byte()
•Double • char()
•Float • float()
•Int • int()
•Long • long()
•Short • word()
•size_t
•String
•String()
•unsigned char
•unsigned int
•unsigned long
•Void
•word
53
54
55
56
57
58
Component List
Arduino Uno
USB cable
LED, RGB LED
LDR
POT(10k)
Resistors
Temp sensor LM-35
Motor Driver L293D, DC Motor
Connecting wire
59
LED Blink
60
Digital Read
61
Analog Read
62
LDR (Light Dependent Resistor)
63
LDR - Wiring
64
TEMP Sensor-LM35
65
66
DC Motor Drive – L293D
Motor Driver Circuit (L293D)
The L293 and L293D devices are quadruple high
current half-H drivers.
67
L293D Functional
Block Diagram
68
69
DC Motor Control
using L293D
70
RGB LED
Vcc
Green
Red Blue
71
Program to interface stepper motor with Arduino
72
Program to interface Temperature sensor and LCD display with Arduino
73
Program to control LED based on LDR sensor value using Arduino
74