Experiment7

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Roll No : CE022

Id No: 20CEUOF014
Name: Darshit Bhuva

Experiment No. 7
Aim : Introduction to Arduino

1). Introduction to Arduino:


1). What is Arduino?
 An Arduino is an open source microcontroller Development Board. you can use the Arduino to read sensors
and control things like motors and lights.
 It is used in alarm system, Robotics, In LED, For making humidity Sensor connected to a plant. and turn on
an automatic watering system if it gets too dry , finger print button etc.

2). Why Arduino is more Popular?


 Because Arduino has following Advantages.
1. Arduino boards are relatively inexpensive compared to other microcontroller platforms.

2. The Arduino Software (IDE) runs on Windows, Macintosh OSX, and Linux operating systems. Most
microcontroller systems are limited to Windows.

3. The Arduino Software (IDE) is easy-to-use for beginners, yet flexible enough for advanced users to
take advantage of as well.

4. The Arduino software is published as open source tools, available for extension by experienced
programmers. The language can be expanded through C++ libraries.

5. The plans of the Arduino boards are published under a Creative Commons license, so experienced
circuit designers can make their own version of the module, extending it and improving it.

3). There are many different Arduino Boards, like


 Arduino USB v2.0
 The Arduino Extreme
 Arduino NG, Diecimila, and the Duemilanove (Legacy Versions)
 ARDUINO UNO
 Arduino Mega 2560
 Arduino Mega ADK
 Arduino Yun
 Arduino Nano
 Arduino LilyPad
2). Circuit Diagram of Arduino UNO Board.

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).

Power (Barrel Jack)

Arduino boards can be powered directly from the AC mains power supply by connecting it to the Barrel Jack
(2). Adaptor for the same is shown in figure below.

Voltage Regulator

The function of the voltage regulator (3) is to control the voltage given to the Arduino board and stabilize the
DC voltages used by the processor and other elements

Crystal Oscillator

The crystal oscillator(4) 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.

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).

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.
Analog pins

 The Arduino UNO board has five analog input pins A0 through A5(10). 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.

Main microcontroller

 Each Arduino board has its own microcontroller (11). You can assume it as the brain of your board.

Power LED indicator

 This LED(13) 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.

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 (14). 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.

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. The pins labeled “~” can be used to generate
PWM.

 The Arduino's programming language makes PWM easy to use; simply call analogWrite(pin, dutyCycle),
where dutyCycle is a value from 0 to 255, and pin is one of the PWM pins (3, 5, 6, 9, 10, or 11).
 PWM has several uses:
 Dimming an LED
 Providing variable speed control for motors.

ICSP:

The bootloader is the little program that runs when you turn the Arduino on, or press the reset button. Its main
function is to wait for the Arduino software on your computer to send it a new program for the Arduino, which
it then writes to the memory on the Arduino. This is important, because normally you need a special device to
program the Arduino. The bootloader is what enables you to program the Arduino using just the USB cable.
ICSP stands for In Circuit Serial Programming, which represents one of the several methods available for
programming Arduino boards. Ordinarily, an Arduino bootloader program is used to program an Arduino board, but
if the bootloader is missing or damaged, ICSP can be used instead. ICSP can be used to restore a missing or damaged
bootloader.

Each ICSP pin usually is cross-connected to another Arduino pin with the same name or function.

 MISO (Master In Slave Out) - The Slave line for sending data to the master,
 MOSI (Master Out Slave In) - The Master line for sending data to the peripherals,
 SCK (Serial Clock) - The clock pulses which synchronize data transmission generated by the master

AREF(16): The Arduino comes with a 10bit ADC (Analog-Digital-Converter), which converts incoming voltages
between 0V and 5V to integer values between 0 and 1023. This results in a resolution of roughly 4.8 mV. (This is
calculated by dividing 1024 into 5V).

If a sensor only delivers a lower maximum voltage, it is resonable to apply this voltage to the AREF pin, just in order
to obtain a higher resolution. for example, if we want to measure voltages with a maximum range of 3.3V, we would
feed a nice smooth 3.3V into the AREF pin – perhaps from a voltage regulator IC. Then the each step of the ADC
would represent around 3.22 millivolts (divide 1024 into 3.3).

Note that in order for this to work, you must run analogReference(EXTERNAL); before using analogRead()

IORef : Input Output Voltage Reference, It allows shields connected to Arduino board to check whether the board is
running at 3.3V or 5V.

