Serial Communication


I just began with my course control technology of a microcontroller ( with arduino)
I completed a step of my homework called doing math with serial communication. see the attachment ‘doing math’
The next task is to use the serial monitor and type in a value in this case 12 press send and it’ll calculate. see the attachment ‘‘uncompleted example’’ for what i mean
By using if(serial.available) and serial.parseInt, but i dont have any idea of how to do it.

anyone here can help me out?


Have you looked up the Serial library and looked at what serial.available does?

Serial.available() will return the number of bytes available to read from the serial port.

To save you some time, try and get one arduino to keep saying "Hello World!" and have the other that is receiving the data keep looping:

//On receiving arduino.

if (Serial.available()>0){
//On sending arduino.
Serial.println("Hello World!");

See what you notice and come back to us ;).

the only thing that i notice is that it keeps saying ''hello world''

void setup() {

 void loop() {
  if (Serial.available()>0){
Serial.println("Hello World!");

@Alexlauman, It must be my day to bitch, so: If you are in school, college, or whatever, I would expect you could use correct grammar. Sentences start with capital letters, and end with proper punctuations.

thnx is not a word.

Just my minute to bitch I guess!

I don't think that's too much to ask. Really, programming languages and compilers are even more concerned with things like grammar, capitalization, and punctuation than even the most strident grammar nazi.

It would be really nice if the people coming here to ask for our help had enough respect to write to us like grownups and not like they are sending a text message to their girlfriend. It's hard enough sorting through code that doesn't make sense without trying to figure out what the person is trying to say about it.

Alexlauman: the only thing that i notice is that it keeps saying ''hello world''

Read my post again.

One should have the Serial.available() loop.

The other Arduino the Serial.println("hello world"); loop.

Will not be doing your homework for you, but as an actual teacher...I will give you a small exercise in order for you to understand the principle out of context for you to apply to another...


Perhaps, the code on the following pages (especially the first one) can also hopefully shed some light on the use of Serial.available(). I think the example for the Uno is quite simple and is well explained... (there is a link for parseInt() which could be useful to read as well)


Have a look at the examples in Serial Input Basics. One of them is likely to meet your need.