Serial Monitor With Arduino Uno R3

About: PrimeRobotics is a E-Commerce site, which focus on supplying right products to Electronics Hobbyists, Enthusiast & Students.

In this experiment, you will learn how to turn on or off LEDs through a computer and the Serial Monitor. Serial Monitor is built-in software in the Arduino IDE. You can send and receive data via the serial port on the control board.

Step 1: Components

- Arduino Uno board * 1

- USB cable * 1

- Resistor (220Ω) * 3

- Red LED * 1

- Green LED * 1

- Blue LED * 1

- Breadboard * 1

- Jumper wires

Step 2: ​Principle:

Serial Monitor is used for communication between the Uno board and a computer or other devices. It is built-in software in the Arduino environment and you can click the button on the upper right corner to open it. You can send and receive data via the serial port on the control board and control the board by input from the keyboard.

Here, the Serial Monitor serves as a transfer station for communication between your computer and the Arduino Uno board. First, the computer transfers data to the Serial Monitor, and then the data is read by the Uno board. Finally, the Uno will perform related operations. Click the icon at the top right corner and a window will pop up as shown below:

Step 3: The Schematic Diagram

Step 4: Procedures

In this experiment, since we use colored LEDs as loads,

you can enter a color among red, green, and blue on Serial Monitor in the IDE. The corresponding LED connected to the Arduino Uno board will then light up.

Step 1:

Build the circuit.

Step 2:

Download the code from https://github.com/primerobotics/Arduino

Step 3:

Upload the sketch to the Arduino Uno board

Click the Upload icon to upload the code to the control board.

If "Done uploading" appears at the bottom of the window, it means the sketch has been successfully uploaded.

Now, click the Serial Monitor button at the upper right corner in the IDE. Then the Serial Monitor window will pop up. With this window, you can not only send data from your computer to the SunFounder Uno board, but also receive data from the board and display it on the screen. When you open the window, it will display "Please input any color of LED:".

You can input a color here. Enter red, green, or blue, click Send, and then the corresponding LED on the breadboard will light up. However, if you enter any other colors, no LEDs will brighten. For example, enter red, and you will see the red LED light up.

Step 5: Code

//Serial
Monitor

// open the serial monitor ,if you input red, you will see the red LED light up

//Email:info@primerobotics.in

//Website:www.primerobotics.in

//2015.5.7

const int greenPin= 2; //the green led pin attact to

const int yellowPin= 3; //the yellow led pin attact to

const int redPin= 4; //the red led pin attach to

String comdata = "";

int lastLength = 0;

void setup()

{

pinMode(greenPin,OUTPUT); //initialize the greenPin as output

pinMode(yellowPin, OUTPUT); //initialize the yellowPin as output

pinMode(redPin, OUTPUT); //initialize the redPin as output

Serial.begin(9600); // start serial port at 9600 bps:

Serial.println("Please input any color of LED:"); //print message on serial monitor

}

void loop()

{

//read string from serial monitor

if(Serial.available()>0) // check if data has been sent from the computer

{

comdata = "";

while (Serial.available() > 0)

{

comdata += char(Serial.read());

delay(2);

}

Serial.println(comdata);

}

if(comdata == "red")

{

digitalWrite(redPin, HIGH);//turn the red led on

digitalWrite(greenPin, LOW);//turn the green led off

digitalWrite(yellowPin, LOW);//turn the yellow led off

}

else if(comdata == "yellow")

{

digitalWrite(redPin, LOW);//turn the red led off

digitalWrite(greenPin, LOW);//turn the green led off

digitalWrite(yellowPin, HIGH);//turn the yellow led on

}

else if(comdata == "green")

{

digitalWrite(redPin, LOW);//turn the red led off

digitalWrite(greenPin, HIGH);//turn the green led on

digitalWrite(yellowPin, LOW);//turn the yellow led off

}

else

{

digitalWrite(redPin, LOW);//turn the red led off

digitalWrite(greenPin, LOW);//turn the green led off

digitalWrite(yellowPin, LOW);//turn the yellow led off

}

}

Step 6: Code Analysis

Share

    Recommendations

    • Epilog X Contest

      Epilog X Contest
    • Remix Contest

      Remix Contest
    • Organization Contest

      Organization Contest

    Discussions

    0
    None
    tytower

    5 weeks ago

    Surely you can be smart enough to attach the ".ino" file mate !!