Friday, 16 September 2016

Edge Detector Robo

Edge Detector Robo:

Code:

#pragma config OSC = HS
#pragma config OSCS = OFF
#pragma config PWRT = OFF
#pragma config BOR = ON
#pragma config BORV = 45
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config DEBUG = OFF
#pragma config STVR = OFF

#define s0 PORTC.F0
#define s1 PORTC.F1

#define m0 PORTB.F0
#define m1 PORTB.F1

#define m2 PORTB.F2
#define m3 PORTB.F3

 int count=0;

void left()
{
  m0=0;
  m1=0;
  m2=1;
  m3=0;
  count=1;
}

void right()
{
  m0=1;
  m1=0;
  m2=0;
  m3=0;
  count=0;
}

void forw()
{
  m0=1;
  m1=0;
  m2=1;
  m3=0;
}

void back()
{
  m0=0;
  m1=1;
  m2=0;
  m3=1;
}
void main(void)
{
//  int count=0;
  TRISC= 0x00;
  TRISD= 0xff;

  while(1)
   {

    if(s0==1&&s1==1)
           {
           forw();
           }

      if(s0==1&&s1==0)
           {
           right();
           }
        if(s0==0&&s1==1)
           {
           left();

           }
         if(s0==0&&s1==0)
           {
           back();
           delay_ms(1000);
           if(count==0)
            {
             left();
             delay_ms(250);
            }
            else
            {
             right();
             delay_ms(250);
             }

           }



      }
}

Circuit Diagram: 






Layout:





Monday, 5 September 2016

Thermometer

Thermometer


Program for thermometer:

#include<LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
#define analog_pins A0;
void setup()
{
  lcd.begin(16,2);
  lcd.print("");
}
void loop()
{
  lcd.clear();
  float temp=analogRead(A0);
  lcd.print(temp*0.488);
 
  lcd.print("degree celsius");
 
  delay(100);

}

ADC with Arduino

ADC with Arduino:

Program for Temp controlled with ADC:


#include<LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
#define analog_pins A0;
void setup()
{
  lcd.begin(16,2);
}
void loop()
{
  lcd.clear();
  float temp=analogRead(A0);
 int a=(temp*0.488);
 lcd.setCursor(0,1);
 lcd.print(a);

 
  if(a>20&&a<35)
{
  lcd.setCursor(0,0);
  lcd.print("light gets off");
}
else if(a >35)
  {
    lcd.setCursor(0,0);
  lcd.print("motor starts");

  }
  delay(1000);

}

Simulation:


  

Serial com. with Arduino

Serial com. with Arduino

Write a program to transmit data on the PC.


void setup()
{



 Serial.begin(9600);
 
}

void loop() // run over and over
{
 Serial.println("Hello world");
}


Simulation:



Write a program to receive data from the PC.


#include<LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
int led1=8;
int led2=9;
int led3=10;
int mot1=11;
int mot2=12;
#include<String.h>
int i=0;
char name[20];

void setup()
{
  pinMode(led1,OUTPUT);
   pinMode(led2,OUTPUT);
    pinMode(led3,OUTPUT);
    pinMode(mot1,OUTPUT);
    pinMode(mot2,OUTPUT);
  lcd.begin(16,2);
  Serial.begin(9600);
 
}
void loop()
{
  while(Serial.available())
  {
   char temp=Serial.read();
 
    name[i]=temp;
    i++;
   if(temp==0x0d)
   {
    if(strncmp(name,"bulb is on",10)==0)
    {
     lcd.clear();
     lcd.print("bulb is on");
   
      digitalWrite(led1,HIGH);
      digitalWrite(led2,LOW);
      digitalWrite(led3,LOW);
     
      i=0;
     }
   
   else    if(strncmp(name,"led is on",9)==0)
 {
   lcd.clear();
   lcd.print("led is on");
   digitalWrite(led2,HIGH);
     digitalWrite(led1,LOW);
      digitalWrite(led3,LOW);
       digitalWrite(mot1,HIGH);
       digitalWrite(mot2,LOW);
       delay(1000);
       digitalWrite(mot1,LOW);
       digitalWrite(mot2,HIGH);
       delay(1000);
       digitalWrite(mot1,LOW);
       digitalWrite(mot2,LOW);
 
   i=0;
 }
 else if(strncmp(name,"fan is on",9)==0)
 {
   lcd.clear();
   lcd.print("fan is on");
   digitalWrite(led3,HIGH);
     digitalWrite(led2,LOW);
      digitalWrite(led1,LOW);
     
   i=0;
 
 }

}
  }

  }


Simulation:









Interfacing of Lcd with Arduino

Interfacing of Lcd with Arduino:


Display "welcome to all" on the lcd.

#include<LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);

void setup()
{
  lcd.begin(16,2);
  lcd.print("welcome to all");
}
void loop()
{
  lcd.setCursor(5,2);

}

Simulation:



Lcd with Switch:


#include<LiquidCrystal.h>
int sw1=1;
int sw2=8;
LiquidCrystal lcd(2,3,4,5,6,7);
int led1=9;
int led2=10;

void setup()
{
  pinMode(sw1,INPUT);
  pinMode(sw2,INPUT);
  lcd.begin(16,2);
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  digitalWrite(sw1, HIGH);
  digitalWrite(sw2,HIGH);
}

