Documente Academic
Documente Profesional
Documente Cultură
Chapter 1....................................................................................................................................................... 6
What is Embedded System? ..................................................................................................................... 6
Characteristics of an embedded system ................................................................................................... 6
Elements of an embedded system............................................................................................................ 7
1. Microcontroller ................................................................................................................................. 7
Application areas of embedded systems .................................................................................................. 8
Chapter 2....................................................................................................................................................... 9
Switches .................................................................................................................................................... 9
Connections .............................................................................................................................................. 9
Basic switch configurations..................................................................................................................... 10
Reversing the polarity using DPDT switches ........................................................................................... 11
Hard Wiring Connections for Robotic car using Two DPDT Switches ..................................................... 11
Chapter 3..................................................................................................................................................... 12
What are resistors ? ................................................................................................................................ 12
Different Types of Resistors .................................................................................................................... 12
Resistor Colour Code............................................................................................................................... 15
What is a Variable Resistor? ................................................................................................................... 16
............................................................................................................................................................ 16
............................................................................................................................................................ 16
Voltage Divider Circuits ........................................................................................................................... 17
Chapter 4..................................................................................................................................................... 18
Transistors ............................................................................................................................................... 18
Remembering the direction of arrow ..................................................................................................... 18
BC-547 & BC-557 ..................................................................................................................................... 19
TIP 122 & TIP 127 (Darlington Pair transistors) ...................................................................................... 19
Transistor as a switch (NPN) ................................................................................................................... 19
Transistor as a switch (PNP) .................................................................................................................... 20
Transistor as a motor driver.................................................................................................................... 20
1
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter 5..................................................................................................................................................... 21
5V Power Supply using 7805 Voltage Regulator ..................................................................................... 21
7805 Voltage Regulator Circuit ............................................................................................................... 21
Steps of conversion ................................................................................................................................. 21
Transformer ............................................................................................................................................ 22
Rectifying circuit...................................................................................................................................... 22
7805 IC .................................................................................................................................................... 22
Chapter 6..................................................................................................................................................... 24
H Bridge................................................................................................................................................... 24
Working of a H-Bridge............................................................................................................................. 25
L293 Motor Driver- H Bridge IC ............................................................................................................... 27
Chapter 7..................................................................................................................................................... 28
What is a relay?....................................................................................................................................... 28
Why is a relay used? ............................................................................................................................... 28
Relay Design ............................................................................................................................................ 29
How relay works?.................................................................................................................................... 29
Chapter 8..................................................................................................................................................... 30
Working of Optocoupler ......................................................................................................................... 30
Chapter 9..................................................................................................................................................... 31
What are capacitors ................................................................................................................................ 31
AC Capacitor Circuit ................................................................................................................................ 31
Phasor Diagram of a purely capacitive circuit......................................................................................... 32
Types of Capacitor .................................................................................................................................. 33
Chapter 10................................................................................................................................................... 36
What is a solenoid valve ?....................................................................................................................... 36
Solenoid Switching .................................................................................................................................. 37
Switching Solenoids using a Transistor ............................................................................................... 37
Chapter- 11 (Basics of Microcontroller) ...................................................................................................... 38
What is a microcontroller? ..................................................................................................................... 38
General architecture of a microcontroller .............................................................................................. 38
Read Only Memory (ROM)...................................................................................................................... 38
Program Counter..................................................................................................................................... 39
2
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Processor................................................................................................................................................. 39
Input/output ports (I/O Ports) ................................................................................................................ 39
Oscillator ................................................................................................................................................. 40
Timers/Counters ..................................................................................................................................... 40
Watchdog timer ...................................................................................................................................... 40
Power Supply Circuit ............................................................................................................................... 41
Brown out ............................................................................................................................................... 41
Serial communication ............................................................................................................................. 42
Chapter- 12 (Arduino) ................................................................................................................................. 43
What is an Arduino?................................................................................................................................ 43
Pin configuration of ATmega 328 ........................................................................................................... 43
Chapter- 13 (LED) ........................................................................................................................................ 44
Simple LED circuit.................................................................................................................................... 44
Type of LEDs ............................................................................................................................................ 44
Chapter- 14 (Basic Output Programs) ......................................................................................................... 47
// WAP to blink 8 LEDs together ............................................................................................................. 47
// WAP to make a simple home automation system that turns on a tube light, a fan and a TV all at one
go. Three appliances are switched off one after the other .................................................................... 48
// WAP to make a moving lights LED pattern with one LED moving right.............................................. 49
// WAP to make a moving lights LED pattern with one LED moving right and then left ........................ 50
//WAP to make a LED pattern in which LEDs are switched ON in increasing order and are switched OFF
in reverse order....................................................................................................................................... 51
//WAP to make a LED pattern in which two extreme LEDS glow and move inwards and outwards ..... 53
// WAP to make a robotic car dance in three different patterns ........................................................... 55
//WAP to make Diwali lights with 5 different patterns. Each pattern is repeated 5 times .................... 59
//WAP to code yet another LED pattern................................................................................................. 62
Chapter- 15(Seven Segment) ...................................................................................................................... 63
What is a seven segment display ? ......................................................................................................... 63
Interfacing with microcontroller ............................................................................................................. 63
Working with more than one display ..................................................................................................... 64
Chapter- 16 (Programs based on Seven Segment Displays) ....................................................................... 65
//WAP to make a 0 to 9 counter using a single seven segment display ................................................. 65
3
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//Program to run a counter from 0 to 99 on a 7 segment display ......................................................... 67
// WAP to control a 0-9 counter with increment and decrement switches ........................................... 70
// WAP to make a 0-999 counter on seven segments ............................................................................ 73
Chapter- 17 (Basic input output programs) ................................................................................................ 76
// WAP to make a basic robotic car ........................................................................................................ 76
// This is an improved code for a robotic car. The motors run with full thrust ...................................... 80
//WAP to solve the debounce problem .................................................................................................. 84
//WAP to make Diwali lights with 3 different patterns. Each pattern is controlled with a switch ........ 85
//WAP to make a password protected system with password:5216, if the password is correct the LED
connected to pin 0 should turn off ......................................................................................................... 89
Chapter- 18 (PWM) ..................................................................................................................................... 91
What is Pulse Width Modulation ............................................................................................................ 91
Chapter- 19 (Programs based on PWM) ..................................................................................................... 92
//WAP to increase and decrease the brightness of an LED connected to pin 3 ..................................... 92
//DC motor speed control using inbuilt PWM pin .................................................................................. 93
Chapter- 20 (RF Module 433 Mhz).............................................................................................................. 95
HT12E Encoder ........................................................................................................................................ 95
HT12D Decoder ....................................................................................................................................... 96
Block Diagram of a RF controlled Car ..................................................................................................... 97
// WAP for the receiver end of a PC controlled robotic car ................................................................... 98
//WAP for the transmitter section of a PC controlled car .................................................................... 101
Chapter- 21 (DTMF Decoder 8870) ........................................................................................................... 104
// WAP to make a GSM controlled Car/Home automation system using DTMF Decoder 8870 .......... 105
Chapter-22 (16x2 LCD) .............................................................................................................................. 109
//WAP to demonstrate the use of a LCD .............................................................................................. 110
//WAP to control a LCD using a variable resistor. The value should be printed on PC when an enter
switch is pressed ................................................................................................................................... 111
//WAP to develop a Washing machine which displays its options on PC as well as LCD ..................... 114
Chapter- 23(Servo Motors) ....................................................................................................................... 119
Controlling a servo motor ..................................................................................................................... 119
// WAP to control a servo motor using a variable resistor ................................................................... 120
Chapter- 24 (Stepper motor) .................................................................................................................... 121
4
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
What is a stepper motor? ..................................................................................................................... 121
How a stepper motor works? ............................................................................................................... 121
Stepper motor sequence ...................................................................................................................... 122
//WAP to rotate a stepper motor ......................................................................................................... 123
5
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 1 (Basics of Embedded Systems)
What is Embedded System?
An embedded system is a system that has software embedded into hardware, which makes a
system dedicated for an application (s) or specific part of an application or product or part of a
larger system. It processes a fixed set of pre-programmed instructions to control
electromechanical equipment which may be part of an even larger system (not a computer with
keyboard, display, etc).
Furthermore any machinery which has mechanical parts, electronic circuits and software can be
termed as an embedded system.
b) Efficiency is of paramount importance for embedded systems. They are optimized for
energy, code size, execution time, weight & dimensions, and cost.
c) Embedded systems are typically designed to meet real time constraints; a real time system
reacts to stimuli from the controlled object/ operator within the time interval dictated by the
environment. For real time systems, right answers arriving too late (or even too early) are
wrong.
d) Embedded systems often interact (sense, manipulate & communicate) with external world
through sensors and actuators and hence are typically reactive systems; a reactive system is in
6
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
continual interaction with the environment and executes at a pace determined by that
environment.
1. Microcontroller
Microcontrollers are single chip semi conductor device which is a computer on chip. In other
words it is a smaller version of a computer but not a complete computer. Its CPU contains an
Arithmetic & Logic Unit(ALU), a Program Counter(PC), a Stack Pointer(SP), registers, a clock and
interrupts circuit on a single chip. To make complete micro computer, one must add memory
usually ROM and RAM, memory decoder, an oscillator, a number of serial and parallel ports
A Microcontrolleris designed to cater for large amount of applications and hence is produced in
bulk. Using it in an embedded system offers various benefits. Design time is low as only
software is to be developed, no digital design is involved. Typical characteristics of a
Microcontroller are relatively high cost, high speeds, higher Power consumption, large
architecture, large memory size, onboard flash and cache, an external bus interface for greater
memory usage.
2. Software
If hardware forms the body of the embedded systems, software is a soul of embedded systems.
The software lends the functionality to an embedded system.Variety of languages has emerged
as the tasks to be performed by embedded systems are of quite diverse nature.
7
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Embedded systems interface with the physical world through Sensors and Actuators. Sensors act
as “senses” for an embedded system, whereas actuators act as “limbs”. Varieties of sensors
working on variety of sensing principles are used in embedded systems. Light, temperature,
acceleration, speed, mass, distance, etc. are common physical parameters which are sensed.
Motors are one of the actuators used in many systems.
Office Equipment
– printer, copier, fax, …
Tools
– Multimeter, oscilloscope, line tester, GPS, …
Banking
– ATMs, statement printers, …
Transportation
– (Planes/Trains/[Automobiles] and Boats)
– radar, traffic lights, signaling systems, …
8
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 2 (Switches)
Switches
A 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").
There are many
different types of
switches.
Apart from the simplest switches wherein actuator make or breaks the contact, there are some
complex switches which use some other physical stimulus. There are switches which changes
their state by sensing light/ magnetic field/temperature/pressure, etc.
Connections
Normally OPEN (NO) switches are those which remain in OFF state. On pressing the
switch, they get closed(or becomes ON).
9
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Exactly opposite Normally CLOSED (NC) switches are those which remain in ON state. On
pressing the switch, they get opened(or becomes OFF).
SPST
SPDT
DPST
Double Pole Single throw (DPST) has two separate poles but only
single throw direction. There are two movable metallic plates
which are operated together. They can be moved together in a
single direction to make contact with two corresponding fixed
metal plates.
10
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
DPDT
Hard Wiring Connections for Robotic car using Two DPDT Switches
11
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 3 (Resistors)
What are resistors ?
Resistors, ( R ) are the most fundamental and commonly used of all the electronic components,
to the point where they are almost taken for granted. There are many different Types of
Resistors available for the electronics constructor to choose from, from very small surface
mount chip resistors up to large wire wound power resistors.
Resistors are “Passive Devices“, that is they contain no source of power or amplification but
only attenuate or reduce the voltage or current signal passing through them. This attenuation
results in electrical energy being lost in the form of heat as the resistor resists the flow of
electrons through it.
There are many thousands of different Types of Resistor and are produced in a variety of forms
because their particular characteristics and accuracy suit certain areas of application, such as
High Stability, High Voltage, High Current etc, or are used as general purpose resistors where
their characteristics are less of a problem.
Some of the common characteristics associated with the resistor are; Temperature Coefficient,
Voltage Coefficient, Noise, Frequency Response, Power as well as a resistorsTemperature
Rating, Physical Size and Reliability.
Carbon Resistors are the most common type of Composition Resistors. Carbon resistors are a
cheap general purpose resistor used in electrical and electronic circuits. Their resistive element
is manufactured from a mixture of finely ground carbon dust or graphite (similar to pencil lead)
and a non-conducting ceramic (clay) powder to bind it all together.
12
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Carbon Resistor
The Carbon Composite Resistor is a low to medium type power resistor which has a low
inductance making them ideal for high frequency applications but they can also suffer from
noise and stability when hot. Carbon composite resistors are generally prefixed with
a “CR” notation (eg, CR10kΩ ) and are available in E6 ( ± 20% tolerance (accuracy) ), E12 ( ±
10% tolerance) and E24 ( ± 5% tolerance) packages with power ratings from 0.125 or 1/4 of a
Watt up to 5 Watts.
Carbon composite resistor types are very cheap to make and are therefore commonly used in
electrical circuits. However, due to their manufacturing process carbon type resistors have very
large tolerances so for more precision and high value resistances, film type resistors are used
instead.
The resistive value of the resistor is controlled by increasing the desired thickness of the
deposited film giving them the names of either “thick-film resistors” or “thin-film resistors”.
Once deposited, a laser is used to cut a high precision spiral helix groove type pattern into this
film. The cutting of the film has the effect of increasing the conductive or resistive path, a bit
like taking a long length of straight wire and forming it into a coil.
13
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Film Resistor
Metal Film Resistors have much better
temperature stability than their carbon
equivalents, lower noise and are
generally better for high frequency or
radio frequency applications. Metal
Oxide Resistors have better high surge
current capability with a much higher
temperature rating than the equivalent metal film resistors.
Metal Film Resistors are prefixed with a “MFR” notation (eg, MFR100kΩ) and a CF for Carbon
Film types. Metal film resistors are available in E24 (±5% & ±2% tolerances), E96 (±1%
tolerance) and E192(±0.5%, ±0.25% & ±0.1% tolerances) packages with power ratings of 0.05
(1/20th) of a Watt up to 1/2 Watt. Generally speaking Film resistors are precision low power
components.
14
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Resistor Colour Code
Black 0 1
Brown 1 10 ± 1%
Red 2 100 ± 2%
Orange 3 1,000
Yellow 4 10,000
Grey 8
White 9
Gold 0.1 ± 5%
15
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Example 1:What is the resistance of this resistor?
Notice that the colors on this resistor are (in order) Red, Green,
Orange, and Silver.
Yes, I know it's not proper scientific notation this way. You can also
write it as 25000 Ω
A variable resistor is a device that is used to change the resistance according to our needs in
an electronic circuit. It can be used as a three terminal as well as a two terminal device. Mostly
they are used as a three terminal device. Variable resistors are mostly used for device
calibration.
16
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
decides the motion of the track. The motion of the wiper through the track helps in increasing and
decreasing the resistance.
The resistance between point A and B is always fixed whereas the resistance between AW and
BW changes when the wiper is turned.
We can make a variable potential divider using a variable resistor. In this case we have a circuit
similar to the previous one butnow the two resistors R1 and R2 are two parts of the same
component. This isuseful for volume controls etc.
The diagram on the right shows the approximate appearance of the variable resistor on its
support. Connect a voltmeter as shown and move s (that is, turn the rheostat). Note that the
voltmeter reading varies from zero to the full voltage of the battery.
17
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 4 (Transistors)
Transistors
The terminals are called: collector (C), base (B) and emitter
(E). Voltage at a transistor terminal (relative to ground) is
indicated by a single subscript, VC is the collector voltage,
for instance. Voltage between 2 terminals is indicated by a
double subscript: VBE is base-to-emitter drop. If the same
letter is doubled, it means power supply voltage: VCC
(positive) is power supply voltage associated with the
collector and VEE (negative) is power supply voltage
associated with the emitter.
18
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
BC-547 & BC-557
BC- 547 is NPN and BC-557 is PNP
Ic = 100 mA
Ic = 8A
Transistor as a switch(NPN)
Here the transistor is working as a switch.The
base is ackting as the controlling terminal.
19
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Transistor as a switch (PNP)
Ve>Vb>Vc. When this condition is true the transistor will turn ON.
20
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 5 (Power Supply)
Steps of conversion
a) Stepping down the 220V AC supply
b) Conversion of AC to DC using rectifier
c) Smoothening of the rectified DC wave
d) Conversion of 12 DC to 5V regulated DC supply
e) Further smoothening if required
21
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Transformer
Selecting a suitable transformer is of great importance. The current rating and the secondary
voltage of the transformer is a crucial factor.
The current rating of the transformer depends upon the current required for the load to
be driven.
As a thumb rule the input voltage to the 78xx IC should be at least 1.5 times therefore
7805 requires an input voltage at least close to 7.5V.
So I chose a 12-0-12center tapped transformer with current rating 1A.
NOTE: Any transformer which supplies secondary peak voltage up to 35V can be used but as the
voltage increases size of the transformer and power dissipation across regulator increases.
Rectifying circuit
7805 IC
Voltage regulator is used to produce a constant linear
output voltage. It’s generally used with AC to
DC power supply. And also it can be used as well as
a DC to DC voltage converter. To regulating low
voltage, most used device is one single IC. 7805, 7812,
7905 etc. 78xx series are design for positive and 79xx
series are for Negative voltage regulator.
22
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Input voltage range 7V- 35V
Current rating Ic = 1A
Output voltage range VMax=5.2V ,VMin=4.8V
Automatic temperature cut off.
23
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 6( H- Bridge/ Motor Driver)
H Bridge
DC motors are really cheap and can be found very
easily. In this post we will discuss the
basic theory behind the DC motor drive system
and its speed control. Having some basic
understanding of how your motor driver works
will play a key role in building your own circuits
debugging them.
24
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Working of a H-Bridge
From the above cases you can see that the direction of current flow is reversed. Hence the
direction of rotation of the motor is also reversed. This way we are able to drive the motor in
both the directions without having to manually flipping the wires.
25
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Switches S1 through S4 are replaced with transistors Q1 through Q4. Here is what it will look
like once we are
done replacing
the mechanical
stuff with
electronics,
The 1k
ohm resistors
connected to
the base of all
the transistors
are meant for
current limiting.
The diodes connected parallel to the transistors are called free-wheeling diodes and are used to
prevent the transistors from getting damaged due the back currents (inductive) during
switching.
In the above circuit, all the transistors are NPN so they turn on if logic 1 is given to them and are
OFF when no logic or logic 0 is given. The drawbacks of this network are that there are 4 IO pins
required to drive one motor. A slight variant of this connection is shown below.
26
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
L293 Motor Driver- H Bridge IC
The IC is divided into two channels, one channel contains one motor and its control signals. So
one side of the IC (pin 1 to 8) is channel 1 and the other side (pin 9 to 16) is channel 2. You can
see that each side has an enable pin (pins 1 and 9) they are used to turn ON/OFF the control
for that channel.
The pins labeled as Motor +ve and Motor -ve (pins 3,6,11, and 14) is where the motor has to be
connected and the Logic A and Logic B (pins 2,7,10, and 15) are where the control signal to that
particular motor has to be given.
Vcc1 (pin16) is the supply for the IC and should not exceed 5V. Vcc2 (pin 8) is the supply for the
motors (high voltage high current supply). The two Vcc are internally isolated. The ground (-ve
terminal) of both the supplies (Eg., 5v for IC and 12v for motors) should be connected to the
ground pins (pins 4,5,12, and 13).
27
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter-7 (Relay)
Relay
What is a relay?
We know that most of the high end industrial application devices
have relays for their effective working. Relays are simple switches
which are operated both electrically and mechanically. Relays consist of
an electromagnet and also a set of contacts. The switching mechanism
is carried out with the help of the electromagnet. There are also other
operating principles for its working. But they differ according to their applications. Most of the
devices have the application of relays.
We may utilize a relay when we wish to control a high voltage (AC or DC) circuit with a low DC
voltage controlling signal.
28
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Relay Design
There are only four main parts in a relay. They are
Electromagnet
Movable Armature
Switch point contacts
Spring
The diagram shows an inner section diagram of a relay. An iron core is surrounded by a control
coil. As shown, the power source is given to the electromagnet through a control switch and
through contacts to the load. When current starts flowing through the control coil, the
electromagnet starts energizing and thus intensifies the magnetic field. Thus the upper contact
arm starts to be attracted to the lower fixed arm and thus closes the contacts causing a short
circuit for the power to the load. On the other hand, if the relay was already de-energized when
the contacts were closed, then the contact move oppositely and make an open circuit.
As soon as the coil current is off, the movable armature will be returned by a force back to its
initial position. This force will be almost equal to half the strength of the magnetic force. This
force is mainly provided by two factors.
29
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 8 (Optocoupler)
Working of Optocoupler
An optocoupler (or an optoelectronic coupler) is basically an interface between two circuits
which operate at (usually) different voltage levels. The key advantage of an optocoupler is the
electrical isolation between the input and output circuits. With an optocoupler, the only
contact between the input and the output is a beam of light. Because of this it is possible to
have an insulation resistance between the two circuits in the thousands of megohms. Isolation
like this is useful in high voltage applications where the potentials of two circuits may differ by
several thousand volts.
The most common industrial use of the optocouplers (or optically-coupled isolators) is as a
signal converter between high-voltage and low- voltage solid-state logic circuits. Optical
isolators can be employed in any situation where a signal must be passed between two circuits
which are isolated from each other.
30
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 9 (Capacitors)
What are capacitors
Capacitance in AC Circuits
When capacitors are connected across a direct current DC supply voltage they become charged
to the value of the applied voltage, acting like temporary storage devices and maintain or hold
this charge indefinitely as long as the supply voltage is present. During this charging process, a
charging current, ( i ) will flow into the capacitor opposing any changes to the voltage at a rate
that is equal to the rate of change of the electrical charge on the plates.
This charging current can be defined as: i = CdV/dt. Once the capacitor is “fully-charged” the
capacitor blocks the flow of any more electrons onto its plates as they have become saturated.
Hence it is said that capacitor blocks DC.
However, if we apply an alternating current or AC supply, the capacitor will alternately charge
and discharge at a rate determined by the frequency of the supply. Then the Capacitance in AC
circuits varies with frequency as the capacitor is being constantly charged and discharged.
We know that the flow of electrons through the Capacitor is directly proportional to the rate of
change of the voltage across the plates. Then, we can see that capacitors in AC circuits like to
pass current when the voltage across its plates is constantly changing with respect to time such
as in AC signals, but it does not like to pass current when the applied voltage is of a constant
value such as in DC signals. Consider the circuit below.
AC Capacitor Circuit
In the purely capacitive circuit above, the capacitor is connected directly across the AC supply
voltage. As the supply voltage increases and decreases, the capacitor charges and discharges
with respect to this change. We know that the charging current is directly proportional to the
rate of change of the voltage across the plates with this rate of change at its greatest as the
31
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
supply voltage crosses over from its positive half cycle to its negative half cycle or vice versa at
points, 0o and 180oalong the sine wave.
At 0o the rate of change of the supply voltage is increasing in a positive direction resulting in a
maximum charging current at that instant in time. As the applied voltage reaches its maximum
peak value at 90o for a very brief instant in time the supply voltage is neither increasing nor
decreasing so there is no current flowing through the circuit.
As the applied voltage begins to decrease to zero at 180o, the slope of the voltage is negative
so the capacitor discharges in the negative direction. At the 180o point along the line the rate of
change of the voltage is at its maximum again so maximum current flows at that instant and so
on.
Then we can say that for capacitors in AC circuits the instantaneous current is at its minimum or
zero whenever the applied voltage is at its maximum and likewise the instantaneous value of
the current is at its maximum or peak value when the applied voltage is at its minimum or zero.
From the waveform above, we can see that the current is leading the voltage by 1/4 cycle or
90o as shown by the vector diagram. Then we can say that in a purely capacitive circuit the
alternating voltage lags the current by 90o.
We know that the current flowing through the capacitance in AC circuits is in opposition to the
rate of change of the applied voltage but just like resistors, capacitors also offer some form of
resistance against the flow of current through the circuit, but with capacitors in AC circuits this
AC resistance is known as Reactance or more commonly in capacitor circuits, Capacitive
Reactance, so capacitance in AC circuits suffers from Capacitive Reactance.
32
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Types of Capacitor
The comparisons between the different types of capacitor are generally made with regards to
the dielectric used between the plates. Like resistors, there are also variable types of capacitors
which allow us to vary their capacitance value for use in radio or “frequency tuning” type
circuits.
Commercial types of Capacitor are made from metallic foil interlaced with thin sheets of either
paraffin-impregnated paper or Mylar as the dielectric material. Some capacitors look like tubes,
this is because the metal foil plates are rolled up into a cylinder to form a small package with
the insulating dielectric material sandwiched in between them.
Dielectric Capacitor
Dielectric Capacitors are usually of the variable type were a continuous variation of capacitance
is required for tuning transmitters, receivers and transistor radios. Variable dielectric capacitors
are multi-plate air-spaced types that have a set of fixed plates (the stator vanes) and a set of
movable plates (the rotor vanes) which move in between the fixed plates.
The position of the moving plates with respect to the fixed plates determines the overall
capacitance value. The capacitance is generally at maximum when the two sets of plates are
fully meshed together. High voltage type tuning capacitors have relatively large spacings or air-
gaps between the plates with breakdown voltages reaching many thousands of volts.
Film Capacitor
33
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
metalised paper, Teflon etc. Film type capacitors are available in capacitance ranges from as
small as 5pF to as large as 100uF is depending upon the actual type of capacitor and its voltage
rating.
Ceramic Capacitor
Electrolytic Capacitors
Electrolytic Capacitors are generally used when very large capacitance values
are required. Here instead of using a very thin metallic film layer for one of
the electrodes, a semi-liquid electrolyte solution in the form of a jelly or
paste is used which serves as the second electrode (usually the cathode).
The majority of electrolytic types of capacitors are Polarized, that is the DC voltage applied to
the capacitor terminals must be of the correct polarity, i.e. positive to the positive terminal and
negative to the negative terminal as an incorrect polarization will break down the insulating
oxide layer and permanent damage may result.
Electrolytic Capacitors are generally used in DC power supply circuits due to their large
capacitance’s and small size to help reduce the ripple voltage or for coupling and decoupling
applications. One main disadvantage of electrolytic capacitors is their relatively low voltage
rating and due to the polarization of electrolytic capacitors, it follows then that they must not
be used on AC supplies. Electrolyte’s generally come in two basic forms; Aluminum Electrolytic
Capacitors and Tantalum Electrolytic Capacitors.
34
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Tantalum Electrolytic Capacitors
Tantalum Electrolytic Capacitors and Tantalum Beads, are available in both wet (foil) and dry
(solid) electrolytic types with the dry or solid tantalum being the most common. Solid tantalum
capacitors use manganese dioxide as their second terminal and are physically smaller than the
equivalent aluminum capacitors.
The dielectric properties of tantalum oxide is also much better than those of aluminium oxide
giving a lower leakage currents and better capacitance stability which makes them suitable for
use in blocking, by-passing, decoupling, filtering and timing applications.
Also, Tantalum Capacitors although polarized, can tolerate being connected to a reverse
voltage much more easily than the aluminium types but are rated at much lower working
voltages. Solid tantalum capacitors are usually used in circuits where the AC voltage is small
compared to the DC voltage.
However, some tantalum capacitor types contain two capacitors in-one, connected negative-to-
negative to form a “non-polarised” capacitor for use in low voltage AC circuits as a non-
polarised device. Generally, the positive lead is identified on the capacitor body by a polarity
mark, with the body of a tantalum bead capacitor being an oval geometrical shape. Typical
values of capacitance range from 47nF to 470uF.
35
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter-10 (Solenoid valve)
What is a solenoid valve ?
Solenoid is a type of electromagnetic actuator that converts an electrical signal into a magnetic
field. The linear solenoid works on the same basic principal as the electromechanical relay, they
can also be switched and controlled using transistors or MOSFET’s. A “Linear Solenoid” is an
electromagnetic device that converts electrical energy into a mechanical pushing or pulling
force or motion.
Linear Solenoid
Linear solenoid’s basically consist of an electrical coil wound around a cylindrical tube with a
ferro-magnetic actuator or “plunger” that is free to move or slide “IN” and “OUT” of the coils
body.
When electrical current flows through a conductor it generates a magnetic field, and the
direction of this magnetic field with regards to its North and South Poles is determined by the
direction of the current flow within the wire. This coil of wire becomes an “Electromagnet” with
its own north and south poles exactly the same as that for a permanent type magnet.
The strength of this magnetic field can be increased or decreased by either controlling the
amount of current flowing through the coil or by changing the number of turns or loops that
the coil has.
36
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
end of the plunger. The force and speed of the plungers movement is determined by the
strength of the magnetic flux generated within the coil.
When the supply current is turned “OFF” (de-energized) the electromagnetic field generated
previously by the coil collapses and the energy stored in the compressed spring forces the
plunger back out to its original rest position. This back and forth movement of the plunger is
known as the solenoids “Stroke”, in other words the maximum distance the plunger can travel
in either an “IN” or an “OUT” direction, for example, 0 – 30mm.
Solenoid Switching
Generally solenoids either linear or rotary operate with the application of a DC voltage, but
they can also be used with AC sinusoidal voltages by using full wave bridge rectifiers to rectify
the supply which then can be used to switch the DC solenoid. Small DC type solenoids can be
easily controlled using Transistor or MOSFET switches and are ideal for use in robotic
applications.
However, as we saw previously with electromechanical relays, linear solenoids are “inductive”
devices so some form of electrical protection is required across the solenoid coil to prevent
high back emf voltages from damaging the semiconductor switching device.
37
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 11 (Basics of Microcontroller)
What is a microcontroller?
A microcontroller (sometimes abbreviated µC, uC or MCU) is a small computer on a
single integrated circuit containing a processor core, memory, and
programmable input/output peripherals. Program memory in the form of NOR flash or OTP ROM is
also often included on chip, as well as a typically small amount of RAM. Microcontrollers are
designed for embedded applications, in contrast to the microprocessors used in personal
computers or other general purpose applications.
38
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Program Counter
Program Counter is an engine running the program and points to the memory address
containing the next instruction to execute. After each instruction execution, the value of the
counter is incremented by 1. For this reason, the program executes only one instruction at a
time just as it is written. However…the value of the program counter can be changed at any
moment, which causes a “jump” to a new memory location. This is how subroutines and branch
instructions are executed. After jumping, the counter resumes even and monotonous
automatic counting +1, +1, +1…
Processor
As its name suggests, this is a unit which monitors and controls all processes within the
microcontroller and the user cannot affect its work. It consists of several smaller subunits, of
which the most important are:
39
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Oscillator
Even pulses generated by the oscillator enable harmonic and
synchronous operation of all circuits within the
microcontroller. It is usually configured as to use quartz-
crystal or ceramics resonator for frequency stabilization. It is
important to say that program instructions are not executed
at the rate imposed by the oscillator itself, but several times
slower. It happens because each instruction is executed in
several steps.
Timers/Counters
Most programs use these
miniature electronic "stopwatches"
in their operation. These are
commonly 8- or 16-bit SFRs the
contents of which are
automatically incremented by each
coming pulse. Once the register is
completely loaded, an interrupt is
generated!
Watchdog timer
The Watchdog Timer is a timer connected to a completely separate RC oscillator within the
microcontroller.
If the watchdog timer is enabled, every time it counts up to the program end, the
microcontroller reset occurs and program execution starts from the first instruction. The point
is to prevent this from happening by using a special command. The whole idea is based on the
fact that every program is executed in several longer or shorter loops.
40
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
If instructions resetting the watchdog timer are set at the appropriate program locations,
besides commands being regularly executed, then the operation of the watchdog timer will not
affect the program execution.
If for any reason (usually electrical noise in industry), the program counter "gets stuck" at some
memory location from which there is no return, the watchdog will not be cleared, so the
register’s value being constantly incremented will reach the maximum et voila! Reset occurs!
Brown out is a potentially dangerous state which occurs at the moment the microcontroller is
being turned off or when power supply voltage drops to the lowest level due to electric noise.
As the microcontroller consists of several circuits which have different operating voltage levels,
this can causeits out of control performance. In order to prevent it, the microcontroller usually
has a circuit for brown out reset built-in. This circuit immediately resets the whole electronics
when the voltage level drops below the lower limit.
Reset pin is usually referred to as Master Clear Reset (MCLR) and serves for external reset of
the microcontroller by applying logic zero (0) or one (1) depending on the type of the
microcontroller. In case the brown out is not built in the microcontroller, a simple external
circuit for brown out reset can be connected to this pin.
41
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Serial communication
Parallel connections between the
microcontroller and peripherals
established over I/O ports are the
ideal solution for shorter
distances up to several meters.
However, in other cases, when it
is necessary to establish
communication between two devices on longer distances it is obviously not possible to use
parallel connections. Then, serial communication is the best solution.
42
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 12 (Arduino)
What is an Arduino?
Arduino is an open-source platform used for building electronics projects. Arduino consists of
both a physical programmable circuit board (often referred to as a microcontroller) and a piece
of software, or IDE (Integrated Development
Environment) that runs on your computer, used to
write and upload computer code to the physical
board.
43
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 13 (LED)
A light-emitting diode (LED) is a two-lead semiconductor light source that resembles a basic pn-
junction diode, except that an LED also emits light. When an LED's anode lead has a voltage that
is more positive than its cathode lead by at least the LED's forward voltage drop, current
flows. Electrons are able to recombine with holes within the device, releasing energy in the form
of photons. This effect is called electroluminescence, and the color of the light (corresponding to
the energy of the photon) is determined by the energy band gap of the semiconductor.
Type of LEDs
1. Miniature
44
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
2. Bi-color and Tri-color
3. Alphanumeric
45
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
characters. Last is the matrix which is, obviously, the most versatile of the four. It covers the full
alphabet (both in upper case and lower case), all numbers and a full variety of symbols.
Lighting LEDs
Lighting LEDs (also referred to as LED lamps, LED bars, or
illuminators) come in many different shapes and sizes,
including the popular Edison light bulb design. As
mentioned throughout this article, heat is the enemy of
an LED. An example of ways in which manufacturers are
addressing this issue with these more commonly used
LEDs is they incorporate an aluminum/ceramic body with fins to increase the total area for heat
to escape.
46
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 14 (Basic Output Programs)
void setup()
{
//**************Code to set the mode to output **********
for(int i=0;i<8;i++)
{
pinMode(i,OUTPUT);
digitalWrite(i,LOW);
}
}
void loop()
{
//**************Code to turn ON**********
for (int i=0;i<8;i++)
{
digitalWrite (i,HIGH);
}
delay(1000);
//**************Code to turn OFF**********
for(int i=0;i<8;i++)
{
digitalWrite(i,LOW);
}
delay(1000);
}
47
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
// WAP to make a simple home automation system that turns on a tube light, a fan
and a TV all at one go. Three appliances are switched off one after the other
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void setup()
{
for(int i=2;i<5;i++)
pinMode(i,OUTPUT); // Pins 2,3 & 4 are used to connect relays(Active HIGH)
}
void loop()
{
for(int i=0;i<3;i++)
{
digitalWrite(i,LOW); // Switch ON all the three appliances
}
delay(10000);
for(int i=0;i<3;i++)
{
digitalWrite(i,HIGH); // Switch OFF three appliances one by one
delay(1000);
}
}
48
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
// WAP to make a moving lights LED pattern with one LED moving right
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void setup()
{
For (int i=0;i<8;i++)
{
pinMode(i, OUTPUT); // initialize the digital pins as an output.
// This can be done in one go using a loop.
}
}
void loop()
{
for (int i=0;i<8;i++)
{
digitalWrite(i, HIGH);
delay(200);
digitalWrite(i, LOW);
}
}
49
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
// WAP to make a moving lights LED pattern with one LED moving right and then left
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void setup()
{
for (int i=0;i<8;i++)
{
pinMode(i, OUTPUT); // initialize the digital pins as an output.
} //This can be done in one go using a loop .
}
void loop()
{
for (int i=0;i<8;i++)
{
digitalWrite(i, HIGH);
delay(200);
digitalWrite(i, LOW);
}
for (int i=7;I >=0;i--) // Execute the loop in reverse direction
{
digitalWrite(i, HIGH);
delay(200);
digitalWrite(i, LOW);
}
}
50
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//WAP to make a LED pattern in which LEDs are switched ON in increasing order and
are switched OFF in reverse order.
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void setup()
{
for (int i=0;i<8;i++)
{
pinMode(i, OUTPUT); // initialize the digital pins as an output.
}
}
void loop()
{
for (int i=0;i<8;i++)
{
digitalWrite(i, HIGH); // LEDs glow one by one
delay(800);
}
delay(1000);
51
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
delay(1000);
delay(1000);
52
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//WAP to make a LED pattern in which two extreme LEDS glow and move inwards
and outwards
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void setup()
{
for (int i=0;i<8;i++)
{
pinMode(i, OUTPUT); // initialize the digital pins as an output.
}
}
void loop()
{
int j;
j=7; // Dummy variable to enable opposite movement
// Till the time i reaches 3, j will reach 4
for (int i=0;i<=3;i++)
{
digitalWrite(i, HIGH);
digitalWrite(j, HIGH); // Make the pattern
delay(800);
j--;
}
for(int i=0;i<8;i++)
{
digitalWrite(i, LOW); //Erase the pattern
}
53
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
delay(1000);
delay(1000);
}
54
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
// WAP to make a robotic car dance in three different patterns
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
55
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
digitalWrite(m2_f,LOW);
}
void stop1() // Function to stop the car
{
for(int i=2;i<6;i++)
{
digitalWrite(i,HIGH);
}
}
void pattern1()
{
forward();
delay(2000);
stop1();
delay(2000);
backward();
delay(2000);
stop1();
delay(2000);
right();
delay(2000);
stop1();
delay(2000);
left();
delay(2000);
stop1();
delay(2000);
}
56
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
void pattern2()
{
for(int rep=0;rep<=4;rep++)
{
right();
delay(500);
stop1();
delay(2000);
left();
delay(500);
stop1();
delay(2000);
}
}
void pattern3()
{
for(int rep=0;rep<5;rep++)
{
forward();
delay(1000);
stop1();
delay(2000);
backward();
delay(1000);
stop1();
delay(2000);
}
}
57
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
void setup()
{
for (int i=2;i<6;i++)
{
pinMode(i,OUTPUT);
digitalWrite(i,HIGH); // Set all pins high initially since our H-Bridge
// Circuit is Active LOW
}
delay(5000);
}
void loop()
{
pattern1();
delay(4000) ;
pattern2();
delay(4000) ;
pattern3();
delay(4000);
}
58
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//WAP to make Diwali lights with 5 different patterns. Each pattern is repeated 5
times
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void setup()
{
for(int i=0;i<8;i++)
{
pinMode(i,OUTPUT);
digitalWrite(i,LOW); // Set all LEDs to LOW since we have connected
// LEDs in CC configuration
}
}
void loop()
{
//********************Code for Pattern 1**************
for(int j=0;j<5;j++) // Pattern is repeated five times
{
for (int i=0;i<8;i++)
{
digitalWrite (i,HIGH);
}
delay(1000);
for(int i=0;i<8;i++)
{
digitalWrite(i,LOW);
59
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
}
delay(1000);
}
60
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
digitalWrite (i,HIGH);
digitalWrite(7-i,HIGH);
delay(500);
digitalWrite (i,LOW);
digitalWrite(7-i,LOW);
}
}
61
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//WAP to code yet another LED pattern
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void setup()
{
for(int i=0;i<8;i++)
{
pinMode(i,OUTPUT);
}
}
void loop()
{
int j=4;
for(int i=0;i<4;i++)
{
digitalWrite(i,HIGH);
digitalWrite(j,HIGH);
delay(500);
j++;
}
int y=4;
for(int i=0;i<4;i++)
{
digitalWrite(i,LOW);
digitalWrite(y,LOW);
delay(500);
y++;
}
}
62
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 15(Seven Segment)
A seven segment is generally available in ten pin package. While eight pins
correspond to the eight LEDs, the remaining two pins (at middle) are common
and internally shorted. These segments come in two configurations, namely,
Common cathode (CC) and Common anode (CA). In CC configuration, the
negative terminals of all LEDs are connected to the common pins. The common is
connected to ground and a particular LED glows when its corresponding pin is given high. In CA
arrangement, the common pin is given a high logic and the LED pins are given low to display a
number.
63
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Working with more than one display
Let’s say we want to print 1234 on the display. In order to accomplish this task we would
require 4 seven segment displays. If we try to devote dedicated pins for every display, we
would require 32 I/O pins for this purpose. Here is a flow chart that will help you understand
the concept of POV.
The data lines are shared between all seven segment displays. So if you write 1 to the data bus
and enable the first segment, you will have to first step. Likewise, write 2 to data bus and
enable the second segment. Similarly do the third and fourth step. Once this cycle is finished,
repeat the step above steps at a frequency of 50 Hz (or higher if your controller has nothing
else to do).
64
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 16 (Programs based on Seven Segment Displays)
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void setup()
{
for(int i=0;i<8;i++)
{
pinMode(i,OUTPUT);
digitalWrite(i,HIGH);
}
}
void loop()
65
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
{
for (int count=0;count<10;count++)
{
for(int i=0;i<8;i++)
{
digitalWrite(i,seven_seg[count][i]); // Place the content of one
} // complete row on the pins 0-7
66
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//Program to run a counter from 0 to 99 on a 7 segment display
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
byteones_segment=8;
bytetens_segment=9;
byte counter;
bytesegment[10][8]=
{
{0,0,0,0,0,0,1,1},
{1,0,0,1,1,1,1,1},
{0,0,1,0,0,1,0,1},
{0,0,0,0,1,1,0,1},
{1,0,0,1,1,0,0,1},
{0,1,0,0,1,0,0,1},
{0,1,0,0,0,0,0,1},
{0,0,0,1,1,1,1,1},
{0,0,0,0,0,0,0,1},
{0,0,0,0,1,0,0,1}};
void setup()
{
for (int i=0;i<9;i++)
{
pinMode(i,OUTPUT);
digitalWrite(i,HIGH);
}
}
67
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
void loop()
{
int ones;
int tens; // variables to separate the value of one's digit and ten's digit
for (counter=0;counter<100;counter++)
{
ones=counter%10; // Formula to calculate the value of one's place
tens=counter/10; // Formula to calculate the value of ten's place
68
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
delay(3);
69
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
// WAP to control a 0-9 counter with increment and decrement switches
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
int sw_1=12;
int sw_2=11;
int count=0;
intseven_seg[10][8] =
{
{0,0,0,0,0,0,1,1},
{1,0,0,1,1,1,1,1},
{0,0,1,0,0,1,0,1},
{0,0,0,0,1,1,0,1},
{1,0,0,1,1,0,0,1},
{0,1,0,0,1,0,0,1},
{1,1,0,0,0,0,0,1},
{0,0,0,1,1,1,1,1},
{0,0,0,0,0,0,0,1},
{0,0,0,1,1,0,0,1}
};
void setup()
{
for(int i=0;i<10;i++)
{
pinMode(i,OUTPUT);
digitalWrite(i,HIGH);
}
70
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
pinMode(12,INPUT);
pinMode(11,INPUT);
}
void loop()
{
if (digitalRead(sw_1)==HIGH) // Increment Switch
{
delay(15);
while(digitalRead(sw_1)==HIGH);
delay(15); // Code to handle debounce problem
count++;
}
if (count>9)
{
count=9;
}
if (count<0)
{
count=0;
}
71
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
// Code to display the count
for(int i=0;i<8;i++)
{
digitalWrite(i,seven_seg[count][i]);
}
72
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
// WAP to make a 0-999 counter on seven segments
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
inti,j;
int segment[10][8]=
{
{0,0,0,0,0,0,1,1},
{1,0,0,1,1,1,1,1},
{0,0,1,0,0,1,0,1},
{0,0,0,0,1,1,0,1},
{1,0,0,1,1,0,0,1},
{0,1,0,0,1,0,0,1},
{0,1,0,0,0,0,0,1},
{0,0,0,1,1,1,1,1},
{0,0,0,0,0,0,0,1},
{0,0,0,1,1,0,0,1},
};
intgen,hun,ten,one;
void setup()
{
for(int k=0;k<12;k++)
{
pinMode(k,OUTPUT);
}
}
void loop()
73
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
{
for (i=0;i<1000;i++)
{
//***************** Calculation of hundred's place, Ten's place and one's place
inthun=i/100;
int gen=i%100;
int ten=gen/10;
int one=gen%10;
for(int rep=0;rep<50;rep++)
// Repeat a single number multiple times so as to allow smooth display
{
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH); // Switch on the hundred's segment
for(j=0;j<8;j++)
{
digitalWrite(j,segment[hun][j]);
}
delay(5);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,HIGH); // Switch on the ten's segment
for(j=0;j<8;j++)
{
digitalWrite(j,segment[ten][j]);
}
74
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
delay(5);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,LOW); // Switch on the one's segment
for(j=0;j<8;j++)
{
digitalWrite(j,segment[one][j]);
}
delay(5);
}
}
75
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 17 (Basic input output programs)
intswitch_forward=3;
intswitch_backward=4;
intswitch_right=5;
intswitch_left=6;
int m1_f=7;
int m1_b=8;
int m2_f=9;
int m2_b=10;
//************************************************************
void setup()
for(int i=3;i<7;i++)
pinMode(i,INPUT);
for(int i=7;i<11;i++)
pinMode(i,OUTPUT);
76
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//*********** Code to specify the actions that need to be taken for different switches
digitalWrite(m1_f,LOW);
digitalWrite(m1_b,HIGH);
digitalWrite(m2_f,LOW);
digitalWrite(m2_b,HIGH);
digitalWrite(m1_f,HIGH);
digitalWrite(m1_b,LOW);
digitalWrite(m2_f,HIGH);
digitalWrite(m2_b,LOW);
digitalWrite(m1_f,HIGH);
digitalWrite(m1_b,LOW);
digitalWrite(m2_f,LOW);
digitalWrite(m2_b,HIGH);
77
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
}
digitalWrite(m1_f,LOW);
digitalWrite(m1_b,HIGH);
digitalWrite(m2_f,HIGH);
digitalWrite(m2_b,LOW);
//***********************************************************************
void loop()
digitalWrite(i,HIGH);
if(digitalRead(switch_forward)==HIGH)
forward();
if(digitalRead(switch_backward)==HIGH)
backward();
78
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
}
if(digitalRead(switch_right)==HIGH)
right();
if(digitalRead(switch_left)==HIGH)
left();
//*****************************************************************
79
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
// This is an improved code for a robotic car. The motors run with full thrust
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
intswitch_forward=3;
intswitch_backward=4;
intswitch_right=5;
intswitch_left=6;
int m1_f=7;
int m1_b=8;
int m2_f=9;
int m2_b=10;
//************************************************************
void setup()
for(int i=3;i<7;i++)
pinMode(i,INPUT);
for(int i=7;i<11;i++)
pinMode(i,OUTPUT);
80
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
}
//*********** Code to specify the actions that need to be taken for different switches
digitalWrite(m1_f,LOW);
digitalWrite(m1_b,HIGH);
digitalWrite(m2_f,LOW);
digitalWrite(m2_b,HIGH);
digitalWrite(m1_f,HIGH);
digitalWrite(m1_b,LOW);
digitalWrite(m2_f,HIGH);
digitalWrite(m2_b,LOW);
digitalWrite(m1_f,HIGH);
digitalWrite(m1_b,LOW);
digitalWrite(m2_f,LOW);
digitalWrite(m2_b,HIGH);
81
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
}
digitalWrite(m1_f,LOW);
digitalWrite(m1_b,HIGH);
digitalWrite(m2_f,HIGH);
digitalWrite(m2_b,LOW);
//***********************************************************************
void loop()
digitalWrite(i,HIGH);
if(digitalRead(switch_forward)==HIGH)
forward();
while(digitalRead(switch_forward)==HIGH);
// The processor remains stuck in this loop until the user doesn't release the switch
82
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
if(digitalRead(switch_backward)==HIGH)
backward();
while(digitalRead(switch_backward)==HIGH);
if(digitalRead(switch_right)==HIGH)
right();
while(digitalRead(switch_right)==HIGH);
if(digitalRead(switch_left)==HIGH)
left();
while(digitalRead(switch_left)==HIGH);
//*****************************************************************
83
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//WAP to solve the debounce problem
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void setup()
pinMode(11,OUTPUT);
digitalWrite(11,LOW);
pinMode(12,INPUT);
digitalWrite(12,LOW);
int a=0;
void loop()
if(digitalRead(12)==HIGH)
delay(15);
digitalWrite(11,a);
84
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//WAP to make Diwali lights with 3 different patterns. Each pattern is controlled
with a switch
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void pattern1()
digitalWrite (i,HIGH);
delay(1000);
for(int i=0;i<8;i++)
digitalWrite(i,LOW);
delay(1000);
85
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
void pattern2()
digitalWrite (i,HIGH);
delay(500);
digitalWrite(i,LOW);
void pattern3()
for(int i=7;i>=0;i--)
digitalWrite(i,HIGH);
delay(500);
digitalWrite(i,LOW);
86
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
}
void setup()
for(int i=0;i<8;i++)
pinMode(i,OUTPUT);
for(int i=8;i<=12;i++)
pinMode(i,INPUT);
void loop()
if(digitalRead(8)==HIGH)
pattern1();
87
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
if(digitalRead(9)==HIGH)
pattern2();
if(digitalRead(10)==HIGH)
pattern3();
for(int i=0;i<8;i++)
digitalWrite(i,LOW);
88
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//WAP to make a password protected system with password:5216, if the password is
correct the LED connected to pin 0 should turn off
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
int b=0,c=0,d=0;
void setup()
pinMode(0,OUTPUT);
digitalWrite(0,HIGH);
for(int i=1;i<7;i++)
pinMode(i,INPUT);
void loop()
if(digitalRead(5)==HIGH)
delay(15);
while(digitalRead(5)==HIGH);
delay(15);
b=1;
89
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
if(digitalRead(2)==HIGH && b==1)
delay(15);
while(digitalRead(2)==HIGH);
delay(15);
c=1;
delay(15);
while(digitalRead(1)==HIGH);
delay(15);
d=1;
delay(15);
while(digitalRead(6)==HIGH);
delay(15);
digitalWrite(0,LOW);
while(1);
90
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 18 (PWM)
91
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 19 (Programs based on PWM)
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void setup()
{
pinMode(3,OUTPUT);
}
void loop()
{
for(int value=0;value<256;value++)
{
analogWrite(3,value);
delay(50);
}
for(int value=255;value>=0;value--)
{
analogWrite(3,value);
delay(50);
}
}
92
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//DC motor speed control using inbuilt PWM pin
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void setup()
{
for(int i=2;i<6;i++)
{
pinMode(i,INPUT);
}
pinMode(9,OUTPUT);
}
// Functions to vary the speed of the motor according to the switch pressed
// Please note that the H Bridge circuit we are using is active low so 255 corresponds to the
minimum speed and 0 corresponds to maximum speed
void gear1()
{
analogWrite(9,200); // Slowest speed
while(digitalRead(2)==HIGH); // Stay here until the switch is released
}
void gear2()
{
analogWrite(9,150);
while(digitalRead(3)==HIGH); // Stay here until the switch is released
}
void gear3()
{
analogWrite(9,75);
93
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
while(digitalRead(4)==HIGH); // Stay here until the switch is released
}
void gear4()
{
analogWrite(9,0); // Fastest speed
while(digitalRead(5)==HIGH); // Stay here until the switch is released
void loop()
{
digitalWrite(9,HIGH); // To turn OFF the motor
if(digitalRead(2)==HIGH)
{
gear1();
}
if(digitalRead(3)==HIGH)
{
gear2();
}
if(digitalRead(4)==HIGH)
{
gear3();
}
if(digitalRead(5)==HIGH)
{
gear4();
}
}
94
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 20 (RF Module 433 Mhz)
HT12E Encoder
The next IC is HT12E. The HT12E is an encoder. It converts digital signals into suitable form to be
transmitted through EM signals. It is an 8-bit Encoder. The HT12E is usually used for 433 MHz
wireless modules. It is an 18 leg IC.
95
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Osc1: 2 – these pins are the oscillator input and output pins. For the ordinary circuit,
they are connected to each other with the help of an external resistor.
TE – this is the transmission enable pin. When this is given true, then data transmission
starts.
Output – this is an output pin. The data in EM signals is given out from this pin.
AD0: 3 – these are the data/address pins.
Note - How does a transmitter know to which receiver it has to send the signal to? It depends on
the configuration of the address pins on Both the ICs. For the Tx-Rx pair to work, they should
have the same configuration of the address pins.The address pins can either be grounded, or can
be given Vcc individually. So the corresponding pins on the Tx and Rx have to have the same
configuration.
You can also use a gamepad for the inputs. Remember, gamepads are designed to be active low
in configuration i.e. when you press a key in the gamepad, it sends out ‘0’ and when left
floating, it gives ‘1’.
HT12D Decoder
The next IC is HT12D. The HT12D is a decoder. It decodes signals into suitable form to be
transmitted through EM signals. It is an 8-bit Encoder. The HT12D is usually used for 433 MHz
wireless modules. It is an 18 leg IC.
96
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
3. VDD – the VCC pin is where we need to supply the input voltage for the working of the
encoder. It is used to power the IC.
4. Osc1: 2 – these pins are the oscillator input and output pins. For the ordinary circuit,
they are connected to each other with the help of an external resistor.
5. DIN – this is the Data input pin. The data input from the receiver module is fed in this
pin.
6. VT – this is an output pin. This pin gives the output as soon as any signal s received by
the receiver.
7. D8: 11 – these are the data pins.
Transmitter
Receiver
97
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
// WAP for the receiver end of a PC controlled robotic car
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
intarsh[4];
int m1_f=6;
int m1_b=7;
int m2_f=8;
int m2_b=9;
void stop1() // Function for moving forward
{
digitalWrite(m1_f,HIGH);
digitalWrite(m2_f,HIGH);
digitalWrite(m1_b,HIGH);
digitalWrite(m2_b,HIGH);
}
98
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
void right() // Function for moving right
{
digitalWrite(m1_f,LOW);
digitalWrite(m2_b,LOW);
}
void setup()
{
for(int i=2; i<6;i++)
{
pinMode(i,INPUT);
}
void loop()
{
for(int i=0; i<4;i++)
{
arsh[i]=digitalRead(i+2);
99
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
}
int sum=0;
sum =(arsh[0]*8) + (arsh[1]*4) +(arsh[2]*2) +(arsh[3]*1);
//Simplifying the process ofrecognition of the action to be taken
if (sum==1)
{
forward();
}
if (sum==2)
{
backward();
}
if (sum==3)
{
right();
}
if (sum==4)
{
left();
}
if (sum==15)
{
stop1();
}
}
100
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//WAP for the transmitter section of a PC controlled car
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
}
intspiderman; // Dummy variable to store the serial input data
void loop()
{
if (Serial.available())
{
spiderman=Serial.read();
}
if(spiderman== 'f')
{
101
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
for(int i=0;i<4;i++)
{
digitalWrite(i+2,arsh[0][i]); // transmit row number zero of the array when
} //'f' is pressed on the keyboard
}
if(spiderman== 'b')
{
for(int i=0;i<4;i++)
{
digitalWrite(i+2,arsh[1][i]); //transmit row number one of the array
} // when 'b' is pressed on the keyboard
}
if(spiderman== 'r')
{
for(int i=0;i<4;i++)
{
digitalWrite(i+2,arsh[2][i]); //transmit row number two of the array when
} //'r' is pressed on the keyboard
}
if(spiderman== 'l')
{
for(int i=0;i<4;i++)
{
digitalWrite(i+2,arsh[3][i]); //transmit row number three of the array
} // when 'l' is pressed on the keyboard
102
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
if(spiderman== 'M')
{
for(int i=0;i<4;i++)
{
digitalWrite(i+2,arsh[4][i]);
}
}
}
103
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 21 (DTMF Decoder 8870)
When a key is being pressed on the matrix keypad, it generate a unique tone consisting of two
audible tone frequency. For example, if the key '1' is being press on the phone, the tone you
hear is actually consist of a 697hz & 1209hz sine signal. Pressing key '9' will generate the tone
form by 852hz& 1477hz. The frequency use in the dial tone system is of audible range suitable
for transmission over the telephone cable.
Q4 Q3 Q2 Q1
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
0 1010
* 1011
# 1100
A 1101
B 1110
C 1111
D 0000
104
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
// WAP to make a GSM controlled Car/Home automation system using DTMF
Decoder 8870
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
intbinary_data_from_DTMF[4]={0,0,0,0};
int sum=0; // To convert the binary data to decimal equivalent
int m1_f=4;
int m1_b=5;
int m2_f=6;
int m2_b=7;
105
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
void left() // function for moving the car left
{
digitalWrite(m1_b,LOW);
digitalWrite(m2_f,LOW);
delay(500);
}
//************************* Code for stopping the motors
void stop1()
{
for(int i=4;i<8;i++)
{
digitalWrite(i,HIGH);
}
}
void setup()
{
for(int i=0;i<4;i++)
{
pinMode(i,INPUT); // Connect the binary data lines of 8870 to these pins
}
for(int i=4;i<8;i++)
{
pinMode(i,OUTPUT); // Connect H- Bridges to these pins
digitalWrite(i,HIGH);
}
}
106
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
void loop()
{
//****************** Code to store the data from DTMF in an array
for(int i=0;i<4;i++)
{
binary_data_from_DTMF[i]=digitalRead(i);
}
//***************** Code for taking the necessary action based on the input
if (sum==1)
{
forward();
}
if (sum==2)
{
backward();
}
if (sum==3)
{
right();
}
if (sum==4)
107
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
{
left();
}
if (sum== 10)
{
stop1();
}
}
108
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter-22 (16x2 LCD)
Pin Configuration
This LCD has two registers, namely, Command and Data.
109
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//WAP to demonstrate the use of a LCD
#include <LiquidCrystal.h>
void setup()
optimus.begin(16,2);
void loop()
for(intnum=0;num<5;num++)
optimus.setCursor(0,0);
optimus.print("Meharban Singh");
optimus.setCursor(0,1);
delay(500);
optimus.clear();
optimus.home();
optimus.print("To");
optimus.setCursor(0,1);
optimus.print("OPTIMUS Labs");
delay(500);
optimus.clear();
110
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//WAP to control a LCD using a variable resistor. The value should be printed on PC
when an enter switch is pressed
#include <LiquidCrystal.h>
int flag=0; // A dummy flag variable to help us in passing valu from one block of code to another
void setup()
pinMode(8,INPUT);
void loop()
//************ Code to decide the value to be printed according to the analog input
optimus.clear();
optimus.setCursor(2,0);
optimus.setCursor(8,1);
optimus.print("CAKES");
flag=1;
111
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
optimus.setCursor(2,0);
optimus.setCursor(6,1);
optimus.print("PASTRIES");
flag=2;
optimus.setCursor(2,0);
optimus.setCursor(6,1);
optimus.print("BROWNIES");
flag=3;
optimus.setCursor(2,0);
optimus.setCursor(6,1);
optimus.print("BISCUITS");
flag=4;
112
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//************** Code to print the selected value over the serial monitor
if(digitalRead(8)==HIGH)
if(flag==1)
Serial.print("CAKES");
if(flag==2)
Serial.print("PASTRIES");
if(flag==3)
Serial.print("BROWNIES");
if(flag==4)
Serial.print("BISCUITS");
delay(200);
113
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//WAP to develop a Washing machine which displays its options on PC as well as LCD
int flag_1=0;
int time_1=1000;
int value=256;
#include <LiquidCrystal.h>
LiquidCrystaloptimus(12,11,5,4,3,2);
void setup()
Serial.begin(9600);
optimus.begin(16,2);
void loop()
optimus.setCursor(0,0);
optimus.print("Enter mode");
Serial.println("Enter mode");
optimus.setCursor(0,1);
optimus.print("Light");
Serial.println("Light");
optimus.setCursor(6,1);
optimus.print("Normal");
Serial.println("Normal");
114
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
optimus.setCursor(13,1);
optimus.print("Hvy");
Serial.println("Heavy");
flag_1=1;
if(Serial.available())
int data;
data=Serial.read();
data = data-48;
if(data == 1)
time_1=2000;
optimus.clear();
optimus.setCursor(0,0);
washing();
optimus.clear();
digitalWrite(9,HIGH);
115
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
if(data == 2)
time_1=3000;
value=200;
optimus.clear();
optimus.setCursor(0,0);
washing();
optimus.clear();
digitalWrite(9,HIGH);
if(data == 3)
time_1=4000;
value=100;
optimus.clear();
optimus.setCursor(0,0);
washing();
optimus.clear();
digitalWrite(9,HIGH);
116
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
flag_1=0;
else
void washing()
Serial.write("Soaking");
optimus.setCursor(0,1);
optimus.print("Soaking");
digitalWrite(9,HIGH);
delay(time_1);
Serial.write("washing");
optimus.setCursor(0,1);
optimus.print("Washing ");
analogWrite(9,value/2);
delay(time_1);
Serial.write("Rinsing");
optimus.setCursor(0,1);
optimus.print("Rinsing ");
analogWrite(9,value/4);
delay(time_1);
117
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Serial.println("Spining");
optimus.setCursor(0,1);
optimus.print("Spining ");
analogWrite(9,value/8);
delay(time_1);
118
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 23(Servo Motors)
The servo control pulse is repeated every 20 milliseconds. In essence, every 20 milliseconds you
are telling the servo, “go here.”
119
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
// WAP to control a servo motor using a variable resistor
#include <Servo.h>
void setup()
void loop()
flexSensor = map(flexSensor, 330, 570, 179, 0); // scale it to use it with the servo
120
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Chapter- 24 (Stepper motor)
121
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
Stepper motor sequence
122
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
//WAP to rotate a stepper motor
// Coded at Optimus Research Labs Pvt. Ltd., By Meharban Singh at Pitampura. Contact :
9717663142
int in_1 =8; // Allot the pins that are to be connected to 4 windings of motor
void setup()
pinMode(i,OUTPUT);
digitalWrite(in_1,HIGH);
digitalWrite(in_2,HIGH);
void loop()
digitalWrite(in_2,HIGH);
123
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142
delay(t);
digitalWrite(in_1,LOW);
digitalWrite(in_2,LOW);
digitalWrite(in_3,HIGH);
delay(t);
digitalWrite(in_2,LOW);
digitalWrite(in_3,LOW);
digitalWrite(in_4,HIGH);
delay(t);
digitalWrite(in_3,LOW);
digitalWrite(in_4,LOW);
digitalWrite(in_1,HIGH);
delay(t);
digitalWrite(in_4,LOW);
digitalWrite(in_1,LOW);
124
Optimus Research Labs Pvt Ltd, Pitampura, M: 9717663142