0% found this document useful (0 votes)
57 views55 pages

Arduino: A Brief Introduction To Modern Micro-Controllers

This document provides an introduction to Arduino microcontrollers. It discusses the history of microcontrollers from 1969 to present. It explains that Arduino makes microcontroller programming accessible by being open source, cross-platform, and allowing interaction with other software. It describes different Arduino boards and their components. It outlines how to download the Arduino IDE, connect a board, install drivers, and do basic coding including functions, data types, operators, and instructions to control pins. It provides examples of traffic light coding tasks using LEDs and timing functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views55 pages

Arduino: A Brief Introduction To Modern Micro-Controllers

This document provides an introduction to Arduino microcontrollers. It discusses the history of microcontrollers from 1969 to present. It explains that Arduino makes microcontroller programming accessible by being open source, cross-platform, and allowing interaction with other software. It describes different Arduino boards and their components. It outlines how to download the Arduino IDE, connect a board, install drivers, and do basic coding including functions, data types, operators, and instructions to control pins. It provides examples of traffic light coding tasks using LEDs and timing functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Arduino

A brief introduction to modern micro-controllers

RAMAN LAB 1
Micro-Controllers
• History:
• 1969: Four phase systems AL1.
• 1971: Intel 4004
• 2022: MARVELL 88MZ300 (SoC)

RAMAN LAB 2
Why Arduino ?
• Microcontrollers are notorious for being difficult to program
• The goal of Arduino is to create an accessible way for software developers to enter
the world of microcontroller programming
• Arduino is open source, both in its software and hardware
• Unlike most microcontroller interfaces, Arduino is cross-platform, so it can be run
on Windows, Linux, and macOS
• Arduino can interact with other software on the computer like Flash or even web
APIs

RAMAN LAB 3
Types of Arduino Boards

Arduino Nano
Arduino LilyPad Arduino Mega

Arduino UNO Arduino Mini Arduino Leonardo


RAMAN LAB 4
PWR IN USB
(to Computer)

RESET

SCL\SDA
(I2C Bus)

POWER
5V / 3.3V /
GND Digital I\O
PWM(3, 5, 6, 9,
Analog 10, 11)
INPUTS

Arduino UNO
RAMAN LAB 5
Layout of
Arduino
UNO

RAMAN LAB 6
Specifications
• Atmega328 Microcontroller:
• 32KB Flash Memory.
• 8 Bit Resolution.
• Tech Specs:
• USB Connector: USB B
• DI/DO Pins: 14
• AI Pins: 6
• PWM Pins: 6
• Communications:
• UART
• SPI
• I2C
• I/O Voltage: 5V
• Rated Supply Voltage: 7-12V
• Clock Speed:
• Main Processor: ATmega328P 16 MHz
• USB Serial Processor: ATmega16U2 16
MHz
• Memory: Atmega328p
• 2KB SRAM, 32KB FLASH, 1KB EEPROM
RAMAN LAB 7
Components
Name Image Type Function
Push Button Digital Input Switch - Closes
or opens circuit
Trim Analog Input Variable resistor
potentiometer
Photoresistor Analog Input Light Dependent
Resistor (LDR)
Relay Digital Output Switch driven by
a small signal
Temp Sensor Analog Input Temp Dependent
Resistor
Flex Sensor Analog Input Variable resistor

Soft Trimpot Analog Input Variable resistor

RGB LED Dig & Analog 16,777,216


Output different colors
RAMAN LAB 8
RAMAN LAB 9
RAMAN LAB 10
RAMAN LAB 11
DownLoad Arduino IDE
(Integrated Development Environment)

arduino.cc/en/main/software

RAMAN LAB 12
Connect Arduino to your
Computer

RAMAN LAB 13
Install Arduino Drivers

RAMAN LAB 14
Open Arduino IDE
VERIFY SERIAL
MONITOR
UPLOAD
NEW TAB
OPEN CODE GOES
SAVE HERE
BOARD &
SERIAL
PORT
SELECTIONS

RAMAN LAB 15
Settings: Tools Board

•Next, double-check that the proper board is selected under the


Tools Board menu.

RAMAN LAB 16
Settings: Tools Serial Port
•Your computer communicates
to the Arduino microcontroller
via a serial port through a
USB-Serial adapter.

