Advertisement

Friday, 13 July 2012

Arduino Communication With PC

CODE IS DEVELOPED BY USING  ARDUINO UNO BOARD

Description:
This code is about communicating arduino with PC .There are 4 LEDs connected with arduino board in this code when "1" is sent from PC one LED turns on when 2 is pressed 2 LEDs turn on likewise by pressing 3 turns 3 LEDs on and so on.





Below code is provided it is tested and working :

int a=8;
int b=9;
int c=10;
int d=11;
void setup(){
  for(int z=8;z<14;z++){
  pinMode(z,OUTPUT);

  Serial.begin(9600);
}}

void loop(){
 
  if(Serial.available()>0){
    int data=Serial.read();
   
    if(data=='1'){
    digitalWrite(a,HIGH);
  
    }
  
  if(data=='2'){
 
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
  }
    if(data=='3'){
 
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
  }
     if(data=='4'){
 
  digitalWrite(a,HIGH);
  digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
  digitalWrite(d,HIGH);
  }

   }
  }

 
 
like and share the knowledge

0 comments:

Post a Comment