3). Structure of a programme in Arduino

void setup()
{
Statements;
}
void loop()
{
Statements;
}
Where setup() is the preparation, and loop() is a execution of a programme.

SetUp():

Syntax:
void setup()
{
statements;
}

The setup function should follow the declaration of any variables at the very beginning of the program. It is the first
function to run in the program, is run only once, and is used to set pinMode or initialize serial communicaton.

The setup() function is called once when your program starts. Use it to initialize pin modes, or begin serial. It must be
included in a program even if there are no statement to run.

loop():

syntax:

void loop()
{
Statements;
}
The loop function follows next and includes the code to be executed continuously-reading inputs, triggering outputs,
etc. this function is the core of all Arduino programs and does the bulk of the work.

After calling the setup() function, the loop() function does precisely what its name suggests, and loops consecutively,
allowing the program to change, respond, and control the Arduino board.

void loop()
{
digitalwrite(pin, HIGH); //turn ‘pin’ on
delay(1000); // pauses for one second
digitalwrite(pin, LOW); //turns ‘pin’ off
delay(1000); // pauses for one second
}
In this code in first line pin will turn on and after pauses for one second and after pin will turn off for one second. So,
this kind of process continue for infinite time. Hence it is called loop.

pinmode():

syntax:

pinMode(pin, input or output);

Used in void setup() to configure a specified pin to behave either as an INPUT or OUTPUT.

Arduino digital pins default to inputs, so they don’t need to be explicitly declared as input with pinMode(). Pins
configured as INPUT are said to be in a high-impedance state. Pins configured as OUTPUT are said to be in a low-
impedance state.

Ex:

void setup()
{
pinmode(pin, OUTPUT); // sets a pin as an output pin
}

It is sets the ‘pin’ as output.

digitalRead():

syntax:

digitalRead(pin);
This function reads the value from a specified digital pin with the result either HIGH or LOW. The pin can be
specified as either a variable or constant(0-13).
Ex:
Value=digitalRead(pin);
It is sets ‘value’ equal to the pin.
digitalwrite():
syntax:
digitalWrite(pin,value);
Outputs either logic level HIGH or LOW at (turns on or off) a specified digital pin. The pin can be specified as either
a variable or constant(0-13).
Ex:
digitalWrite(pin, HIGH); //sets ‘pin’ to high
The following example reads a pushbutton connected to a digital input turns on an LED connected to a digital output
when the button has been pressed.
Ex:
Int led = 13; //connect LED to pin 13
Int pin = 7; //connect pusbutton to pin 7
Int value =0; //variable to store the read value
void setup()
{
pinMode(led, OUTPUT); //sets pin 13 as output
pinMode(pin, INPUT); //sets pin 7 as input
}
void loop()
{
value=digitalRead(pin); //sets ‘value’ equal to the input pin
digitalWrite(led, value); //sets ‘led’ to the button’s value
}

analogread():
syntax:
analogRead(pin);
Reads the value form a specified analog pin with a 10-bit resolution. This function only works on the analog in pins
(0-5). The resulting integer values range from 0 to 1023.
Ex:
Value = analogRead(pin);

analogwrite():

syntax:

analogWrite(pin, Value);

A value generates a steady 0 volts output at the specified pin; a value of 255 generates a steady 5 volts output at the
specified pin. For values in between 0 to 255, the pin rapidly alternates between 0 and 5 volts-the higher the value,
the more often the pin is HIGH (5 volts). For example, a value of 64 will be 0 volts three-quarters of the time, and 5
volts one quarter of the time; a value of 128 will be at 0 half the time and 255 half the time; and a value of 192 will
be 0 volts one quarter of the time and 5 volts three-quarters of the time.

Because this is a hardware function, the pin will generate a steady wave after a call to analogWrite in the
background until the next call to analogWrite(or a call to digitalRead or digitalWrite on the same pin).

Ex:

Int led=10; // LED with 220 resistor on pin 10

Int pin=0; // potentiometer on analog pin 0

Int Value; // value for reading

void loop()
{
Value = analogread(pin); //sets ‘value’ equal to ‘pin’
Value/=4; // converts 0-1023 to 0-255
analogWrite(led, Value); //outputs PWM signal to led
}

delay():
syntax:
delay(ms);
pauses your program for the amount of time as specified in milliseconds, where 1000 equals 1 second.
Ex:
delay(1000); // it will pauses program for 1 second.

You might also like