Experiment 7
Experiment 7
Experiment 7
Id No: 20CEUOF014
Name: Darshit Bhuva
Experiment No. 7
Aim : Introduction to Arduino
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.
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).
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).
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.
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.
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:
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
}
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:
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.