0% found this document useful (0 votes)
3 views8 pages

expermant-1Emb.Sys. Arduino Arch.

The document provides an overview of the Arduino microcontroller, detailing its hardware features, power options, and various components such as the voltage regulator, crystal oscillator, and input/output pins. It explains essential functions in Arduino programming, including setup(), loop(), pinMode(), and digitalWrite(), with example code for each. The document emphasizes the importance of structuring code into functions for better organization and reusability.

Uploaded by

khansaa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
3 views8 pages

expermant-1Emb.Sys. Arduino Arch.

The document provides an overview of the Arduino microcontroller, detailing its hardware features, power options, and various components such as the voltage regulator, crystal oscillator, and input/output pins. It explains essential functions in Arduino programming, including setup(), loop(), pinMode(), and digitalWrite(), with example code for each. The document emphasizes the importance of structuring code into functions for better organization and reusability.

Uploaded by

khansaa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

Syste Engineeringn Departmentet

Embedded System Lab


LAB-2
Arduino
Arduino is a single-board microcontroller meant to make the application more accessible
which are interactive objects and its surroundings. The hardware features with an open-
source hardware board designed around an 8-bit Atmel AVR microcontroller or a 32-bit
Atmel ARM. Current models consists a USB interface, 6 analog input pins and 14 digital I/O
pins that allows the user to attach various extension boards.

internal connection of 7-segment display

1 Power USB
Arduino board can be powered by using the USB cable from your computer. All you need to
do is connect the USB cable to the USB connection (1).
2 Power (Barrel Jack)
Arduino boards can be powered directly from the AC mains power supply by connecting
it to the Barrel Jack (2).
3 Voltage Regulator
The function of the voltage regulator is to control the voltage given to the Arduino board
and stabilize the DC voltages used by the processor and other elements.

4 Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time issues. How does Arduino
calculate time? The answer is, by using the crystal oscillator. The number printed on top
of the Arduino crystal is 16.000H9H. It tells us that the frequency is 16,000,000 Hertz or
16 MHz.
5, 17 Arduino Reset
You can reset your Arduino board, i.e., start your program from the beginning. You can
reset the UNO board in two ways. First, by using the reset button (17) on the board.
Second, you can connect an external reset button to the Arduino pin labelled RESET (5).

6, 7, 8, 9 Pins (3.3, 5, GND, Vin)


- 3.3V (6) − Supply 3.3 output volt
- 5V (7) − Supply 5 output volt
- Most of the components used with Arduino board works fine with 3.3 volt and 5 volt.
- GND (8)(Ground) − There are several GND pins on the Arduino, any of which can be
used to ground your circuit.
- Vin (9) − This pin also can be used to power the Arduino board from an external power
source, like AC mains power supply.

10 Analog pins
The Arduino UNO board has six analog input pins A0 through A5. These pins can read the
signal from an analog sensor like the humidity sensor or temperature sensor and convert it
into a digital value that can be read by the microprocessor.

11 Main microcontroller
Each Arduino board has its own microcontroller (11). You can assume it as the brain of your
board. The main IC (integrated circuit) on the Arduino is slightly different from board to
board. The microcontrollers are usually of the ATMEL Company. You must know what IC your
board has before loading up a new program from the Arduino IDE. This information is
available on the top of the IC. For more details about the IC construction and functions, you
can refer to the data sheet.

12 ICSP pin
Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino consisting of MOSI,
MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI (Serial Peripheral Interface),
which could be considered as an "expansion" of the output. Actually, you are slaving the
output device to the master of the SPI bus.

13 Power LED indicator


This LED should light up when you plug your Arduino into a power source to indicate that
your board is powered up correctly. If this light does not turn on, then there is something
wrong with the connection.

14 TX and RX LEDs
On your board, you will find two labels: TX (transmit) and RX (receive). They appear in two
places on the Arduino UNO board. First, at the digital pins 0 and 1, to indicate the pins
responsible for serial communication. Second, the TX and RX led (13). The TX led flashes with
different speed while sending the serial data. The speed of flashing depends on the baud
rate used by the board. RX flashes during the receiving process.
15 Digital I/O
The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide PWM (Pulse Width
Modulation) output. These pins can be configured to work as input digital pins to read logic
values (0 or 1) or as digital output pins to drive different modules like LEDs, relays, etc.

16 AREF
AREF stands for Analog Reference. It is sometimes, used to set an external reference voltage
(between 0 and 5 Volts) as the upper limit for the analog input pins.
Functions
allow structuring the programs in segments of code to perform individual tasks. The typical
case for creating a function is when one needs to perform the same action multiple times in
a program.
Standardizing code fragments into functions has several advantages −
 Functions help the programmer stay organized. Often this helps to conceptualize the
