Friday, August 14, 2020

Programming of Line Detector Robots using Arduino

int mot1=9;
int mot2=6;
int mot3=5;
int mot4=3;

int left=13;
int right=12;

int Left=0;
int Right=0;

void LEFT (void);
void RIGHT (void);
void STOP (void);

void setup()
{
  pinMode(mot1,OUTPUT);
  pinMode(mot2,OUTPUT);
  pinMode(mot3,OUTPUT);
  pinMode(mot4,OUTPUT);

  pinMode(left,INPUT);
  pinMode(right,INPUT);

  digitalWrite(left,HIGH);
  digitalWrite(right,HIGH);


}

void loop()
{

analogWrite(mot1,255);
analogWrite(mot2,0);
analogWrite(mot3,255);
analogWrite(mot4,0);

while(1)
{
  Left=digitalRead(left);
  Right=digitalRead(right);

  if((Left==0 && Right==1)==1)
  LEFT();
  else if((Right==0 && Left==1)==1)
  RIGHT();
}
}

void LEFT (void)
{
   analogWrite(mot3,0);
   analogWrite(mot4,30);
 
 
   while(Left==0)
   {
    Left=digitalRead(left);
    Right=digitalRead(right);
    if(Right==0)
    {
      int lprev=Left;
      int rprev=Right;
      STOP();
      while(((lprev==Left)&&(rprev==Right))==1)
      {
         Left=digitalRead(left);
         Right=digitalRead(right);
      }
    }
    analogWrite(mot1,255);
    analogWrite(mot2,0);
   }
   analogWrite(mot3,255);
   analogWrite(mot4,0);
}

void RIGHT (void)
{
   analogWrite(mot1,0);
   analogWrite(mot2,30);

   while(Right==0)
   {
    Left=digitalRead(left);
    Right=digitalRead(right);
    if(Left==0)
    {
      int lprev=Left;
      int rprev=Right;
     STOP();
      while(((lprev==Left)&&(rprev==Right))==1)
      {
         Left=digitalRead(left);
         Right=digitalRead(right);
      }
    }
    analogWrite(mot3,255);
    analogWrite(mot4,0);
    }
   analogWrite(mot1,255);
   analogWrite(mot2,0);
}
void STOP (void)
{
analogWrite(mot1,0);
analogWrite(mot2,0);
analogWrite(mot3,0);
analogWrite(mot4,0);

}

Programming of Frequency Counter Circuit using 8051 Microcontroller.

#include
#define lcd P1
sbit rs=P3^0;
sbit e=P3^1;

unsigned long z=0;
void delay (int);
void display (unsigned char);
void cmd (unsigned char);
void init (void);
void string (char *);
void intro (void);
char i=0;


void delay (int i)
{
int j=0;
for(j=0;j
{
TMOD=0x51;
TH0=0xFC;
TL0=0x66;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
}

void cmd (unsigned char c)
{
lcd=c;
rs=0;
e=1;
delay(10);
e=0;
}
void display (unsigned char c)
{
lcd=c;
rs=1;
e=1;
delay(10);
e=0;
}
void string (char *c)
{
while(*c)
{
display(*c++);
}
}
void init (void)
{
cmd(0x38);
cmd(0x01);
  cmd(0x0c);
cmd(0x80);
}
void intro (void)
{
cmd(0x80);
string("  Electronics  ");
cmd(0xc0);
string("      Hub      ");
delay(2000);
cmd(0x01);
cmd(0x80);
string("   Frequency   ");
cmd(0xc0);
string("    Counter    ");
delay(2000);
cmd(0x01);
cmd(0x80);
}

void main()
{
unsigned int temp=0;
unsigned int temp1=0;
unsigned int frequency;
init();
intro();
delay(100);
while(1)
{

  TMOD=0x51;
TH1=0;
TL1=0;
TR1=1;
delay(100);
TR1=0;
frequency=(TH1*256)+TL1;
frequency=frequency*10;
 

////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(i==0)
{
string("Frequency In Hz");
i++;
}


    cmd(0xc5);
if((frequency>=1) && (frequency<10 span="">
{
string("    ");
  temp=frequency*10000;
  temp1=((temp/10000)+48);
  display(temp1);

  }
  else if((frequency>=10) && (frequency<100 span="">
{
string("   ");
temp=frequency*1000;
  temp1=((temp/10000)+48);
  display(temp1);

temp1=(((temp/1000)%10)+48);
  display(temp1);

}
//////////////////////////////////////////////////////////////////////
else if((frequency>=100) && (frequency<1000 span="">
{
string("  ");
temp=frequency*100;
  temp1=((temp/10000)+48);
  display(temp1);

temp1=(((temp/1000)%10)+48);
  display(temp1);

temp1=(((temp/100)%10)+48);
display(temp1);

}

else if((frequency>=1000) && (frequency<10000 span="">
{
string(" ");
temp=frequency*10;
  temp1=((temp/10000)+48);
  display(temp1);

temp1=(((temp/1000)%10)+48);
  display(temp1);

temp1=(((temp/100)%10)+48);
display(temp1);

temp1=(((temp/10)%10)+48);
display(temp1);

}
else if((frequency>=10000) && (frequency<100000 span="">
{
temp=frequency*1;
  temp1=((temp/10000)+48);
  display(temp1);

temp1=(((temp/1000)%10)+48);
  display(temp1);

temp1=(((temp/100)%10)+48);
display(temp1);

temp1=(((temp/10)%10)+48);
display(temp1);

temp1=((temp%10)+48);
display(temp1);


}
else
{
string("    0");
}
delay(500);
 }
while(1);
}

WATER LEVEL INDICATOR USING 8051 MICROCONTROLLER

WATER LEVEL INDICATOR 8051 MICROCONTROLLER CODE.

#define  F_CPU 8000000UL
#include
#include

int main(void)
{
DDRB = 0x00; // PORTB pins as input
DDRD = 0xff; // PORTD as output
DDRC = 0x01; // Buzzer
unsigned char seg[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};
    while(1)
    {
        if((PINB & 0xff)==0x00) // 8th probe, Tank full
{
PORTC = 0x01;
PORTD = seg[8];
}
else if((PINB & 0xff)==0x01) // 7th probe
{
PORTC = 0x01;
_delay_ms(500);
PORTC = 0x00;
_delay_ms(500);
PORTD = seg[7];
}
else if((PINB & 0xff)==0x03) // 6th probe
{
PORTC = 0x00;
PORTD = seg[6];
}
else if((PINB & 0xff)== 0x07) // 5th probe
{
PORTC = 0x00;
PORTD = seg[5];
}
else if((PINB & 0xff)== 0x0f) // 4th probe
{
PORTC = 0x00;
PORTD = seg[4];
}
else if((PINB & 0xff)==0x1f) // 3rd probe
{
PORTC = 0x00;
PORTD = seg[3];
}
else if((PINB & 0xff) == 0x3f) // 2nd probe
{
PORTC = 0x00;
PORTD = seg[2];
}
else if((PINB & 0xff) == 0x7f) // 1st probe
{
PORTC = 0x00;
PORTD = seg[1];
}
else                                // Tank empty
{
PORTC = 0x00;
PORTD = seg[0];
}
    }
}