•Check to make sure that the


drivers are properly installed.

RAMAN LAB 17
Basic Coding
Notebook

error & status messages

RAMAN LAB 18
Data Types:
Type Sign Byte Bits Range Other Info.
s Min Max
char signed 1 8 -128 127 ASCII
char unsigned 1 8 0 255 ASCII
byte 1 8 0 255
int(Uno+) signed 2 16 -32768 32767 Uno model +others
short 2 16 -32768 32767
int(Uno+) unsigned 2 16 0 65535 Uno model +others
word 2 16 0 65535 Same as unsigned int
long signed 4 32 -2147483648 2147483647 Append with ‘L’
Long unsigned 4 32 0 4294967295
float 4 32 -3.4028235E+38 3.4028235E+38 6-7 dec digits of
precision
double (Uno+) 4 32 -3.4028235E+38 3.4028235E+38 Same as float

RAMAN LAB 19
Commonly used operators:
• Sum: + • AND: &&
• Product: * • OR: ||
• Division: / • NOT: !
• Subtraction: - • Equal to: ==
• Modulo: % • Greater than: >
• Exponent: ^ • Less than: <
• Greater than equal to: >=
• Less than equal to: <=
• Not Equal to: !=

RAMAN LAB 20
Basic Coding
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. RAMAN LAB 21
pinMode()
• Instruction used to set the mode (INPUT or
OUTPUT) in which we are going to use a pin.
• E.g.: pinMode (13, OUTPUT);
• i.e. setting pin13 as output.

digitalWrite()
• Write a HIGH or a LOW value to a digital pin.
• E.g.: digitalWrite (11, HIGH);
• i.e. setting pin 11 to high.

RAMAN LAB 22
digitalRead()
• Reads the value from a specified digital pin,
either HIGH or LOW
• E.g.: 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.
• E.g.: delay(1000);
• ie. waits for a second (1000 ms = 1 s)
RAMAN LAB 23
Setup
The setup section is used for assigning input and outputs
(Examples: motors, LED’s, sensors etc) to ports on the Arduino
To do this we use the command “pinMode”

void setup() {
port #

pinMode(9, OUTPUT);
Input or Output
}
RAMAN LAB 24
Loop
void loop() { Port # from setup

digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(1000);
Turn the LED on
or off
} Wait for 1 second
or 1000 milliseconds
RAMAN LAB 25
RAMAN LAB 26
TASK 1
• Using 3 LED’s (red, yellow and green) build a traffic light that
• Illuminates the green LED for 5 seconds
• Illuminates the yellow LED for 2 seconds
• Illuminates the red LED for 5 seconds
• repeats the sequence
• Note that after each illumination period the LED is turned off!

TASK 2
• Modify Task 1 to have an advanced green (blinking green LED) for 3
seconds before illuminating the green LED for 5 seconds

RAMAN LAB 27
Control Structure & Loop
If conditioning: Switch case: while(expression)
{ Block of statements; }
if(condition) switch(var)
{ {
Statement-1 Case 1:
…. // do something when var equal to
do { Block of statements; }
Statement-N 1
while (expression);
break;
}
else if(condition) Case 2:
{ // do something when var equal to for ( initialize; control; increment or decrement)
Statement 2 { // statement block }
} break;
else{Statement}
default:
//if nothing else matches, do the
default
//default is optional
RAMAN LAB 28
}
Practical Hands On

RAMAN LAB 29
Circuit #1:
Blinking an LED
LEDs (light emitting
diodes) are small,
powerful lights used in
many different
applications.

RAMAN LAB 30
Resistor Color Code

RAMAN LAB 31
Circuit Schematic
Pin 13 is a digital pin and can be used as an
output or an input. Here we will use it to
output power to the LED.

Pin 13 will be connected to


the positive lead on the LED.

The negative lead on the


LED will be connected to
one leg of the resistor.

The other leg of the resistor


will be connected to ground
to complete the circuit.
Note: These components are all in series (one
after the LAB
RAMAN other, like beads on a string). 32
Design it!

RAMAN LAB 33
RAMAN LAB 34
Create the Sketch
/*
Blink
Turns on an LED for one second then off for one second, repeatedly.
*/
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
} RAMAN LAB 35
Circuit #2: Potentiometer
How to read analog input from the physical world
using a potentiometer (“pot” for short) and control
the blink rate of an LED. We’ll also learn how to use
the serial monitor to watch how the voltage changes.

When it’s connected with 5V across its two outer


pins, the middle pin outputs a voltage between 0 and +5V
5V, depending on the position of the knob. In this
way, it can be used as a “voltage divider”.
Analog
Input
GND

RAMAN LAB 36
Circuit Schematic

We’re adding a
potentiometer to
control the blink rate
of the LED.

We’re running 5V across the


outer pins of the pot. The
middle pin of the potentiometer
will be connected to analog
input pin 0.

RAMAN LAB 37
Design it!

RAMAN LAB 38
RAMAN LAB 39
Create the Sketch
int sensorPin =0;
int ledPin =13;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
int sensorValue;
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH);
delay(sensorValue);
digitalWrite(ledPin, LOW);
delay(sensorValue);
Serial.println(sensorValue);
} RAMAN LAB 40
Circuit #3
Photo Resistor (Light Sensor)
• Photoresistors change resistance based on
how much light the sensor receives.
• Use our photo resistor in a “voltage
divider” configuration. Output:
• High voltage = lot of light
• Low voltage = little light

• Brighten and dim an LED based on the


light level picked up by the photo resistor.

RAMAN LAB 41
Resistive Sensors & Voltage Dividers
Resistor in disguise!
• Arduino measures voltage, not
resistance. Need a voltage divider:
• Consists of two resistors.
Top resistor
• The “top” resistor is the sensor.
• The “bottom” resistor is a
normal, fixed resistor (usually 10
KΩ). Bottom resistor

When top resistor is connected to 5V and the bottom


resistor to ground, the middle will output a voltage
proportional to the values of the two resistors.

RAMAN LAB 42
Pulse Width Modulation (PWM)
• Arduino is so fast it can blink a pin on and off 1,000 times per second.
• PWM pins also vary amount of time blinking pin spends on HIGH vs.
LOW.

• Use function: analogWrite(pin, value)


• Choose a pin marked by a ~
• Value is the duty cycle
• 0 = always OFF
• 255 = always ON
• 127 = on HALF the time
(50% duty cycle)

RAMAN LAB 43
Pulse Width Modulation (PWM)

10% duty cycle

50% duty cycle

90% duty cycle

RAMAN LAB 44
Circuit Schematic
The left side of the schematic is
almost the same as the previous
circuits. What’s changed?

RAMAN LAB 45
Design it!

RAMAN LAB 46
RAMAN LAB 47
Create the Sketch
const int sensorPin=0;
const int ledPin=9;
int lightLevel, high=0, low=1023;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
lightLevel = analogRead(sensorPin);
autoTune();
analogWrite(ledPin, lightLevel);
Serial.println(lightLevel);
} RAMAN LAB 48
Create the Sketch
void autoTune()
{
if(lightLevel<low)
{
low=lightLevel;
}
if(lightLevel>high)
{
high=lightLevel;
}
lightLevel=map(lightLevel, low+30, high-30, 0, 255);
lightLevel=constrain(lightLevel, 0, 255);
} RAMAN LAB 49
Circuit #4:
Temperature Sensor
• Temperature sensors are used to measure
ambient temperature.

• Sensor we’re using has three pins – positive,


ground, and a signal. For every centigrade
degree it reads, it outputs 10 millivolts.

• We’ll integrate the temperature sensor with


Arduino and use the serial monitor to display
the temperature.

RAMAN LAB 50
Circuit Schematic

RAMAN LAB 51
Design it!

RAMAN LAB 52
RAMAN LAB 53
Create the Sketch
const int temperaturePin = 0;
void setup() {
Serial.begin(9600); float getVoltage(int pin)

}void loop() { {
float voltage, degreesC, degreesF;
return(analogRead(pin) *
voltage = getVoltage(temperaturePin);
0.004882814);
degreesC = (voltage - 0.5) * 100.0;
degreesF = degreesC * (9.0/5.0) + }
32.0;
Serial.print("voltage: ");
Serial.print(voltage);
Serial.print(" deg C: ");
Serial.print(degreesC);
Serial.print(" deg F: ");
Serial.println(degreesF);
RAMAN LAB 54
delay(1000);}
RAMAN LAB 55

You might also like