In the previous tutorial I have explained how to setup a basic serial connection between an Atmega16 controller Board and a computer/laptop. In this article we’ll learn how to control a robot using the computer/laptop wirelessly through Bluetooth.
Components Required
1. Atmega16 development board with 16MHz crystal 2. Serial Bluetooth Module(AUBTM/HC-05/HC-04/BLUSMIRF) 3.PC/Laptop running Windows XP/7/8 4.USB Bluetooth(Not required if you laptop/PC has inbuilt hardware) 5.Motor Driver L293D 6.2 X 12V 100RPM Geared DC motor 7.2 X Wheels 8.Chassis 9. Castor wheel 10.Female jumper wires
1. Atmega16 development board with 16MHz crystal 2. Serial Bluetooth Module(AUBTM/HC-05/HC-04/BLUSMIRF) 3.PC/Laptop running Windows XP/7/8 4.USB Bluetooth(Not required if you laptop/PC has inbuilt hardware) 5.Motor Driver L293D 6.2 X 12V 100RPM Geared DC motor 7.2 X Wheels 8.Chassis 9. Castor wheel 10.Female jumper wires
Software Required
Serial Port Software on your PC (RealTerm/HyperTerminal/TeraTerm/Putty/ Your own Program)
Block-Diagram
Mechanical Construction:
Let us start with the hardware assembly part first. It should be simple since we are using a ready-made chassis. Start by attaching the motors and castor wheel to the chassis.
Next attach the wheels to the motor shafts using the screw provided on the wheel.
Connect the wires emerging from the two motors to the output pins of the L293D motor driver.
After all connections are made, this is how it looks.
Remember: RX (PIN 14) of controller to TX of modem and TX (PIN 15) of controller to RX of modem.
#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>
// Right motor ( + ) = PB1 , Right motor ( - ) = PB2
// Left motor ( + ) = PB4 , Left motor ( - ) = PB3
// Left motor ( + ) = PB4 , Left motor ( - ) = PB3
void USARTInit(uint16_t ubrr_value)
{
//Set Baud rate
UBRRL = ubrr_value;
UBRRH = (ubrr_value>>8);
/*Set Frame Format
>> Asynchronous mode
>> No Parity
>> 1 StopBit
>> char size 8
*/
UCSRC=(1<<URSEL)|(3<<UCSZ0);
//Enable The receiver and transmitter
UCSRB=(1<<RXEN)|(1<<TXEN);
}
//This function is used to read the available data
//from USART. This function will wait untill data is
//available.
char USARTReadChar()
{
//Wait untill a data is available
while(!(UCSRA & (1<<RXC)))
{
//Do nothing
}
//Now USART has got data from host
//and is available is buffer
return UDR;
}
//This fuction writes the given "data" to
//the USART which then transmit it via TX line
void USARTWriteChar(char data)
{
//Wait untill the transmitter is ready
while(!(UCSRA & (1<<UDRE)))
{
//Do nothing
}
//Now write the data to USART buffer
UDR=data;
}
void main()
{
DDRB=0b00011110; //PB1, PB2, PB3, PB4 as output port
//Varriable Declaration
char data;
/*First Initialize the USART with baud rate = 9600bps
for Baud rate = 9600bps
UBRR value = 12 //// 1Mhz // atmega16
// For 16 Mhz check the UBRR value in datasheet
*/
USARTInit(12); //UBRR = 12
//Loop forever
while(1)
{
//Read data
data=USARTReadChar();
if((data==t))
{
PORTB=0b00000000; //stop
}
if((data==d))
{
PORTB=0b00010000; //turn right
}
if((data==a))
{
PORTB=0b00000010; //turn left
}
if((data==w))
{
PORTB=0b00010010; //move forward
}
if((data==s))
{
PORTB=0b00001100; //move reverse
}
{
PORTB=0b00000000; //stop
}
if((data==d))
{
PORTB=0b00010000; //turn right
}
if((data==a))
{
PORTB=0b00000010; //turn left
}
if((data==w))
{
PORTB=0b00010010; //move forward
}
if((data==s))
{
PORTB=0b00001100; //move reverse
}
}
}
NOTE : if you r facing any problem info me.
NOTE : if you r facing any problem info me.
No comments:
Post a Comment