Arduino Sketch 1

A program that allows the user to control the LED connected to pin 13 of the Arduino. When the program is started, the LED should be off. The user should open the serial monitor to communicate with the Arduino. If the user sends the character '1' through the serial monitor then the LED should turn on. If the user sends the character '0' through the serial monitor then the LED should turn off.


Code:-

void setup() 
{
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  Serial.println();  

}

void loop() 
{
  int x;
  x=Serial.read();

    if (x=='1')
  {
    digitalWrite(13,HIGH);
    Serial.print(" LED ON ");
  }
    if (x=='0')
  {
    digitalWrite(13,LOW);
    Serial.print(" LED OFF ");
  }
}

Comments

Post a Comment