I will further extend my last project on serial communication by writing a program that controls the inbuilt LED in the arduino uno connected to the digital pin 13 through the serial monitor. The following program turns ON the LED when ‘1’ is sent to the board by the computer and turns OFF the LED when 0 is sent by the computer to the Arduino board. In all other cases it will print”invalid command”.

The string “invalid command” will be sent by the arduino to the computer in case of not receiving a 0 or 1 as the command programmed for the state of the LED. We can also send a group of messages (Strings) from the serial monitor to the arduino processor by pressing the send button.

The code is pretty basic all I have done is that I added the if-else condition as per my requirements. Rest all the code is same as in my last project.

char value;

int LED =13;

void setup(){

void loop(){
while(Serial.available() == 0);
value = Serial.read();

if(value == ‘0’)
digitalWrite(LED, LOW);
Serial.println(“LED IS OFF”);
else if(value == ‘1’)
Serial.println(LED IS ON);
Serial.println(“INVALID COMMAND BRO”);
} //end

In the previous project and in this one I have introduced you ways in which you can interact with your board. This must have fascinated you in learning that you are able to comprehend the bit-by-bit data that you send and receive.
There is beauty in understanding the basics, as I had already mentioned.
Once you understand how or what governs a particular system we tend to be more curious about it and  start understanding more and more.
The cycle goes on, and we end up learning all about that particular thing. This is knowledge, this is the purest meaning of education. 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s