You are on page 1of 2

Session 4 Exercise 2:

Objective: Building a control node.

Steps:

 Plug Arduino board to into your computers USB port.


 Connect external LED in series with a 1 Kohm resistor to pin 11 as shown in below
picture.

 Upload below given program on Arduino board.


 Open serial monitor and send letter c or C and d or D to switch LED ON and OFF
respectively.
 An acknowledgement message will be displayed on serial monitor.

Code:

const int ledpin= 11;

void setup()

Serial.begin(9600); //Communicate with PC/LAPTOP

pinMode(ledpin, OUTPUT);

digitalWrite(ledpin,LOW);

}
void loop()

if(Serial.available()>0)

int val = Serial.read();

if(val=='c'|| val== 'C')

digitalWrite(ledpin,HIGH);

Serial.println("LED is ON");

if(val=='d' || val == 'D')

digitalWrite(ledpin,LOW);

Serial.println("LED is OFF");

You might also like