void loop()
  if(digitalRead(sw1)==0)
  {
   lcd.clear();
   lcd.print("switch 1 is on");
   digitalWrite(led1,HIGH);
   delay(1000);
   digitalWrite(led1,LOW);
  // delay(1000);
  }
  
  else
  {
    lcd.clear();
   lcd.print("switch 1 is off");
   //digitalWrite(led1,HIGH);
   //delay(1000);
  // digitalWrite(led1,LOW);
  // delay(1000);
  }
 
  if(digitalRead(sw2)==0)
  {
   lcd.setCursor(0,1);
   lcd.print("switch 2 is on");
   digitalWrite(led2,HIGH);
   delay(1000);
   digitalWrite(led2,LOW);
  // delay(1000);
  } 


  else 
  {
    lcd.setCursor(0,1);
    lcd.print("switch 2 is off");
  //  delay(1000);
  }
  
  delay(1000);



Simulation:




 










Interfacing of 7 segment with Arduino

Interfacing of 7 segment with Arduino:

Display 0-9 on 7 segment:


int segment_pins[8]={2,3,4,5,6,7,8,9};
int segment_digit[10]={0xc0,0xF9,0xA4,0x0B,0x99,0x92,0x82,0xF8,0x08,0x09};

void setup()
 {

 for(int i=0;i<8;i++)
  pinMode(segment_pins[i],OUTPUT);
 }


void loop()
{
  for(int temp=0;temp<10;temp++)
  {
    char temp2=segment_digit[temp];
   for(int k=0;k<8;k++)
  {
    char temp1=temp2&0x01;
    temp2=temp2>>1;
    digitalWrite(segment_pins[k],temp1);
  }
  delay(1000);
}
}

Simulation:



Display 0-99 on 7 segment:


int segment_pins[7]={0,1,2,3,4,5,6};
int segment_pinss[7]={7,8,9,10,11,12,13};
int segment_digit[10]={0xc0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
 
void setup()
 {
 
 for(int i=0;i<8;i++)
 
  pinMode(segment_pins[i],OUTPUT);
 
  for(int m=0;m<8;m++)
 
  pinMode(segment_pinss[m],OUTPUT);
 
 }
 

void loop()
{
  for(int temp=0;temp<10;temp++)
  {
    char temp2=segment_digit[temp];
   for(int k=0;k<7;k++)
  {
    char temp1=temp2&0x01;
   
    digitalWrite(segment_pins[k],temp1);
     temp2=temp2>>1;
  }
    for(int temp5=0;temp5<10;temp5++)
  {
    char temp6=segment_digit[temp5];
   for(int n=0;n<7;n++)
  {
    char temp7=temp6&0x01;
    
    digitalWrite(segment_pinss[n],temp7);
    temp6=temp6>>1;
  }
  delay(1000);
  }
  
}
}


Simulation:


Display 0-99 on 7 segment multiplexing:


int segment_pins[8]={0,1,2,3,4,5,6};
int segment_digit[10]={0xc0,0xF9,0xA4,0x0B,0x99,0x92,0x82,0xF8,0x08,0x09};

int seg1=7;
int seg2=8;

char temp1,temp2;
 
void setup()
 {
 
  for(int i=0;i<7;i++)
  pinMode(segment_pins[i],OUTPUT);
  pinMode(seg1, OUTPUT);
  pinMode(seg2, OUTPUT);
 }
 

void loop()
{
  for(int dig1=0;dig1<10;dig1++)
  {
   for(int dig2=0;dig2<10;dig2++)
   { 
    
    for(int m=0;m<30;m++)
    {
      temp1=segment_digit[dig1];
      temp2=segment_digit[dig2];
     for(int i=0;i<2;i++)
     {
      display1(i);
      delay(1);
     }
    }
   }
  }
}

void display1(int i)
{
  switch(i)
  {
    case 0:
    digitalWrite(seg1, HIGH);
    digitalWrite(seg2, LOW);
    for(int k=0;k<8;k++)
    {
     char a=temp1&0x01;
     temp1=temp1>>1;
     digitalWrite(segment_pins[k],a);
     delay(1);
    }
    digitalWrite(seg1, LOW);
    digitalWrite(seg2, LOW);
   temp1=0xff; 
    for(int k=0;k<8;k++)
    {
     char a=temp1&0x01;
     temp1=temp1>>1;
     digitalWrite(segment_pins[k],a);
     //delay(5);
    }
    break;
    
    case 1:
    digitalWrite(seg1, LOW);
    digitalWrite(seg2, HIGH); 
     for(int b=0;b<8;b++)
     {
      char temp4=temp2&0x01;
      temp2=temp2>>1;
      digitalWrite(segment_pins[b],temp4);
      delay(1);
     }
     digitalWrite(seg1, LOW);
    digitalWrite(seg2, LOW);
   temp2=0xff; 
      for(int b=0;b<8;b++)
     {
      char temp4=temp2&0x01;
      temp2=temp2>>1;
      digitalWrite(segment_pins[b],temp4);
     // delay(5);
     }
    
     break;
  }
  
  }


Simulation:




Interfacing of Led with Arduino

Interfacing of Led with Arduino:


/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led1 = 13;
int led2 = 12;
int led3 = 11;
int led4 = 10;

// the setup routine runs once when you press reset:
void setup() {              
  // initialize the digital pin as an output.
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW); // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led4, HIGH);
  digitalWrite(led3, LOW);
// turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}


Simulation: