Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CHAPTER-1
INTRODUCTION
Swarm robotics is a new approach to the coordination of multi-robot system
which consist of large numbers of mostly simple physical robot. It is supposed that a
desired collective behavior emerges from the interactions between the robots and interactions
of robots with the environment. This approach emerged on the field of artificial swarm
intelligence, as well as the biological studies of insects, ants and other fields in nature,
where swarm behavior occurs.
Swarm intelligence:
SI (Swarm Intelligence) systems are typically made up of a population of
simple agents interacting locally with one another and with their environment. The
inspiration often comes from nature, especially biological systems. The agents follow very
simple rules, and although there is no centralized control structure dictating how individual
agents should behave, local, and to a certain degree random, interactions between such agents
lead to the emergence of intelligent global behavior, unknown to the individual agents.
Swarm robotics:
Swarm robotics is a relatively new field that focuses on controlling largescale homogeneous multi-robot systems. These systems are used to develop useful macrolevel behaviors while being made of modules that are very simple in design and compact in
size. These properties allow robot swarms to reach populations ranging from a dozen
modules to hundreds of modules. The theme of simplicity and elegance resonates throughout
swarm robotics research in both the designs of the robots as well as the algorithms that are
devised for these systems.
1.1 Objectives:
1.1.1 Goals:
Both miniaturization and cost are key-factors in swarm robotics. These are
the constraints in building large groups of robotics; therefore the simplicity
of the individual team member should be emphasized.
A lot of research has been put into achieving this goal of simplicity at the
individual robot level. Being able to use actual hardware in research of
Swarm Robotics in place of simulations allows researchers to come across
and resolve a lot more issues and thus, broadens the scope of Swarm
Research greatly.
The goals of these projects is manifold, including but not limited to keeping
the cost of individual robots low in order to be able to make the swarms
scale-able, making each member of the swarm less demanding in terms of
resources and making them more power/energy efficient. One such system
of swarm is the LIBOT Robotic System that involves a low cost robot built
for outdoor swarm robotics. The robots are also made to have enough
provisions for indoor use via Wi-Fi, since the GPS sensors provide poor
communication inside buildings. Another example of such an attempt is the
micro robot (Colias), built in the Computer Intelligence Lab at the
University of Lincoln, UK. This micro robot is built on a 4 cm circular
Page 1
1.1.2
chassis and is low-cost and open platform for use in a variety of Swarm
Robotics applications.
Functionalities:
It can be switched to master and slave mode.
Slave robots works on the commands which are transmitted by
the master robot.
Abstacle avoidance.
1.2 Requirements:
1. Requires a microcontroller to control all the actions.
2. A master communication module to send commands and to receive
information to monitor their presence.
3. Slave communication module to send its availability.
4. Communication medium.
5. Slider switch setup.
6. Push button setup.
7. RF communication medium.
8. Power supply system.
Page 2
CHAPTER-2
REQUIREMENT ANALYSIS
Introduction:
Communication Technology:
Microcontroller definition:
The important features that every microcontroller must have are as following:
1. Size of CPU.
2. Frequency of operation.
3. Power consumption.
4. Required interfacing features.
5. Number of input and output pins.
Requirements of the designs are
6. Less power consumption.
7. Portability.
8. Speed in operation.
9. Less complex design.
10. Small in size.
Dept of ECE, NCET
Page 3
There are many microcontrollers available in the market like ARM microcontroller,
PIC microcontroller, 8051 microcontroller and AVR microcontroller. But for swarm
robotics we are using the microcontroller from AVR family i.e., ATMEGA-16
microcontroller.
Size of the memory is 16K bytes.
32 programmable input & output lines.
Operating voltage ranges from 4.5V-5.5V.
Speed of the microcontroller is 0-16MHZ.
Power consumption:
Active : 1.1mA.
Idle mode : 0.35mA.
Power mode down: <1A.
2.1.1 Main features of 8051, AVR, ARM and PIC microcontroller:
8051 Microcontroller: 8051 needs external 3Mhz clock and reset to be
connected.8051 has no internal ADC .
AVR microcontroller: AVR controller contains internally 1MHz of clock and
external clock can also be connected. Has inbuilt PWM signal. And has inbuilt 8
channel ADC.
ARM Microcontroller: ARM microcontroller has low power i.e., 3.3V.
PIC Microcontroller: PIC microcontroller has inbuilt library and has background
code.
2.2 Motor driver:
A motor driver is required to run the robot. We are using L239D motor driver.
L293D is a dual H-bridge motor driver integrated circuit (IC). Motor drivers act as current
amplifiers since they take a low-current control signal and provide a higher-current signal.
This higher current signal is used to drive the motors.
L293D contains two inbuilt H-bridge driver circuits. In its common mode of operation, two
DC motors can be driven simultaneously, both in forward and reverse direction. The motor
operations of two motors can be controlled by input logic at pins 2 & 7 and 10 & 15. Input
Page 4
logic 00 or 11 will stop the corresponding motor. Logic 01 and 10 will rotate it in clockwise
and anticlockwise directions, respectively.
Enable pins 1 and 9 (corresponding to the two motors) must be high for motors to start
operating. When an enable input is high, the associated driver gets enabled. As a result, the
outputs become active and work in phase with their inputs. Similarly, when the enable input
is low, that driver is disabled, and their outputs are off and in the high-impedance state.
Pin No
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Function
Enable pin for Motor 1; active high
Input 1 for Motor 1
Output 1 for Motor 1
Ground (0V)
Ground (0V)
Output 2 for Motor 1
Input 2 for Motor 1
Supply voltage for Motors; 9-12V (up
Enable pin for Motor 2; active high
Input 1 for Motor 1
Output 1 for Motor 1
Ground (0V)
Ground (0V)
Output 2 for Motor 1
Input2 for Motor 1
Supply voltage; 5V (up to 36V)
Page 5
Slide switches are one of the most common switches used in electrical
devices. Compact sized and operable with only a finger, slide switches are important as their
absence can render the device useless in absence of the capability to switch ON and OFF
without having to pull the mains cord. It is uncanny to list all the applications where slide
switch is used. From electrical chimneys to hand blender in the kitchen, from lamp to the toy
car in the living room, slide switches are almost omni present.We are used to see switches
and use it as a black box.
2.5 Software:
To proceed with above selected components, there is a need of softwares to
simulate, debug the code. For that we require a very good debugging tool which is easy to
understand and easy to work out.
Here we use following software to stimulate the code and debug the
software. We use:
1. Proteus
2. AVR studio -4.
1. AVR Studio-4:
AVR studio-4 is a software used to code the program as required from the
function of our application. Coding the program in AVR studio-4 is very easy to write and
also very easy to understand. The code can be understand easily by anyone.
Page 6
2.Proteus:
Proteus is a software used for real time stimulation. In proteus we get all the
components which are required for the stimulation of our application.
CHAPTER-3
SYSTEM OVERVIEW
Introduction:
Swarm robot means group of robots communicating with each other and
working on one particular goal together. The group of robots working on one particular goal
on the instructions of on master robot. The robots are divided in two modes one robot will
be in master mode and other will be in slave mode. All the slave robots works according to
the instruction of master robot.
The components required to build Swarm robots are a ATMEGA-16 Microcontroller, L239D
motor driver,HT12E(encoder which is at transmitter side),HT12D decoder(which will be at
receiver side), transmitter and receiver module, LEDs, Push button, Slider switch etc.
Power supply
Page 7
Sensors
MICROCONTROLLER
(ATMEGA16)
RF Transmitter
Mode select
(Master and
Slave)
RF Receiver
Page 8
Page 9
Description
Alternate Function
T0: Timer0 External Counter Input.
(XCK/T0)
PB0
(T1) PB1
(INT2/AIN0)
I/O PORTB, Pin 2
PB2
(OC0/AIN1)
PB3
(SS) PB4
(MOSI) PB5
(MISO) PB6
(SCK) PB7
RESET
10
Vcc
Vcc = +5V
11
GND
GROUND
12
XTAL2
13
XTAL1
14
(RXD) PD0
15
(TXD) PD1
16
(INT0) PD2
17
(INT1) PD3
18
(OC1B) PD4
19
(OC1A) PD5
20
(ICP) PD6
21
PD7 (OC2)
22
PC0 (SCL)
23
PC1 (SDA)
TWI Interface
Page 10
24
PC2 (TCK)
25
PC3 (TMS)
26
PC4 (TDO)
27
PC5 (TDI)
28
PC6
(TOSC1)
29
PC7
(TOSC2)
30
AVcc
31
GND
GROUND
32
AREF
33
PA7 (ADC7)
ADC Channel 7
34
PA6 (ADC6)
ADC Channel 6
35
PA5 (ADC5)
ADC Channel 5
36
PA4 (ADC4)
ADC Channel 4
37
PA3 (ADC3)
ADC Channel 3
38
PA2 (ADC2)
ADC Channel 2
39
PA1 (ADC1)
ADC Channel 1
40
PA0 (ADC0)
ADC Channel 0
JTAG Interface
Page 11
Page 12
The Power-down mode saves the register contents but freezes the Oscillator, disabling all
other chip functions until the next External Interrupt or Hardware Reset. In Power-save mode,
the Asynchronous Timer continues to run, allowing the user to maintain a timer base while
the rest of the device is sleeping. The ADC Noise Reduction mode stops the CPU and all I/O
modules except Asynchronous Timer and ADC, to minimize switching noise during ADC
conversions. In Standby mode, the crystal/resonator Oscillator is running while the rest of the
device is sleeping. This allows very fast start-up combined with low-power consumption. In
Extended Standby mode, both the main Oscillator and the Asynchronous Timer continue to
run. The device is manufactured using Atmels high density nonvolatile memory technology.
The Onchip ISP Flash allows the program memory to be reprogrammed in-system through an
SPI serial interface, by a conventional nonvolatile memory programmer, or by an On-chip
Boot program running on the AVR core. The boot program can use any interface to download
the application program in the Application Flash memory. Software in the Boot Flash section
will continue to run while the Application Flash section is updated, providing true ReadWhile-Write operation. By combining an 8-bit RISC CPU with In-System SelfProgrammable Flash on a monolithic chip, the Atmel ATmega16 is a powerful
microcontroller that provides a highly-flexible and cost-effective solution to many embedded
control applications. The ATmega16 AVR is supported with a full suite of program and
system development tools including: C compilers, macro assemblers, program
debugger/simulators, in-circuit emulators, and evaluation kits.
VCC: Digital supply voltage.
GND :Ground.
Port A (PA7..PA0): Port A serves as the analog inputs to the A/D Converter. Port A also serves
as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins can provide
internal pull-up resistors (selected for each bit). The Port A output buffers have symmetrical
drive characteristics with both high sink and source capability. When pins PA0 to PA7 are
used as inputs and are externally pulled low, they will source current if the internal pull-up
resistors are activated. The Port A pins are tri-stated when a reset condition becomes active,
even if the clock is not running.
Port B (PB7..PB0): Port B is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port B output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port B pins that are externally pulled low will
source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset
condition becomes active, even if the clock is not running.
Port C (PC7..PC0): Port C is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port C output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port C pins that are externally pulled low will
source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset
condition becomes active, even if the clock is not running. If the JTAG interface is enabled,
the pull-up resistors on pins PC5(TDI), PC3(TMS) and PC2(TCK) will be activated even if a
reset occurs. Port D (PD7..PD0): Port D is an 8-bit bi-directional I/O port with internal pullup resistors (selected for each bit). The Port D output buffers have symmetrical drive
characteristics with both high sink and source capability. As inputs, Port D pins that are
Page 13
externally pulled low will source current if the pull-up resistors are activated. The Port D pins
are tri-stated when a reset condition becomes active, even if the clock is not running.
RESET: Reset Input. A low level on this pin for longer than the minimum pulse length will
generate a reset, even if the clock is not running. The minimum pulse length is given in Table
15 on page 38. Shorter pulses are not guaranteed to generate a reset.
XTAL1: Input to the inverting Oscillator amplifier and input to the internal clock operating
circuit. XTAL2 :Output from the inverting Oscillator amplifier.
AVCC: AVCC is the supply voltage pin for Port A and the A/D Converter. It should be
externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be
connected to VCC through a low-pass filter.
AREF: AREF is the analog reference pin for the A/D Converter
Page 14
devices are designed to drive inductive loads such as relays, solenoids, dc and bipolar
stepping motors, as well as other high-current/high-voltage loads in positive-supply
applications. All inputs are TTL compatible. Each output is a complete totem-pole drive
circuit, with a Darlington transistor sink and a pseudo Darlington source. Drivers are enabled
in pairs, with drivers 1 and 2 enabled by 1,2EN and drivers 3 and 4 enabled by 3,4EN. When
an enable input is high, the associated drivers are enabled, and their outputs are active and in
phase with their inputs. When the enable input is low, those drivers are disabled, and their
outputs are off and in the high-impedance state. With the proper data inputs, each pair of
drivers forms a full-H (or bridge) reversible drive suitable for solenoid or motor applications
The driver IC L293D is quad push-pull drivers capable of delivering output currents to 1A
per channel respectively. Each channel is controlled by a TTL-compatible logic input and
each pair of drivers (a full bridge) is equipped with an inhibit input available at pin 1 and pin
9. The motor will run only when chip inhibit is at high logic i.e. chip inhibit is enabled. The
connection diagram is shown below:
Page 15
HT12E has a transmission enable pin which is active low. When a trigger signal is received
on TE pin, the programmed addresses/data are transmitted together with the header bits via an
RF or an infrared transmission medium. HT12E begins a 4-word transmission cycle upon
receipt of a transmission enable. This cycle is repeated as long as TE is kept low. As soon as
TE returns to high, the encoder output completes its final cycle and then stops.
Page 16
Pin No
Function
1
2
3
4
5
6
7
8
9
Ground (0V)
10
11
12
13
14
15
Oscillator input
16
Oscillator output
17
18
Page 17
In simple terms, HT12D converts the serial input into parallel outputs. It decodes the
serial addresses and data received by, say, an RF receiver, into parallel data and sends them to
output data pins. The serial input data is compared with the local addresses three times
continuously. The input data code is decoded when no error or unmatched codes are found. A
valid transmission in indicated by a high signal at VT pin.
HT12D is capable of decoding 12 bits, of which 8 are address bits and 4 are data bits. The
data on 4 bit latch type output pins remain unchanged until new is received.
Page 18
PIN DESCRIPTION :
Pin No
Function
1
2
3
4
5
6
7
8
9
Ground (0V)
10
11
12
13
14
15
Oscillator output
16
Oscillator input
17
18
Page 19
Page 20
CHAPTER-4
DESIGN AND IMPLEMENTATION
Introduction:
In previous chapter we discussed about the components which are required for the design of
swarm robots. But only selecting components is not enough, the interfacing each and every
component should be done very carefully, interfacing enhances the project. In this chapter we
interface and connect the components with each other. After designing we write the required
code or program for our project by using AVR studio-4 according to our need. For testing our
project we use Proteus for stimulation.
4.1 Design:
Page 21
Input 1
Input 2
Direction of DC Motor
Stop
Anti-Clockwise
Clockwise
Stop
12V, 1A DC Adapter-1pc
DC Motor Driver-1pc
1 to 1 Connector-1pc
Robot-1pc
Softwares Required:
AVR Studio 4
WinAVR -2010
USBasp Driver
Page 22
Circuit Diagram:
Circuit diagram showing connections from ATMEGA 16 to motors through L293D motor
driver.
Connection Guide:
The step-by-step connection guide for L293D based DC Motor Driver Interfacing with
ATmega16 in 5V Mode project is as follows:
Insert the DC Pin of 12V, 1A DC Adapter to the DC Socket of AVR Trainer Board-100.
Connect PortB header of AVR Trainer Board-100 with Input header of DC Motor Driver
with a 10 to 10 FRC Female Connector.
Page 23
Connect the 12V pin of PWM & Motor Voltage header of DC Motor Driver with the 12V
header of AVR Trainer Board-100 with a 1 to 1 Connector.
Connect the Robot connector to the Output header of the DC Motor Driver.
Connect the ISP header of AVR Trainer Board-100 with AVR USB Programmer header of
AVR USB Programmer with a 10 to 10 FRC Female Connector.
Connect the AVR USB Programmer to the PC/Laptops USB Port directly or with the help
of USB AM-FM Cable.
Switch on the power with the help of Power Switch of AVR Trainer Board-100.
Download the L293D based DC Motor Driver Interfacing with ATmega16 in 5V Mode
Hex file to AVR Trainer Board-100 with the help of SinaProg Hex downloader and AVR
USB Programmer.
4.1.2.1 Description :
This radio frequency (RF) transmission system employs Amplitude Shift
Keying (ASK) with transmitter/receiver (Tx/Rx) pair operating at 434 MHz. The transmitter
module takes serial input and transmits these signals through RF. The system allows one way
communication between two nodes, namely, transmission and reception. The RF module has
been used in conjunction with a set of four channel encoder/decoder ICs. Here HT12E &
HT12D have been used as encoder and decoder respectively. The encoder converts the parallel
inputs (from the remote switches) into serial set of signals. These signals are serially
transferred through RF to the reception point. The decoder is used after the RF receiver to
decode the serial format and retrieve the original signals as outputs. These outputs can be
observed on corresponding LEDs.
Dept of ECE, NCET
Page 24
Encoder IC (HT12E) receives parallel data in the form of address bits and control bits. The
control signals from remote switches along with 8 address bits constitute a set of 12 parallel
signals. The encoder HT12E encodes these parallel signals into serial bits. Transmission is
enabled by providing ground to pin14 which is active low. The control signals are given at
pins 10-13 of HT12E. The serial data is fed to the RF transmitter through pin17 of HT12E.
Transmitter, upon receiving serial data from encoder IC (HT12E), transmits it wirelessly to
the RF receiver. The receiver, upon receiving these signals, sends them to the decoder IC
(HT12D) through pin2. The serial data is received at the data pin (DIN, pin14) of HT12D. The
decoder then retrieves the original parallel format from the received serial data.
When no signal is received at data pin of HT12D, it remains in standby mode and consumes
very less current (less than 1A) for a voltage of 5V. When signal is received by receiver, it is
given to DIN pin (pin14) of HT12D. On reception of signal, oscillator of HT12D gets
activated. IC HT12D then decodes the serial data and checks the address bits three times. If
these bits match with the local address pins (pins 1-8) of HT12D, then it puts the data bits on
its data pins (pins 10-13) and makes the VT pin high. An LED is connected to VT pin (pin17)
of the decoder. This LED works as an indicator to indicate a valid transmission. The
corresponding output is thus generated at the data pins of decoder IC. A signal is sent by
lowering any or all the pins 10-13 of HT12E and corresponding signal is received at receivers
end (at HT12D). Address bits are configured by using the by using the first 8 pins of both
encoder and decoder ICs. To send a particular signal, address bits must be same at encoder
and decoder ICs. By configuring the address bits properly, a single RF transmitter can also be
used to control different RF receivers of same frequency.
To summarize, on each transmission, 12 bits of data is transmitted consisting of 8 address bits
and 4 data bits. The signal is received at receivers end which is then fed into decoder IC. If
address bits get matched, decoder converts it into parallel data and the corresponding data bits
get lowered which could be then used to drive the LEDs. The outputs from this system can
either be used in negative logic or NOT gates (like 74LS04) can be incorporated at data pins.
4.1.2.2 Circuit diagram for HT12E with Transmitter module:
Page 25
Page 26
Page 27
a) Transmitter Module:
Pin Number
Function
Name
Ground (0V)
GND
DATA
Supply Voltage(5V)
Antenna Outputpin
VCC
ANT
Receiver Module:
Page 28
Pin
Function
Name
Ground (0V)
GND
DATA
NC
VCC
VCC
Ground (0V)
GND
Ground (0V)
GND
ANT
Number
Page 29
Fig:4.1.4: Pin diagram and Block diagram of LM805 Regulated DC power supply
4.1.4. Pin Description:
Page 30
Current rating Ic = 1A
Transformer :
Page 31
The current rating of the transformer depends upon the current required for the load to
be driven.
The input voltage to the 7805 IC should be at least 2V greater than the required 2V
output, therefore it requires an input voltage at least close to 7V.
So I chose a 6-0-6 transformer with current rating 500mA (Since 6*2 = 8.4V).
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 :
The best is using a full wave rectifier
1N4007 diodes are used as its is capable of withstanding a higher reverse voltage of
1000v whereas 1N4001 is 50V
Capacitors :
Knowledge of Ripple factor is essential while designing the values of capacitors
It is given by
1. f= frequency of AC ( 50 Hz)
2. R=resistance calculated
R= V/Ic
V= secondary voltage of transformer
V=62=8. 4
Page 32
3. C= filtering capacitance
We have to determine this capacitance for filtering
Y=Vac-rms/Vdc
Vac-rms = Vr/23
Vdc= VMax-(Vr/2)
Vr= VMax- VMin
Vr = 5.2-4.8 =0. 4V
Vac-rms = .3464V
Vdc = 5V
Y=0 .06928
Hence the capacitor value is found out by substituting the ripple factor in Y=1/(43fRC)
Thus, C= 2314 F and standard 2200F is chosen
Datasheet of 7805 prescribes to use a 0.01F capacitor at the output side to
avoid transient changes in the voltages due to changes in load and a 0.33F at the input side
of regulator to avoid ripples if the filtering is far away from regulator.
Circuit Diagram:
Page 33
CHAPTER -5
SENSORS
A device that detects the changes in electrical or physical or other quantities and
thereby produces an output as an acknowledgement of change in the quantity is called as a
Sensor. Generally, this sensor output will be in the form of electrical or optical signal.
Dept of ECE, NCET
Page 34
Fig:5.2: IR Sensor
Generally, thermal radiation is emitted by all the objects in the infrared spectrum.
The infrared sensor detects this type of radiation which is not visible to human eye.
Advantages:
Page 35
Disadvantages:
5.3. Working:
The basic idea is to make use of IR LEDs to send the infrared waves to the object. Another IR
diode of the same type is to be used to detect the reflected wave from the object.
When IR receiver is subjected to infrared light, a voltage difference is produced across the
leads. Less voltage which is produced can be hardly detected and hence operational
amplifiers (Op-amps) are used to detect the low voltages accurately.
Measuring the distance of the object from the receiver sensor. The electrical property of IR
sensor components can be used to measure the distance of an object. The fact when IR
receiver is subjected to light, a potential difference is produced across the leads.
5.4. Applications:
Page 36
Heating Infrared can be used to cook and heat food items. They can take away
ice from the wings of an aircraft. They are popular in industrial field such as, print
dying, forming plastics, and plastic welding.
Spectroscopy This technique is used to identify the molecules by analysing the
constituent bonds. This technique uses light radiation to study organic compounds.
Meteorology Cloud heights, calculate land and surface temperature is possible
earth.
Communications Infrared laser provide light for optical fibre communication.
These radiations are also used for short range communications among mobiles and
computer peripherals.
CHAPTER-6
RESULTS
Page 37
CHAPTER-7
CONCLUSION & FUTURE WORK
Page 38
7.1. Conclusion:
The swarm robot is designed for obstacle avoidance and also as light follower.
ATMEGA-16 microcontroller has been interfaced with different components as L239D motor
driver, HT12E encoder along with the transmitter module, and HT12D decoder along with
the receiver module and also with a push button and slider switch. We use AVR Studio-4 for
coding the program and Proteus to stimulate it.
References
Page 39
Appendix
#ifndef F_CPU
#define F_CPU 1000000UL
Dept of ECE, NCET
Page 40
#endif
#include <avr/io.h> //initialising AVR GPIO library
#include <util/delay.h> //initialising delay library
void forward()
{
PORTB|=(1<<7); //motor pins 1001
PORTB&=~(1<<6);
PORTB&=~(1<<5);
PORTB|=(1<<4);
PORTB|=(1<<3); // transmitting 1001
PORTB&=~(1<<2);
PORTB&=~(1<<1);
PORTB|=(1<<0);
}
void backward()
{
PORTB&=~(1<<7); //motor pins 0110
PORTB|=(1<<6);
PORTB|=(1<<5);
PORTB&=~(1<<4);
PORTB&=~(1<<3); //transmitting 0110
PORTB|=(1<<2);
PORTB|=(1<<1);
PORTB&=~(1<<0);
}
void left()
{
PORTB&=~(1<<7); //motor pins 0101
PORTB|=(1<<6);
PORTB&=~(1<<5);
PORTB|=(1<<4);
PORTB&=~(1<<3); //transmitting 0101
PORTB|=(1<<2);
PORTB&=~(1<<1);
PORTB|=(1<<0);
}
void right()
{
PORTB|=(1<<7); //motor pins 1010
PORTB&=~(1<<6);
PORTB|=(1<<5);
Dept of ECE, NCET
Page 41
PORTB&=~(1<<4);
PORTB|=(1<<3); //transmitting 1010
PORTB&=~(1<<2);
PORTB|=(1<<1);
PORTB&=~(1<<0);
}
void stop()
{
PORTB&=~(1<<7); //motor pins 0000
PORTB&=~(1<<6);
PORTB&=~(1<<5);
PORTB&=~(1<<4);
PORTB&=~(1<<3); //transmitting 0000
PORTB&=~(1<<2);
PORTB&=~(1<<1);
PORTB&=~(1<<0);
}
int main()
{
DDRB=0XFF; //initialinsing PORTB as outputs : Lower nibble for RF Transmitter, Higher
nibble for Motor driver
PORTB=0X00;
DDRD=0X00; //initialising PORTD as inputs : Lower nibble for RF receiver, PD4
make it Master or Slave
PORTD=0XFF;
DDRC=0X00; //initialising PORTC as outputs : PC0 and PC1 for sensor inputs
PORTC=0x03;
while(1)
{
if((PIND & 0X10) == 0X00) //PD4 HIGH: Robot acts as Master
{
if((PINC & 0X03)== 0X03) //LEFT and RIGHT side has Object
{
forward(); //Robot moves forward and transmits 1001
}
else if((PINC & 0X03)== 0X00) //LEFT and RIGHT side has no Object
{
stop(); //Robot stops and transmits 0000
}
else if((PINC & 0X03)== 0X01) //LEFT side has Object
{
left(); //Robot moves left and transmits 0101
}
else if((PINC & 0X03)== 0X02) //RIGHT side has Object
{
right(); //Robot moves right and transmits 1010
Dept of ECE, NCET
Page 42
}
else
{
stop();
}
}
else if ((PIND & 0X10) == 0X10) // PD4 LOW : Robot acts as Slave
{
if((PIND & 0X0F)== 0X09) //Received 1001, when master moving forward
{
forward(); //Robot moves forward
}
else if((PIND & 0X0F)== 0X00) //Received 0000, when master is not
moving
{
stop(); //Robot stops
}
else if((PIND & 0X0F)== 0X05) //Received 0101, when master moving left
{
left(); //Robot moves left
}
else if((PIND & 0X0F)== 0X0A) //Received 1010, when master moving
right
{
right(); //Robot moves right
}
else
{
stop();
}
}
}
}
Page 43