program.
 Functions codify one action in one place so that the function only has to be thought
about and debugged once.
 This also reduces chances for errors in modification, if the code needs to be changed.
 Functions make the whole sketch smaller and more compact because sections of code
are reused many times.
 They make it easier to reuse code in other programs by making it modular, and using
functions often makes the code more readable.
There are two required functions in an Arduino sketch or a program i.e. setup () and loop().
Other functions must be created outside the brackets of these two functions.
The most common syntax to define a function is −
setup()
Description

The setup() function is called when a sketch starts. Use it to initialize variables, pin
modes, start using libraries, etc. The setup() function will only run once, after each
powerup or reset of the Arduino board.

Example Code
int buttonPin = 3;

void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}

void loop() {
// ...
}

loop()
Description

After creating a setup() function, which initializes and sets the initial values,
the loop() function does precisely what its name suggests, and loops consecutively, allowing
your program to change and respond. Use it to actively control the Arduino board.

Example Code
int buttonPin = 3;

// setup initializes serial and the button pin


void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}

// loop checks the button pin each time,


// and will send serial if it is pressed
void loop() {
if (digitalRead(buttonPin) == HIGH) {
Serial.write('H');
}
else {
Serial.write('L');
}

delay(1000);
}
pinMode() Function
Description
The pinMode() function is used to configure a specific pin to behave either as an input or an
output. It is possible to enable the internal pull-up resistors with the mode INPUT_PULLUP.
Additionally, the INPUT mode explicitly disables the internal pull-ups.
pinMode() Function Syntax
Void setup () {
pinMode (pin , mode);
}
 pin − the number of the pin whose mode you wish to set
 mode − INPUT, OUTPUT, or INPUT_PULLUP.
Example

int button = 5 ; // button connected to pin 5


int LED = 6; // LED connected to pin 6

void setup () {
pinMode(button , INPUT_PULLUP);
// set the digital pin as input with pull-up resistor
pinMode(button , OUTPUT); // set the digital pin as output
}

void setup () {
If (digitalRead(button ) == LOW) // if button pressed {
digitalWrite(LED,HIGH); // turn on led
delay(500); // delay for 500 ms
digitalWrite(LED,LOW); // turn off led
delay(500); // delay for 500 ms
}
}

digitalWrite()
[Digital I/O]

Description

Write a HIGH or a LOW value to a digital pin.

If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the
corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.

If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable


(LOW) the internal pullup on the input pin. It is recommended to set
the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor.

If you do not set the pinMode() to OUTPUT, and connect an LED to a pin, when
calling digitalWrite(HIGH), the LED may appear dim. Without explicitly
setting pinMode(), digitalWrite() will have enabled the internal pull-up resistor,
which acts like a large current-limiting resistor.
Syntax

digitalWrite(pin, value)

Parameters

pin: the Arduino pin number.


value: HIGH or LOW.

Returns

Nothing

Example Code

The code makes the digital pin 13 an OUTPUT and toggles it by alternating
between HIGH and LOW at one second pace.

void setup() {
pinMode(13, OUTPUT); // sets the digital pin 13 as output
}

void loop() {
digitalWrite(13, HIGH); // sets the digital pin 13 on
delay(1000); // waits for a second
digitalWrite(13, LOW); // sets the digital pin 13 off
delay(1000); // waits for a second
}

pinMode()
[Digital I/O]

Description

Configures the specified pin to behave either as an input or an output.


See the Digital Pins page for details on the functionality of the pins.

As of Arduino 1.0.1, it is possible to enable the internal pullup resistors


with the mode INPUT_PULLUP. Additionally, the INPUT mode explicitly
disables the internal pullups.

Syntax

pinMode(pin, mode)
Parameters

pin: the Arduino pin number to set the mode of.


mode: INPUT, OUTPUT, or INPUT_PULLUP. See the Digital Pins page for a more
complete description of the functionality.

Returns

Nothing

Example Code

The code makes the digital pin 13 OUTPUT and Toggles it HIGH and LOW

void setup() {
pinMode(13, OUTPUT); // sets the digital pin 13 as output
}

void loop() {
digitalWrite(13, HIGH); // sets the digital pin 13 on
delay(1000); // waits for a second
digitalWrite(13, LOW); // sets the digital pin 13 off
delay(1000); // waits for a second
}

Notes and Warnings

The analog input pins can be used as digital pins, referred to as A0, A1,
etc.

You might also like