The serial monitor lets you send and recieve text messages from the Arduino to your computer. In this lesson you will learn how to control 4 LED's from your computer with the Arduino Serial Monitor. 

Upload the sketch on the Arduino Code page to your Arduino.

To open the Serial Monitor click the right-most button on the toolbar in the Arduino IDE, The following window will open:

arduino lesson 4 p2

This window is called the Serial Monitor and it is part of the Arduino IDE software. Its job is to allow you to both send messages from your computer to an Arduino board (over USB) and also to receive messages from the Arduino.

Type a number 1 to 4 in the text field of the Serial Monitor an then press the "Send"button. The corresponding LED light up and you will get a confirmation message from the Arduino board, so that the Serial Monitor will appear as shown below. If you type "x" then all the LED's will be cleared.

arduino lesson 4 p3


 

 arduino Uno Board 1x  
 breadboard 1x  
 LED red 4x  
resistor 100ohm 4x

 arduino lesson 4 schema

arduino lesson 4 bb


 

/*
Arduino - Lesson 4. Serial Monitor

Turns on an LED on for one second, 4 with different resistors so the LED brightess will change.

This example code is in the public domain.

modified 03 mar 2016
by www.avrprojects.net
*/

void setup()
{
Serial.begin(9600);
Serial.println("Enter LED Number 1 to 4 or 'x' to clear");
}

void loop()
{


if (Serial.available())
{
char ch = Serial.read();
if (ch >= '1' && ch <= '4')
{
int led = ch - '0';
digitalWrite(led + 1,HIGH);
Serial.print("Turned on LED ");
Serial.println(led);
}
else
{
Serial.println("Enter LED Number 1 to 4 or 'x' to clear");
}

if (ch == 'x')
{
int x = 2;
while(x <= 5)
{
digitalWrite(x,LOW);
x = x + 1;
}
Serial.println("Cleared");
}
}
}