Friday, 16 September 2016

Bluetooth_controlled_Robotic_ARM

Bluetooth_controlled_Robotic_ARM


Code:


#include <avr/io.h>
#define F_CPU 8000000ul
#include<util/delay.h>

#define m11 PB0
#define m12 PB1

#define m21 PB2
#define m22 PB3

#define m31 PA2
#define m32 PA1

#define m41 PA4
#define m42 PA3

#define m51 PC4
#define m52 PC6

#define LED11 PD7
#define LED12 PC0

#define motor PORTC

char str[3],i=0;

void serialinit()
{
UCSRB=0x18;
UCSRC=0x86;
UBRRL=0x33;
}

void send(char p)
{
UDR=p;
while(!(UCSRA & (1<<UDRE)));
}

void txstring(char *ptr)
{
  while(*ptr)
  {
 send(*ptr);
 ptr++;
  }
}

void rxdata()
{
   while(!(UCSRA & (1<<RXC)));
   char temp=UDR;
   str[i++]=temp;
}

int main(void)
{
DDRC=0xff;
DDRA=0xff;
DDRB=0xff;
DDRD|=1<<LED11;
serialinit();
    while(1)
    {
        rxdata();

/***** based Movement ****/
if(str[i-1]=='1')          
{
PORTB|=1<<m11;
PORTB&=~(1<<m12);
txstring("Left Moving\r\n");
i=0;
_delay_ms(100);
}

else if(str[i-1]=='2')
{
   PORTB|=1<<m12;
   PORTB&=~(1<<m11);
txstring("Moving Right\r\n");
i=0;
_delay_ms(100);
}

/******solder Movement *****/

else if(str[i-1]=='3')
{
PORTB|=1<<m21;
PORTB&=~(1<<m22);
txstring("Solder Up\r\n");
i=0;
_delay_ms(100);
}

else if(str[i-1]=='4')
{
PORTB|=1<<m22;
PORTB&=~(1<<m21);
txstring("Solder Down\r\n");
i=0;
_delay_ms(100);
}

/******* Elbow Movement ********/

else if(str[i-1]=='5')
{
PORTA|=1<<m31;
PORTA&=~(1<<m32);
txstring("Elbow Up\r\n");
i=0;
_delay_ms(100);
}
 
  else if(str[i-1]=='6')
  {
  PORTA|=1<<m32;
  PORTA&=~(1<<m31);
  txstring("Elbow Down\r\n");
  i=0;
  _delay_ms(100);
  }
 
  /***** wrist Movement ******/
 
  else if(str[i-1]=='7')
  {
  PORTA|=1<<m41;
  PORTA&=~(1<<m42);
  txstring("Wrist Up\r\n");
  i=0;
  _delay_ms(100);
  }
 
  else if(str[i-1]=='8')
  {
  PORTA|=1<<m42;
  PORTA&=~(1<<m41);
  txstring("Wrist Down\r\n");
  i=0;
  _delay_ms(100);
  }
 
  /****** holding ********/
 
  else if(str[i-1]=='9')
  {
  PORTC|=1<<m51;
  PORTC&=~(1<<m52);
  txstring("Holding\r\n");
  i=0;
  _delay_ms(100);
  }
 
  else if(str[i-1]=='t')
  {
  PORTC|=1<<m52;
  PORTC&=~(1<<m51);
  txstring("Releasing\r\n");
  i=0;
  _delay_ms(100);
  }
 
  else
  {
  PORTA=0;
  PORTC=0;
  PORTB=0;
  }
    }
}


Simulation:





0 comments:

Post a Comment

if you have any doubt please let me know