Switch Processing

Description

     Guys, In this project we are going to control an LED by a switch using Arduino.This is simple project for beginners.Here when the switch is turned on the led will turn on and when the switch is turned of the LED will turn off. Okey,let's make it.
      
Components Required

 1. Arduino UNO  * 1
 2. LED  * 1
 3. Switch * 1
 4. Resister(220 Ohm)  * 1
 5. Jumper Wires  * 1

Circuit Diagram




Program

int switchPin = 4;                // Switch connected to pin 4 
int led = 13; 
void setup() { 
  pinMode(switchPin, INPUT);   
  pinMode(led,OUTPUT);
  Serial.begin(9600);         // Start serial communication at 9600 bps 

 
void loop() 

  if (digitalRead(switchPin) == HIGH)
  {  // If switch is ON, 
    digitalWrite(13,HIGH);
    Serial.write(1);                     // send 1 to Processing
  }
  else
  {                               
    digitalWrite(13,LOW);
    Serial.write(0);                     // send 0 to Processing 
  }                              
} // put your setup code here, to run once: