0% found this document useful (0 votes)
25 views

Electronics

Uploaded by

akarshk742
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Electronics

Uploaded by

akarshk742
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 101

techbvrushabh@gmail.

com | Vrushabh Nawgire


BASICS ELECTRONICS
All materials are made up
from atoms, and all atoms consist of
protons, neutrons and electrons.
Protons, have a positive
electrical charge. Neutrons have no
electrical charge while Electrons,
have a negative electrical charge.

Atoms are bound together by


powerful forces of attraction existing
between the atoms nucleus and the
electrons in its outer shell.
When these protons, neutrons
and electrons are together within the
atom they are happy and stable.

Now if we create a closed

[email protected] | Vrushabh Nawgire


circuit these loose electrons will start to move and drift back
to the protons due to theirattraction creating a flow of
electrons.

What is Electric Current ?

This flow of electrons is called an “Electrical


Current”. It is measured in Amperes, symbol “I”.
It is the continuous and uniform flow of
electrons (the negative particles of an atom)
around a circuit that are being “pushed” by the
voltage source.

[email protected] | Vrushabh Nawgire


In reality, electrons flow from the negative (-ve)
terminal to the positive (+ve) terminal of the supply and for
ease of circuit understanding conventional current flow
assumes that the current flows from the positive to the
negative terminal.

Generally in circuit diagrams the flow of current through


the circuit usually has an arrow associated with the
symbol “I” to indicate the actual direction of the current
flow.

This flow of current from positive to


negative is generally known as conventional
current flow.

[email protected] | Vrushabh Nawgire


What is Voltage then ?

Voltage can be thought of as the


force that pushes electrons through a
conductor and the greater the voltage the greater is
its ability to “push” the electrons through a given
circuit.
As energy has the ability to do work this
potential energy can be described as the work
required in joules to move electrons in the form of an
electrical current around a circuit from one point or node to
another.
Then the difference in voltage
between any two points, connections or
junctions (called nodes) in a circuit is
known as the Potential Difference.

[email protected] | Vrushabh Nawgire


A constant voltage source is called a DC Voltage with a
voltage that varies periodically with time is called an AC
voltage. Batteries or power supplies are mostly used to
produce a steady D.C. (direct current) voltage source such as
5v, 12v, 24v etc in electronic circuits and systems.

While A.C. (alternating current) voltage sources are


available for domestic house and industrial power and
lighting as well as power transmission. The mains voltage
supply in the United Kingdom is currently 230 volts a.c. and
110 volts a.c. in the USA.

[email protected] | Vrushabh Nawgire


What is Resistance ?

Resistance, ( R ) is the capacity of a material


to resist or prevent the flow of current or, more
specifically, the flow of electric charge within a
circuit. The circuit element which does this perfectly is called
the “Resistor”.

The amount of resistance a resistor has is determined


by the relationship of the current through it to the voltage
across it which determines whether the circuit element is a
“good conductor” – low resistance, or a “bad conductor” –
high resistance.

[email protected] | Vrushabh Nawgire


What is AC Voltage?
Alternating current (AC) is electric current which periodically reverses
direction,

What is DC Voltage?
in contrast to direct current (DC) which flows only in one direction.

Parallel Vs Series Connection?

[email protected] | Vrushabh Nawgire


Type of signals:
High/ON/1/Vcc – 5 volts/3.3 volts/ 12 volts etc

Low/OFF/0/GND- 0 volts/ negative terminal

How do I measure voltage?


To measure voltage, follow these steps:

1. Plug your black and red probes into the appropriate sockets (also
referred to as "ports") on your multimeter. For most multimeters, the
black probe should be plugged into the socket labeled "COM," and the
red probe into the socket labeled with a "V" (it might also have some
other symbols). Remember to check out our image gallery, the
Multimeter Overview tab, or your multimeter's manual if you have
trouble identifying the right socket.
2. Choose the appropriate voltage setting on your multimeter's dial.
Remember that most battery-powered circuits will have direct current,
but the setting you select will depend on the science project you are
doing. If you are working with a manual-ranging multimeter, you can
estimate the range you need based on the battery (or batteries)
powering your circuit. For example, if your circuit is powered by a
single 9V battery, it probably doesn't make sense to select the setting for
200V, and 2V would be too low. If available, you would want to select
20V.
3. Touch the probe tips to your circuit in parallel with the element you
want to measure voltage across (refer to the Multimeter Overview tab
for an explanation of series and parallel circuits). For example, Figure 6
shows how to measure the voltage drop across a lightbulb powered by
the battery. Be sure to use the red probe on the side connected to the
positive battery terminal, and the black probe on the side connected to
the negative battery terminal (nothing will be harmed if you get this
backwards, but your voltage reading will be negative).

[email protected] | Vrushabh Nawgire


Figure 6. Measuring voltage across a lightbulb by attaching the multimeter
probes in parallel. Current flow is represented by the yellow arrows. In
voltage-measurement mode, the multimeter's resistance is very high, so
almost all of the current flows through the lightbulb, and the multimeter does
not have a big impact on the circuit. Notice how the knob has been set to

measure DC voltage (DCV) and the red probe is plugged into the correct port
for measuring voltage (labeled "VΩ" because it is also used to measure
resistance).

[email protected] | Vrushabh Nawgire


4. If your multimeter is not auto-ranging, you might need to adjust the
range. If your multimeter's screen just reads "0," then the range you
have selected is probably too high. If the screen reads "OVER," "OL," or
"1" (these are different ways of saying "overload"), then the range you
have selected is too low. If this happens, adjust your range up or down
as necessary. Remember that you might need to consult your
multimeter's manual for specifics about your model.

How do I measure current?

To measure current, follow these steps:

1. Plug your red and black probes into the appropriate sockets (also
referred to as "ports") on the multimeter. For most multimeters, the
black probe should be plugged into the socket labeled "COM." There
might be multiple sockets for measuring current, with labels like "10A"
and "mA". Note:It is always safer to start out with the socket that can
measure a larger current. Plug the red socket into the high-current port.
2. Choose the appropriate current setting on your multimeter. Remember
to check if your circuit is direct current or alternating current, and that
almost all battery-powered circuits will be direct current. If your meter
is not auto-ranging, you might need to guess at the scale to use (you can
change this later if you don't get a good reading).
3. Connect the multimeter probes in series to the current you want to
measure (refer to the Multimeter Overview tab for an explanation of
series and parallel circuits). For example, Figure 7 shows how to
measure the current through a lightbulb that is powered by a battery.
Be sure to use the red probe toward the battery's positive side,
otherwise your current reading will be negative.

[email protected] | Vrushabh Nawgire


Figure 7. Measuring the current through a lightbulb by attaching a
multimeter in series. Current flow is represented by the yellow arrows. In
current-measurement mode, the multimeter's resistance is very low, so the
current can easily flow through the multimeter without affecting the rest of
the circuit. Notice how the knob has been set to measure direct current (DCA)
and the red probe is plugged into the port for measuring current, labeled with
an "A."

4. If your multimeter is not auto-ranging, you might need to adjust the


range. If your multimeter's screen just reads "0," then the range you
have selected is probably too high. If the screen reads "OVER," "OL," or
"1" (these are different ways of saying "overload"), then the range you
have selected is too low. If this happens, adjust your range up or down
as necessary. Remember that you might need to consult your
multimeter's manual for specifics about your model.

How do I measure resistance?

To measure resistance, follow these steps:

1. Plug your red and black probes into the appropriate sockets on your
multimeter. For most multimeters, the black probe should be plugged
into the socket labeled "COM," and the red probe should be plugged into
the socket labeled with an "Ω" symbol.
2. Choose the appropriate resistance measurement setting on your
multimeter's dial. If you have an estimate for the resistance you will be
measuring (for example, if you are measuring a resistor with a known
value), that will help you pick the range.

[email protected] | Vrushabh Nawgire


3. Important: Turn off the power supply to your circuit before measuring
resistance. If your circuit has a power switch, you can do this by turning
the switch "off." If there is no switch, you can remove the batteries. If
you do not do this, your reading might be incorrect. If your circuit has

multiple components, you might need to remove the component you


want to measure in order to accurately determine its resistance. For
example, if your circuit has two resistors in parallel, you will have to
remove one resistor to measure their resistances individually.

Connect one of your multimeter's probes to each side of the object


whose resistance you want to measure. Resistance is always positive
and the same in both directions, so it does not matter if you switch the
black and red probes in this case (unless you are dealing with a diode,
which acts like a one-way valve for electricity, so it has a high resistance

[email protected] | Vrushabh Nawgire


in one direction and a low resistance in the other direction). Figure 8
shows how to measure the resistance of a lightbulb.

Figure 8. Measuring the resistance of a lightbulb using a multimeter. Notice


how the lightbulb has been disconnected from the circuit. The multimeter
supplies its own small amount of current, which allows it to measure the
resistance. Notice how the knob has been set to the "Ω" to measure resistance,
and the red probe is plugged into the proper port to measure resistance
(labeled "VΩ" since it is also used to measure voltage).

4. If your multimeter is not auto-ranging, you might need to adjust the


range. If your multimeter's screen just reads "0," then the range you
have selected is probably too high. If the screen reads "OVER," "OL," or
"1" (these are different ways of saying "overload"), then the range you
have selected is too low. If this happens, adjust your range up or down
as necessary. Remember that you might need to consult your
multimeter's manual for specifics about your model.

How do I do a continuity check?

To do a continuity check (which ensures that there is a conductive path


between two points in your circuit), follow these steps:

1. Set your multimeter to the continuity check symbol. Remember that this
symbol might not look the same on all multimeters (and some
multimeters do not have it at all), so check out the Multimeter Overview
tab or our multimeter image gallery to see examples.
2. Plug your probes into the appropriate sockets. On most multimeters, the
black probe should go into the socket labeled "COM," and the red probe
should go into the same socket you would use to measure voltage or
resistance (not current), labeled with a V and/or an Ω.
3. Important: Turn off the power supply to your circuit before doing a

[email protected] | Vrushabh Nawgire


continuity check. If your circuit has a power switch, you can do this by
turning the switch "off." If there is no switch, you can remove the
batteries.

Touch two parts of your circuit with the probes. If the two parts of the
circuit are electrically connected with very little resistance between
them, your multimeter should beep. If they are not connected, it will not
make a noise and might display something on the screen such as "OL,"
"OVER," or "1," which all stand for "overload." The easiest way to test
this function with your multimeter is to check it with a single piece of
conductive material (most metals) and a piece of non-conducting
material, like wood or plastic. See Figure 9 for an example.

Figure 9. Using a multimeter to do a continuity test. If a conductive path is


formed between the probe tips, the multimeter will beep. If the conductive
path is broken (possibly due to a wire that has come loose in your circuit, or a
bad solder connection), the multimeter will not beep. Notice how the knob has
been set to the symbol for continuity and the red probe is plugged into the VΩ
port (this port is not always labeled with the continuity symbol).

[email protected] | Vrushabh Nawgire


How do I do a diode check?

The diode check feature is useful to determine in which direction electricity


flows through a diode. The exact operation of the "diode check" function will
vary for different multimeters, and some multimeters do not have a diode
check feature at all. Because of this variety, and because the feature is not
required for most Science Buddies projects, we have not included directions
here. If you need to do a diode check, consult the manual for your multimeter.

How do I know which scale to pick for voltage, current, or resistance, and how
do I read the numbers at different scales?

If your multimeter is not auto-ranging, knowing which scale to pick can be


tricky, especially if you are not very familiar with metric prefixes. Here are
two rules of thumb you can follow for measuring voltage, current, and
resistance:

• Voltage: Many manual-ranging multimeters have settings for 200mV,


2V, and 20V. It is very unlikely that battery-powered circuits will exceed
20V (for example, two 9V batteries connected in series will provide a
maximum of 18V). A single AA or AAA battery supplies 1.5V. Two AA or
AAA batteries combined in a battery pack will provide 3V, four will
provide 6V, and eight will provide 12V. So, if you know what type of
batteries (and how many), are powering your circuit, you can pick a
starting range to measure voltage. Remember that you want to pick the
next highest voltage setting (just like with measuring distance; you
would need a yardstick— not a 12-inch ruler— to measure something
that is 18 inches long). So, for a circuit powered by a single AA battery
(1.5V), you would select the 2V setting. For a circuit powered by a 9V
battery, you would select 20V.
• Current: When measuring current, it is always a good idea to start out
with the highest possible current setting (and the appropriate high-
current socket, if your multimeter has multiple sockets to measure
current), in order to avoid blowing a fuse. If the current you measure is

[email protected] | Vrushabh Nawgire


low enough to safely use your low-current settings and socket, then you
can take a new reading to get a more-accurate measurement. For
example, say your multimeter has a socket with a 10A fuse and one with
a 200mA fuse. Using the 10A socket, you measure a current of 150mA.
Then it would be safe to measure again with the 200mA socket (and a
lower setting on the knob).
• Resistance: If you are measuring an object with a known resistance,
you can use that value to choose the appropriate resistance setting. As
with current and voltage, you need to pick the next largest resistance
value on your scale. For example, to measure a 4.7kΩ resistor, you
would select 20kΩ. If you are measuring an object with unknown
resistance, you will just have to guess, but it is difficult to damage your
multimeter or the object you are testing when measuring resistance, so
this is not a big problem.

What is analog Signal?


An analog signal is any continuous signal for which the time varying feature
(variable) of the signal is a representation of some other time varying
quantity, i.e., analogous to another time varying signal. For example, in an
analog audio signal, the instantaneous voltage of the signal varies
continuously with the pressure of the sound waves. It differs from a digital
signal, in which the continuous quantity is a representation of a sequence of
discrete values which can only take on one of a finite number of values.[1][2]
The term analog signal usually refers to electrical signals; however,
mechanical, pneumatic, hydraulic, human speech, and other systems may also
convey or be considered analog signals.

What is digital signal?


A digital signal is a signal that is being used to represent data as a sequence of
discrete values; at any given time it can only take on one of a finite number of

[email protected] | Vrushabh Nawgire


values. This contrasts with an analog signal, which represents continuous
values; at any given time it represents a real number within a continuous
range of values.

What is a common anode led?

There are two types of LED 7-segment displays: common cathode (CC) and
common anode (CA). The difference between the two displays is the
common cathode has all the cathodes of the 7-segments connected directly
together and the common anode has all the anodes of the 7-segments
connected together.
What is LED?
A light-emitting diode (LED) is a semiconductor device that emits visible light
when an electric current passes through it.

What is switch and its type?


An electrical switch is any device used to interrupt the flow of electrons in a
circuit. Switches are essentially binary devices: they are either completely on
(“closed”) or completely off (“open”).

What is PCB?
A PCB is a thin board made of fiberglass, composite epoxy, or other laminate
material. Conductive pathways are etched or "printed" onto board, connecting
different components on the PCB, such as transistors, resistors, and integrated
circuits. PCBs are used in both desktop and laptop computers.

What is breadboard?
A breadboard is a construction base for prototyping of electronics.

[email protected] | Vrushabh Nawgire


Chapter
Introduction
2
to Electronics

[email protected] | Vrushabh Nawgire


Soldering & De-soldering

Soldering , is a process in
which two or more items (usually
metal) are joined together by
melting and putting a filler
metal (solder) into the joint.
The filler metal having a
lower melting point than the
adjoining metal. Soldering differs from welding in that
soldering does not involve melting the work pieces.
In brazing, the filler metal melts at a higher temperature, but
the work piece metal does not melt
De-soldering is the removal
of solder and components from
a circuit board for troubleshooting,
repair, replacement, and salvage.

[email protected] | Vrushabh Nawgire


[email protected] | Vrushabh Nawgire
Method of Soldering & De-soldering

Step 1 Preparing the PCB

1. Check to be sure the pad size of the PCB lines up with


the pins on the SMD
2. Clean the PCB of any dust or
debris.
3. Turn the soldering iron on now,
and set the temperature
between 600-700 degrees.

Warning: When heated to these


temperatures, you will be burned if you touch the tip of
the soldering iron.

[email protected] | Vrushabh Nawgire


Tweezers to Position the
Step 2
Component

1. Align the pins of the component with the pads on the


circuit board.

2. Since most surface


mount components
have the same amount
of pins on both sides,
it is important to find
"pin 1" every time you
place a new
component.

[email protected] | Vrushabh Nawgire


Step 3 Track Down One Corner

1. Keep one hand still,


holding the component
in place with the
tweezers.
2. By now, the soldering
iron should be hot. Get a
small to medium sized
dot of solder on the tip.
3. Pick any corner pin on
the component touch
and hold the soldering
iron to the pad that will be associated with that pin.
4. If you have done this correctly, the solder should have
transferred from the pad on the circuit board to the
component pin fixed later.

[email protected] | Vrushabh Nawgire


Step 4 Flux

1. This substance is messy, so be sure to use an applicator.


(toothpick, brush, etc.) In
this case, I have used a metal
tip.
2. Get a large amount of flux on
the applicator.
3. Spread the flux over the pins
on the opposite side of the
component that was tacked
down in the previous step.

[email protected] | Vrushabh Nawgire


Step 5 Solder

1. Pick up the soldering iron


in one hand, and the
solder in the other, as per
the picture below.
2. Use the soldering iron to
heat up the pad, not the
pin on the component.
3. While the pin is hot,
position the solder
between the pad and the
pin. The heat will melt the
solder, and the flux will
cause it to flow where it needs to.
4. Repeat this as many times as necessary.

[email protected] | Vrushabh Nawgire


Step 6 Heating Up to Fix De-
soldering Track

These steps will also work for removing the component


from the board.
1. Take the desoldering wick
and place it over the solder you
want to remove.
2. With the soldering iron,
lightly press on the wick, to
ensure the heat is transferred
through to the solder.
Warning: Remember that heat removes solder, not pressure.
Too much pressure applied could remove the pad or pin on
the component, ruining the component or board.

[email protected] | Vrushabh Nawgire


Clean With Rubbing
Step 7
Alcohol

If water soluble solder was used, replace rubbing


alcohol with water.
1. Take the anti-static cloth and
pour a small amount of
rubbing alcohol onto it.
2. Gently clean around the newly
soldered component, and
where any excess flux exists.
This will give a more
professional look.

[email protected] | Vrushabh Nawgire


What is IC?
An integrated circuit or monolithic integrated circuit (also referred to as an
IC, a chip, or a microchip) is a set of electronic circuits on one small flat piece
(or "chip") of semiconductor material, normally silicon

How to read pins configuration in intigrated circuit ?


A semicircular notch is present in IC. From LHS of notch pin no 1 starts and
continues.

For eg,

[email protected] | Vrushabh Nawgire


What is Arduino?
Arduino is an open-source electronics platform based on easy-to-use
hardware and software. Arduino boards are able to read inputs - light on a
sensor, a finger on a button, or a Twitter message - and turn it into an output -
activating a motor, turning on an LED, publishing something online.

Inputs and outputs in electronic circuits

The input is what sets an electrical circuit in action. Any of the following components can
be used as inputs:

• a switch (eg push-switch, microswitch)


• a key pad
• a Light Dependent Resistor (LDR)
• a thermistor
• a photodiode
• a phototransistor
• an opto-isolator
• a proximity switch or reed switch.

The output is what results from an electrical circuit. Any of the following components may
be used as outputs:

• an LED
• a lamp
• a buzzer
• a piezo
• a motor or stepper motor
• a solenoid
• a relay
• a seven-segment display.

What is sensor?

[email protected] | Vrushabh Nawgire


A sensor is a device that detects and responds to some type of input from the
physical environment. The specific input could be light, heat, motion,
moisture, pressure, or any one of a great number of other environmental
phenomena.

How to start coding in arduino software ?


How to upload program in arduino?

STEP 1

Arduino microcontrollers come in a variety of types. The most common is the


Arduino UNO, but there are specialized variations. Before you begin building,
do a little research to figure out which version will be the most appropriate
for your project.

STEP 2

To begin, you'll need to install the Arduino Programmer, aka the integrated
development environment (IDE).

STEP 3

Connect your Arduino to the USB port of your computer. This may require a
specific USB cable. Every Arduino has a different virtual serial-port address, so
you 'll need to reconfigure the port if you're using different Arduinos.

STEP 4

Set the board type and the serial port in the Arduino Programmer.

[email protected] | Vrushabh Nawgire


STEP 5

Test the microcontroller by using one of the preloaded programs, called


sketches, in the Arduino Programmer. Open one of the example sketches, and
press the upload button to load it. The Arduino should begin responding to the
program: If you've set it to blink an LED light, for example, the light should
start blinking.

STEP 6

To upload new code to the Arduino, either you'll need to have access to code
you can paste into the programmer, or you'll have to write it yourself, using
the Arduino programming language to create your own sketch. An Arduino
sketch usually has five parts: a header describing the sketch and its author; a
section defining variables; a setup routine that sets the initial conditions of
variables and runs preliminary code; a loop routine, which is where you add
the main code that will execute repeatedly until you stop running the sketch;
and a section where you can list other functions that activate during the setup
and loop routines. All sketches must include the setup and loop routines.

STEP 7

Once you've uploaded the new sketch to your Arduino, disconnect it from
your computer and integrate it into your project as directed.

[email protected] | Vrushabh Nawgire


Making an led blinking program ?

This example shows the simplest thing you can do with an Arduino or
Genuino to see physical output: it blinks the on-board LED.

Hardware Required

• Arduino or Genuino Board optional


• LED
• 220 ohm resistor

Circuit

This example uses the built-in LED that most Arduino and Genuino boards
have. This LED is connected to a digital pin and its number may vary from
board type to board type. To make your life easier, we have a constant that is
specified in every board descriptor file. This constant is LED_BUILTIN and
allows you to control the built-in LED easily. Here is the correspondence
between the constant and the digital pin.

• D13 - 101
• D13 - Due
• D1 - Gemma
• D13 - Intel Edison
• D13 - Intel Galileo Gen2
• D13 - Leonardo and Micro
• D13 - LilyPad
• D13 - LilyPad USB
• D13 - MEGA2560
• D13 - Mini
• D6 - MKR1000
• D13 - Nano
• D13 - Pro

[email protected] | Vrushabh Nawgire


• D13 - Pro Mini
• D13 - UNO
• D13 - Yún
• D13 - Zero

If you want to lit an external LED with this sketch, you need to build this
circuit, where you connect one end of the resistor to the digital pin
correspondent to the LED_BUILTIN constant. Connect the long leg of the LED
(the positive leg, called the anode) to the other end of the resistor. Connect the
short leg of the LED (the negative leg, called the cathode) to the GND. In the
diagram below we show an UNO board that has D13 as the LED_BUILTIN
value.

The value of the resistor in series with the LED may be of a different value
than 220 ohm; the LED will lit up also with values up to 1K ohm.

[email protected] | Vrushabh Nawgire


Schematic

[email protected] | Vrushabh Nawgire


Code

After you build the circuit plug your Arduino or Genuino board into your computer, start
the Arduino Software (IDE) and enter the code below. You may also load it
from the menu File/Examples/01.Basics/Blink . The first thing you do is to
initialize LED_BUILTIN pin as an output pin with the line

pinMode(LED_BUILTIN, OUTPUT);

In the main loop, you turn the LED on with the line:

digitalWrite(LED_BUILTIN, HIGH);

This supplies 5 volts to the LED anode. That creates a voltage difference
across the pins of the LED, and lights it up. Then you turn it off with the line:

digitalWrite(LED_BUILTIN, LOW);

That takes the LED_BUILTIN pin back to 0 volts, and turns the LED off. In
between the on and the off, you want enough time for a person to see the
change, so the delay() commands tell the board to do nothing for 1000
milliseconds, or one second. When you use the delay() command, nothing else
happens for that amount of time. Once you've understood the basic examples,
check out the BlinkWithoutDelay example to learn how to create a delay while
doing other things.

Once you've understood this example, check out the DigitalReadSerial


example to learn how read a switch connected to the board.

/*
Blink

Turns an LED on for one second, then off for one second, repeatedly.

Most Arduinos have an on-board LED you can control. On the UNO, MEGA

[email protected] | Vrushabh Nawgire


and ZERO
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
the correct LED pin independent of which board is used.
If you want to know what pin the on-board LED is connected to on your
Arduino
model, check the Technical Specs of your board at:
https://www.arduino.cc/en/Main/Products

void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage
level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the
voltage LOW
delay(1000); // wait for a second
}

[email protected] | Vrushabh Nawgire


Making an program of trafic light signal with led and Arduino?
Step 1: You Will Need:

[email protected] | Vrushabh Nawgire


Step 2: Get the Components

I assume you already have an adruino board, and maybe also a Protoshield.

You'll need the LED's and resistors

the 220 Ohm resistors are color coded so: Red, Red, Brown

[email protected] | Vrushabh Nawgire


Step 3: Hook Up to the Board

Since this is a really simple project we only need 3 digital pins and ground.

Put the LED's in the breadboard/protoboard and use the resistors to connect
them to the digital pins,

Green to pin 8
Yellow to pin 9

[email protected] | Vrushabh Nawgire


and Red to pin 10

then connect all the negative pins of the LED's together and to ground.

Step 4: Upload the Code!

Again, since this is a really simple project the code is also simple,
just copy it from below and upload it to your board via USB.

[email protected] | Vrushabh Nawgire


Code:

int greenled = 8; //Led's and pins


int yellowled = 9;
int redled = 10;

void setup()
{
pinMode(greenled, OUTPUT); //Pinmodes of the leds
pinMode(yellowled, OUTPUT);
pinMode(redled, OUTPUT);
}

void loop()
{
digitalWrite(greenled, HIGH); //Green on for 5 seconds
delay(5000);
digitalWrite(greenled, LOW); //Green off, yellow on for 2 seconds
digitalWrite(yellowled, HIGH);
delay(2000);
digitalWrite(yellowled, LOW); //yellow off, red on for 5 seconds
digitalWrite(redled, HIGH);
delay(5000);
digitalWrite(yellowled, HIGH); //Yellow and red on for 2 seconds
delay(2000);
digitalWrite(redled, LOW); //Red and Yellow off
digitalWrite(yellowled, LOW);
}

[email protected] | Vrushabh Nawgire


Making an obstacle detector program using ir sensor with
Arduino?

Here is how the sensor looks. We will see another pictorial representation of
the above sensor and discuss about the details of the part.

The pictorial representation is given below:

[email protected] | Vrushabh Nawgire


Let's learn and see what the sensor has. As you can see, the numbers are
mentioned. We will discuss the workaround and try to understand each and
every word. First one goes like:

Sensor Parts Functions


This port in the sensor sends the digital output to the output unit. Here,
OUTPUT
we have the sensor output port on board as 7.
GND This port is used to connect to the board's Grounded port.
The voltage supply port, here we have used the 5 V supply port from
VCC
the board.
Distance The CW (Clock wise) movement increases the distance proximity and
Manipulator the opposite decreases.
Power and Former illuminates when the Power is supplied and the latter when any
Obstacle LED obstacle comes over.

The circuit board looks as shown below:

[email protected] | Vrushabh Nawgire


Snippet

int LED = 13; // Use the onboard Uno LED

int obstaclePin = 7; // This is our input pin

int hasObstacle = HIGH; // HIGH MEANS NO OBSTACLE

void setup()

pinMode(LED, OUTPUT);

pinMode(obstaclePin, INPUT);

Serial.begin(9600);

void loop()

hasObstacle = digitalRead(obstaclePin); //Reads the output of the obstac


le sensor from the 7th PIN of the Digital section of the arduino

if (hasObstacle == LOW) //LOW means something is ahead, so illuminate


s the 13th Port connected LED

Serial.println("Stop something is ahead!!");

digitalWrite(LED, HIGH); //Illuminates the 13th Port LED

} else

[email protected] | Vrushabh Nawgire


{

Serial.println("Path is clear");

digitalWrite(LED, LOW);

delay(200);

[email protected] | Vrushabh Nawgire


What is L293D?
What Is Motor Driver IC?

A motor driver IC is an integrated circuit chip which is usually used to control motors in
autonomous robots. Motor driver ICs act as an interface between microprocessors in
robots and the motors in the robot. The most commonly used motor driver IC’s are from
the L293 series such as L293D, L293NE, etc. These ICs are designed to control 2 DC motors
simultaneously. L293D consist of two H-bridge. H-bridge is the simplest circuit for
controlling a low current rated motor. For this tutorial we will be referring the motor
driver IC as L293D only. L293D has 16 pins, they are comprised as follows:
Ground Pins - 4
Input Pins - 4
Output Pins - 4
Enable pins - 2
Voltage Pins - 2
The workings of the individual pins are explained in detail, later in the tutorial.

Why We Need Motor Driver IC?

Motor Driver ICs are primarily used in autonomous robotics only. Also most
microprocessors operate at low voltages and require a small amount of current to operate
while the motors require a relatively higher voltages and current . Thus current cannot be
supplied to the motors from the microprocessor. This is the primary need for the motor
driver IC.

How Motor Driver Operates?

The L293D IC receives signals from the microprocessor and transmits the relative signal to
the motors. It has two voltage pins, one of which is used to draw current for the working of
the L293D and the other is used to apply voltage to the motors. The L293D switches it
output signal according to the input received from the microprocessor.
For Example: If the microprocessor sends a 1(digital high) to the Input Pin of L293D, then
the L293D transmits a 1(digital high) to the motor from its Output Pin. An important thing
to note is that the L293D simply transmits the signal it receives. It does not change the
signal in any case.

L293D And Its Working

[email protected] | Vrushabh Nawgire


The L293D is a 16 pin IC, with eight pins, on each side, dedicated to the controlling of a
motor. There are 2 INPUT pins, 2 OUTPUT pins and 1 ENABLE pin for each motor. L293D
consist of two H-bridge. H-bridge is the simplest circuit for controlling a low current rated
motor.
The Theory for working of a H-bridge is given below.

Working Of A H-bridge

H-bridge is given this name because it can be modelled as four switches on the corners of
‘H’. The basic diagram of H-bridge is given below :

In the given diagram, the arrow on the left points to the higher potential side of the input
voltage of the circuit. Now if the switches S1 & S4 are kept in a closed position while the
switches S2 & S3 are kept in a open position meaning that the circuit gets shorted across
the switches S1 & S4. This creates a path for the current to flow, starting from the V input
to switch S1 to the motor, then to switch S4 and then the exiting from the circuit. This flow
of the current would make the motor turn in one direction. The direction of motion of the
motor can be clockwise or anti-clockwise, this is because the rotation of the motor depends
upon the connection of the terminals of the motor with the switches.
For simplicity, lets assume that in this condition the motor rotates in a clockwise direction.
Now, when S3 and S2 are closed then and S1 and S4 are kept open then the current flows
from the other direction and the motor will now definitely rotates in counter-clockwise

[email protected] | Vrushabh Nawgire


direction
When S1 and S3 are closed and S2 and S4 are open then the ‘STALL’ condition will
occur(The motor will break).

Stall Condition:
When the motor is applied positive voltage on both sides then the voltage from both the
sides brings the motor shaft to a halt

L293D Pin Diagram :

[email protected] | Vrushabh Nawgire


In the above diagram we can see that,

Pin
Pin Characteristics
No.

Enable 1-2, when this is HIGH the left part of the IC will work and when it is low the
1
left part won’t work. So, this is the Master Control pin for the left part of IC

2 INPUT 1, when this pin is HIGH the current will flow though output 1

3 OUTPUT 1, this pin should be connected to one of the terminal of motor

4,5 GND, ground pins

6 OUTPUT 2, this pin should be connected to one of the terminal of motor

7 INPUT 2, when this pin is HIGH the current will flow though output 2

VC, this is the voltage which will be supplied to the motor. So, if you are driving 12 V
8
DC motors then make sure that this pin is supplied with 12 V

16 VSS, this is the power source to the IC. So, this pin should be supplied with 5 V

15 INPUT 4, when this pin is HIGH the current will flow though output 4

14 OUTPUT 4, this pin should be connected to one of the terminal of motor

13,12 GND, ground pins

11 OUTPUT 3, this pin should be connected to one of the terminal of motor

10 INPUT 3, when this pin is HIGH the current will flow though output 3

Enable 3-4, when this is HIGH the right part of the IC will work and when it is low
9
the right part won’t work. So, this is the Master Control pin for the right part of IC

[email protected] | Vrushabh Nawgire


Chapter
Introduction
3
to Seven
Segment
Display

[email protected] | Vrushabh Nawgire


Seven Segment Display

Seven segment displays are


commonly used in many electrical
applications, including alarm clocks,
timers, and scales. In this tutorial, you
will learn how to use your own 7-
segment displays!

A 7-segment display is an electronic device that can be


used for displaying numerals and some letters. Different
letters/numbers can be represented by connecting different
pins on the display to the battery, which turns on the LEDs in
parallel. This activity introduces how to use a 7-segment
display using only a battery, a breadboard, a resistor, and
some wires.
LEDs are really fun to learn how to use –
if you want to learn more about how the LEDs
inside of a 7-segment display work, you
can find more information at the bottom of
this page.

[email protected] | Vrushabh Nawgire


Supplies
▪ A breadboard. If you are not familiar with how a
breadboard works, this is a useful introduction
▪ Some jumper wires,
▪ Some 7-segment displays.
▪ 360+ ohm resistor(s). We used a 470 ohm resistor. Any
resistor value between 360-500 ohms will work for this
activity.
▪ A 9 V battery and a battery clip.

[email protected] | Vrushabh Nawgire


Be careful not to let the
wire leads from the battery
touch each other. This will
short the battery (the battery
will heat up and could
become dangerous).
Adult supervision
needed for soldering.
Adult supervision should
be used to look up the type of
7-segment display you are
using on the internet.
It is important to know whether the device is common
anode (like the ones we are using) or common cathode. The
maximum current rating and the connections inside
different 7-segment displays may be different, and not using
the devices correctly can “burn out” an LED (it is unlikely
that the 7-segment will actually become hot, but the LED
inside the segment can become unusable)

[email protected] | Vrushabh Nawgire


Soldering Resistor to the
Clip

1. Solder a resistor to the positive lead of the battery clip.


2. Attach the battery clip to the battery. Insert the positive
(red) end of the battery clip into the ‘+’ rail of the
breadboard, and the negative (black) end of the battery
clip into the ‘-‘ rail.
3. Using a jumper wire,
connect the ‘+’ rail
with the common
anode pin this
provides power to the
device.
4. Using another jumper
wire, connect the
other pins to the ‘-‘
rail. The segment that is connected to this pin should
now turn on!

[email protected] | Vrushabh Nawgire


5. Try connecting
other pins with
jumper wires to the
‘-‘ rail. How many
segments can you
light up? Can you
make a number or
letter?
6. Try connecting
more 7-segment
displays on the breadboard. Can you write the word
‘HI’? Can you write the word ‘HELLO’?

[email protected] | Vrushabh Nawgire


More About Diodes
The 7-segment display is a device made up of seven
LEDs connected in parallel. LED is an acronym for Light
Emitting Diode. LEDs work very similarly to normal diodes –
except that when an LED is on, it emits light. Below is a
typical pin configuration and block diagram for a common
anode 7-segment display, like the one we used in this
activity.

As you can see in the block diagram, a diode is shown as


a triangle and a line. The direction in which the triangle is
pointing changes how the diode works. If we were to
connect the positive end of the battery to the line labelled
‘3,8’ and the negative end of the battery to the line labelled
‘7’, the LED ‘a’ would turn on. However, if we reversed the
battery connections, nothing would turn on. Why? Because

[email protected] | Vrushabh Nawgire


the diode would not be on!
To turn a diode on, you need to make sure current is
flowing through the diode in the direction the triangle is
pointing (called the forward direction).
If current isn’t flowing, or is flowing in the opposite
(reverse) direction of the triangle, the diode will be off. In
this case, since the triangle of diode ‘a’ is pointing down, we
can make the current flow down by connecting the positive
end of the battery to ‘3,8’ and the negative end of the battery
to ‘7’.

[email protected] | Vrushabh Nawgire


Chapter
Introduction
4
to
Potentiometer

[email protected] | Vrushabh Nawgire


Potentiometer
A potentiometer is a three-terminal
resistor with a sliding or rotating contact
that forms an adjustable voltage divider
If only two terminals are used, one end
and the wiper, it acts as a variable
resistor or rheostat.
The measuring instrument called a
potentiometer is essentially a voltage
divider used for
measuring electric potential (voltage);
the component is an implementation of
the same principle, hence its name.
Potentiometers are commonly
used to control electrical devices such
as volume controls on audio
equipment.
Potentiometers operated by a
mechanism can be used as position transducers, for example,
in a joystick. Potentiometers are rarely used to directly
control significant power (more than a watt), since the
power dissipated in the potentiometer would be comparable
to the power in the controlled load.

[email protected] | Vrushabh Nawgire


The resistive element of inexpensive potentiometers is
often made of graphite. Other materials used include
resistance wire, carbon particles in plastic, and a
ceramic/metal mixture called cermet. Conductive track
potentiometers use conductive polymer resistor pastes that
contain hard-wearing resins and polymers, solvents, and
lubricant, in addition to the carbon that provides the
conductive properties.

Others are enclosed within the equipment and are


intended to be adjusted to calibrate equipment during
manufacture or repair, and not otherwise touched. They are
usually physically much smaller than user-accessible
potentiometers, and may need to be operated by a
screwdriver rather than having a knob. They are usually
called "preset potentiometers" or "trim[ming] pots". Some
presets are accessible by a small screwdriver poked through
a hole in the case to allow servicing without dismantling.

[email protected] | Vrushabh Nawgire


Televisions

Potentiometers were formerly used to control picture


brightness, contrast, and color response. A potentiometer
was often used to adjust "vertical hold", which affected the
synchronization between the receiver's internal sweep
circuit (sometimes a multivibrator) and the received picture
signal, along with other things such as audio-video carrier
offset, tuning frequency (for push-button sets) and so on.

[email protected] | Vrushabh Nawgire


Chapter
Introduction
5
to Measuring
Instruments

[email protected] | Vrushabh Nawgire


E lectrical measurements are the methods, devices

and calculations used to measure electrical quantities.


Measurement of electrical quantities may be done to
measure electrical parameters of a system.
Using transducers, physical properties such as
temperature, pressure, flow, force, and many others can be
converted into electrical signals, which can then be
conveniently measured and recorded.
High-precision laboratory measurements of electrical
quantities are used in experiments to determine
fundamental physical properties such as the charge of the
electron or the speed of light, and in the definition of the
units for electrical measurements, with precision in some
cases on the order of a few parts per million.

[email protected] | Vrushabh Nawgire


VARIOUS ELECTRONIC MEASUREMENT EQUIPMENTS ARE -
Ammeter
Ammeter is an electronic instruments device used to
determine the electric current flowing through a circuit.
Ammeters measuring current in milli-ampere range is
known as milli-ammeters. Common types of ammeters are
moving-coil ammeter and moving-iron ammeter. Ammeters
are connected in series to the circuit whose current is to be
measured. Hence this electronic instrument is designed to
have as minimum resistance/
loading as possible. It is used
commonly in electronics lab.

[email protected] | Vrushabh Nawgire


Voltmeter
Voltmeter is an electronic
instrument used in an electric circuit
to determine the potential difference
or voltage between two different
points. Digital and analog voltmeters
are available in electronics lab. They
are usually connected in parallel
(shunt) to the circuit. Hence, they are designed to have
maximum resistance as possible to reduce the loading effect.
This device is also common in electronics lab.

Multimeter
Multimeter is an electronic
instrument used to measure different
electrical parameters such as voltage,
current, resistance etc. It is the
common electronic instruments used
to troubleshoot the faults in all
electrical and electronic devices. Digital multimeters are
most commonly used in electronics lab since they offer

[email protected] | Vrushabh Nawgire


better precision and accuracy and are cheaper compared to
the analog versions. It will show the numerical values in its
digital display.

[email protected] | Vrushabh Nawgire


6

Chapter
Introduction
to Arduino
Basics

[email protected] | Vrushabh Nawgire


Overview

The Arduino microcontroller is an easy to use yet


powerful single board computer that has gained
considerable traction in the hobby and professional market.
This is what the Arduino board looks like.

The Arduino programming language is a simplified


version of C/C++. If you know C, programming the Arduino
will be familiar. If you do not know C, no need to worry as
only a few commands are needed to perform useful
functions.

[email protected] | Vrushabh Nawgire


Arduino Pins :

USB To PC : It is used to communicate Arduino via Universal


Serial Bus to PC for programming/sending data to Arduino
serially.

[email protected] | Vrushabh Nawgire


7V to 12V DC Input : For external supply, the voltage range
of 7V to 12V DC is recommended. The 9V battery can be used
to power your Arduino Uno board.

Reset Button : It Resets the Arduino board if pressed.

GND : Ground.

TX : Transmit, It is used to transmit TTL serial data. It is also


referred as ‘outwards’ since it ‘transmits’ data from Arduino
to other connected peripheral device.

RX : Receive, It is used to receive TTL serial data. IT is also


referred as ‘inwards’ since it ‘receives’ data from external
hardware to Arduino.

Vin : Voltage In, If you’re powering your Arduino board from


USB nothing is obtained from Vin pin. But, if you’re powering
the board with external supply then that supply is directly
obtained from Vin pin. However, the supply obtained at Vin
pin is usually lesser by 1V than voltage supplied to Power
pin due to reverse polarity protection diode.

[email protected] | Vrushabh Nawgire


5V Pin : It is used to power external components connected
to Arduino which needs 5V.

3.3V Pin : It is used to power external components


connected to Arduino which needs 3.3V

IORef : Input Output Voltage Reference, It allows shields


connected to Arduino board to check whether the board is
running at 3.3V or 5V.

[email protected] | Vrushabh Nawgire


[email protected] | Vrushabh Nawgire
An important feature of the Arduino is that you can
create a control program on the host PC, download it to the
Arduino and it will run automatically. Remove the USB cable
connection to the PC, and the program will still run from the
top each time you push the reset button. Remove the battery
and put the Arduino board in a closet for six months. When
you reconnect the battery, the last program you stored will
run.

Connecting a Battery

For stand-alone operation, the board is powered by a


battery rather than through the USB connection to the
computer. While the external power can be anywhere in the
range of 6 to 24 V (for example, you could use a car battery),
a standard 9 V battery
is convenient
Warning: Watch the
polarity as you
connect your battery
to the snap as reverse
orientation could blow
out your board.
Disconnect your
Arduino from the
computer.

[email protected] | Vrushabh Nawgire


Connect a 9 V battery to the Arduino power jack using the
battery snap adapter. Confirm that the blinking program
runs. This shows that you can power the Arduino from a
battery and that the program you download runs without
needing a connection to the host PC.

Click the Upload button or Ctrl-U to compile the program


and load on the Arduino board. Click the Serial Monitor
button . If all has gone well, the monitor window will show
your message and look something like this

[email protected] | Vrushabh Nawgire


Congratulations; you have created and run your first
Arduino program!
Push the Arduino reset button a few times and see what
happens.

[email protected] | Vrushabh Nawgire


Flashing an LED

Create and run this Arduino program


void setup()
{
pinMode(2,OUTPUT);
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
}
void loop()
{}

[email protected] | Vrushabh Nawgire


Reading a switch

Create and run this Arduino program

void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println(digitalRead(3));
delay(250);}

[email protected] | Vrushabh Nawgire


Controlling a Small DC Motor

void setup()

{
pinMode(2,OUTPUT);
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
}
void loop()
{}

[email protected] | Vrushabh Nawgire


The Simple Commands

This section covers the small set of commands you need


to make the Arduino do something useful. These commands
appear in order of priority. You can make a great machine
using only digital read, digital write and delay commands.
Learning all the commands here will take you to the next
level.

pinMode

This command, which goes in the setup() function, is


used to set the direction of a digital I/O pin. Set the pin to
OUTPUT if the pin is driving and LED, motor or other device.
Set the pin to INPUT if the pin is reading a switch or other
sensor. On power up or reset, all pins default to inputs. This
example sets pin 2 to an output and pin 3 to an input.

void setup()
{
pinMode(2,OUTPUT);
pinMode(3,INPUT);
}
void loop() {}

[email protected] | Vrushabh Nawgire


Serial.print

The Serial.print command lets you see what's going on


inside the Arduino from your computer. For example, you
can see the result of a math operation to determine if you are
getting the right number. Or, you can see the state of a digital
input pin to see if the Arduino is a sensor or switch properly.
When your interface circuits or program does not seem to be
working, use the Serial.print command to shed a little light
on the situation. For this command to show anything, you
need to have the Arduino connected to the host computer
with the USB cable. There are two forms of the print
command. Serial.print() prints on the same line while
Serial.println() starts the print on a new line.
Here is a brief program to check if your board is alive
and connected to the PC

void setup()
{
Serial.begin(9600);
Serial.println("Hello World");
}
void loop() {}

[email protected] | Vrushabh Nawgire


Here is a program that loops in place, displaying the
value of an I/O pin. This is useful for checking the state of
sensors or switches and to see if the Arduino is reading the
sensor properly.
Try it out on your Arduino. After uploading the
program, use a jumper wire to alternately
connect pin 2 to +5V and to Gnd.

void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println(digitalRead(2));
delay(100);
}

If you wanted to see the states of pins 2 and 3 at the


same time, you can chain a few print commands, noting that
the last command is a println to start a new line.

void setup()
{
Serial.begin(9600);
}

[email protected] | Vrushabh Nawgire


void loop()
{
Serial.print("pin 2 = ");
Serial.print(digitalRead(2));
Serial.print(" pin 3 = ");
Serial.println(digitalRead(3));
21
delay(100);
}
DigitalWrite

This command sets an I/O pin high (+5V) or low (0V)


and is the workhorse for commanding the outside world of
lights, motors, and anything else interfaced to your board.
Use the pinMode()
command in the setup() function to set the pin to an output.
digitalWrite(2,HIGH); // sets pin 2 to +5 volts
digitalWrite(2,LOW); // sets pin 2 to zero volts

Delay

Delay pauses the program for a specified number of


milliseconds. Since most interactions with the world involve
timing, this is an essential instruction. The delay can be for 0
to 4,294,967,295 msec. This code snippet turn on pin 2 for 1

[email protected] | Vrushabh Nawgire


second.
digitalWrite(2,HIGH); // pin 2 high (LED on)
delay(1000); // wait 500 ms
digitalWrite(2,LOW); // pin 2 low (LED off)

If

This is the basic conditional branch instruction that


allows your program to do two different things depending
on whether a specified condition is true or false. Here is one
way to have your program wait in place until a switch is
closed. Connect a switch to pin 3 as shown in Section 3.
Upload this program then try closing the switch

void setup()
22
{
Serial.begin(9600);
}
void loop()
{
if (digitalRead(3) == LOW) {
Serial.println("Somebody closed the switch!");
}
}
The if line reads the state of pin 3. If it is high, which it

[email protected] | Vrushabh Nawgire


will be for this circuit when the switch is open, the code
jumps over the Serial.println command and will repeat the
loop. When you close the switch, 0V is applied to pin 3 and
its state is now LOW. This means the if condition is true so
this time around the code between the braces is executed
and the message is printed
The if line reads the state of pin 3. If it is high, which it
will be for this circuit when the switch is open, the code
jumps over the Serial.println command and will repeat the
loop. When you close the switch, 0V is applied to pin 3 and
its state is now LOW. This means the if condition is true so
this time around the code between the braces is executed
and the message is printed the condition is true, the program
will execute the commands between the braces.
If the condition is not true, the program will skip to the
statement following the braces.
The condition compares one thing to another. In the
example above, the state of pin 1 was compared to LOW with
==, the equality condition. Other conditional operators are !=
(not equal to), > (greater than), < (less than), >= (greater
than or equal to), and <= (less than or equal to).
You can have the program branch depending on the
value of a variable. For example, this program will print the
value of i only when it is less than 30.

[email protected] | Vrushabh Nawgire


int i;
void setup()
{
Serial.begin(9600);
i=0;
}
void loop()
{
i=i+1;
if (i<30) {
Serial.println(i);
}
}

For

The for statement is used to create program loops.


Loops are useful when you want a chunk of code to be
repeated a specified number of times. A variable is used to
count the number of times the code is repeated. Here is an
example that flashes an LED attached to pin 2 five times

int i;
void setup()
{

[email protected] | Vrushabh Nawgire


pinMode(2,OUTPUT);
for (i=0;i<5;i++) {
digitalWrite(2,HIGH);
delay(250);
digitalWrite(2,LOW);
delay(250);
}
}
void loop() {}

The variable i is the loop counter. The for() statement


has three parts: the initialization, the check and the
increment. Variable i is initialized to zero. The check is to see
if i is less then 5. If so, the commands between the braces are
executed. If not, those commands are skipped. After the
check, i is incremented by 1 (the i++ command). While the
for statement could read for (i=1;i==5;i++), it is convention
to start the counter variable at zero and use less than for the
condition check.
You can have the loop counter increment by two or by
three or by any increment you want. For
example, try this code fragment.

int i;
void setup()
{

[email protected] | Vrushabh Nawgire


Serial.begin(9600);
for (i=0;i<15;i=i+3) {
Serial.println(i);
}
}
void loop() {}
While

The while statement is another branch command that


does continuous looping. If the condition following the while
is true, the commands within the braces are executed
continuously. Here is an example that continuously reads a
switch on pin 3, and then when the switch is pressed, the
condition is no longer true so the code escapes the while
command and prints.

void setup()
{
Serial.begin(9600);
while(digitalRead(3) == HIGH) {
}
Serial.println("Switch was pressed");
}
void loop() {}

Goto

[email protected] | Vrushabh Nawgire


The goto statement commands the computer to jump
immediately to another part of the program marked by an
address label. The goto should be used sparingly because it
makes the program hard to follow, but is handy for breaking
out of nested loops or other complex control structures.
Here is an example

void setup()
{
Serial.begin(9600);
while(true) {
if (digitalRead(3) == LOW) {
goto wrapup;
}
}
wrapup:
Serial.println("Switch was pressed");
}
void loop() {}

The while(true) statement runs continuously, checking


the state of pin 3 each time. When pin 3 is low (pressed), the
if condition is true and the goto statement executed,
breaking out of the while loop.

[email protected] | Vrushabh Nawgire


Functions

Functions are a powerful programming feature that are


used when you want to set up an action that can be called
from several places in the program. For example, let's say
you wanted an LED connected to pin 2 to flash 3 times as an
alert, but that you needed to execute the alert at three
different places in the program. One solution would be to
type in the flashing code at the three separate program
locations. This uses up precious code space and also means
that if you change the flash function, for example changing
from 3 flashes to 4, you have to change the code in three
places.
A better solution is to write the flash function as a
subroutine and to call it from the main body of the code.
Here is an example

int i;
void setup()
{
pinMode(2,OUTPUT);
Serial.begin(9600);
Serial.println("Welcome to my program");
delay(1000);

[email protected] | Vrushabh Nawgire


flasher(); // call flasher function
Serial.println("I hope you like flashing");
delay(1000);
flasher(); // call flasher again
Serial.println("Here it is one more time");
delay(1000);
flasher();
}
void loop() {}
void flasher()
{
for(i=0;i<3;i++) {
digitalWrite(2,HIGH);
delay(250);
digitalWrite(2,LOW);
delay(250);
}
}
The function flasher() is defined outside the setup() and
loop() functions. When the main program encounters a
flasher(); command, the programimmediately jumps to the
function and starts executing the code there.

Coding Style

Style refers to your own particular style for creating

[email protected] | Vrushabh Nawgire


code and includes layout, conventions for
using case, headers, and use of comments. All code must
follow correct syntax, but there are many different styles you
can use. Here are some suggestions: Start every program
with a comment header that has the program name and
perhaps a brief description of what the program does. Use
indentation to line things up. Function name and braces are
in column one, then use indents in multiples of 2 or 4 to
mark code chunks, things inside loops and so on.

Mark major sections or functions with a comment header


line or two, have just the right number of comments, not too
few and not too many. Assume the reader knows the
programming language so have the comment be instructive.
Here is an example of an instructive comment

digitalWrite(4,HIGH) // turn on motor


and here is a useless comment
digitalWrite(4,HIGH) // set pin 4 HIGH

You need not comment every line. In fact, commenting


every line is generally bad practice.Add the comments when
you create the code. If you tell yourself, "Oh, I'll add the
comments. when the code is finished", you will never do it.

[email protected] | Vrushabh Nawgire


Common Coding Errors
1. Forgetting the semi-colon at the end of a statement
2. Misspelling a command
3. Omitting opening or closing braces

[email protected] | Vrushabh Nawgire


Chapter
Introduction
7
to Arduino
Sensors

[email protected] | Vrushabh Nawgire


Sharp IR Range Finder

Infrared light Is
transmitted and then
reflected back From an
object. Based on the angle
of reflection, the sensor can figure out distance to that object.
Equations for Calculating range(in cm) from Voltage: Volts =
5/1024* Analog_Reading.

Common Problems And Resolutions

1. Don’t use in Direct or indirect Sunlight 2. Don’t Use


reflective objects
3. Be Sure to be within the acceptable range
4. The Linear equations don’t work below/above the
detection range
5. Wait At least 40ms Before reading the same sensor again

[email protected] | Vrushabh Nawgire


Ultrasonic Sensor

Theory:
Ultrasonic Sound is emitted and then
the sensor waits for the sound to bounce
back from an object. The Total round trip
time translates into distance, since the
speed of sound is known. To Transmit
ultrasonic sound, send a 2 μS high pulse.
Equation For calculating range(in cm) from
duration of round trip Range = Round_trip/
29 / 2

[email protected] | Vrushabh Nawgire


Common Problems And Resolutions
1. Temperature Affects the speed of sound. Take it into
account if you want a lot of accuracy.
2. Avoid Foam objects( they absorb sound waves)
3. Be Sure to be within the acceptable range
4. The Linear equations don’t work below/above the
detection range
5. Avoid Using multiple sonars at the same exact moment

[email protected] | Vrushabh Nawgire


Switch
Theory:
Pushing or sliding closes the
switch and short circuits the two
sides of the switch to each other.
Also Known as a momentary switch.
Use A 10k Resistor for pullup or
pulldown. 50mS Should be a good
value for debouncing.

[email protected] | Vrushabh Nawgire


Common Problems And Resolutions
1. Debouncing Is a major issue
2. Be Sure to use a pulldown or pullup resistor to avoid
floating
3. Be Sure to stay within your switch’s electrical limits
4. Remember To declare the switch’s pin as an input
5. Know Whether your switch is High When closed or when
open.

[email protected] | Vrushabh Nawgire


Potentiometer

Theory:
Sliding Or rotating a potentiometer
changes the resistance at the output pins.
By Inputting voltage and treating the
potentiometer (or pot) as a voltage divider
Note: Some Potentiometers have a linear
relationship between resistance and
position, others do not!

Common Problems And Resolutions


1. Many Pots do not have a linear relationship
2. Remember To set the potentiometer pin as an Input
3. Don’t Forget to connect all the pins of the pot

[email protected] | Vrushabh Nawgire


[email protected] | Vrushabh Nawgire

You might also like