How do you send data to arduino using the serial monitor?

Hi

I would like to know how I can send the data to arduino using serial monitor. Can someone give me a code to do that. I want to enter "+++" to arduino which in turn should send it to the Tx pin a transceiver to put it to configuration mode.

Thanks

There is a text entry field at the top of the serial monitor, and a Send button. Type some text. Click the button. Make sure that you set the option at the lower right to not append anything.

Don't you have to code arduino to check if there is any data sent to it?

Don't you have to code arduino to check if there is any data sent to it?

Of course.

I would like to know how I can send the data to arduino using serial monitor.

I answered this.

Can someone give me a code to do that.

There is no code required to send data TO the Arduino. That code already exists, in the form of the Serial Monitor.

I want to enter "+++" to arduino which in turn should send it to the Tx pin a transceiver to put it to configuration mode.

So, do that.

Notice that no where did you ask what the Arduino needed to do to participate in the process.

I used the following code available in the website to communicate with arduino using serial monitor. But the problem is when I enter '1' it prints '49' on the serial monitor which is the ASCII decimal. So how can I get the output as '1' instead of '49'?

int incomingByte = 0; // for incoming serial data

void setup() { Serial.begin(9600); // opens serial port, sets data rate to 9600 bps }

void loop() {

// send data only when you receive data: if (Serial.available() > 0) { // read the incoming byte: incomingByte = Serial.read();

// say what you got: Serial.print("I received: "); Serial.println(incomingByte, DEC); } }

Make incomingByte a char,

char incomingByte = 0;   // for incoming serial data

and change this

    Serial.println(incomingByte, DEC);

to this

    Serial.println(incomingByte);

Or, leave incomingByte as an int, and cast it to a char:

    Serial.println((char)incomingByte);

Why does it gives me ASCII code when I run my code? Is it because Serial.print() data in ASCII code?

So, to print the same character you entered to serial monitor then the Serial.print needs to take the character as a whole is it?

Serial.println() has overloads for different data types, and will change the output format according to the type it gets passed.

When you use

Serial.println(incomingByte, DEC);

The ‘,DEC’ forces interpretation to decimal, and, as I think you also discovered, ‘,HEX’ will produce a different result, the ‘31’ you got earlier before modifying your post.

Thanks alot. One thing I noticed was when I enter '12' it gives me an output of 1 followed by 2 in the next line. So output 1 then 2. Is there anyway I can print it as together.

The output is now: I received: 1 I received: 2

I want it to be: I received: 12

That depends on whether you want to print the two characters '1' then '2', or the number twelve.

You seem to be dwelling on Serial.printing, which is not what you'll need to do to send data to your transceiver.

Ok, Serial.print() is just to print to computer screen, right? I was looking through stuff and always come up with virtualwire library. Is it a good choice to send data between a low cast transmitter and receiver of 433 MHz.

Serial.print() will write to whatever is connected at the other end of the serial connection. If your transceiver is connected to the serial port, then you need to use Serial.print(), or Serial.write(), depending on the data you want to send. If it's not connected to the serial port, then you need to use whatever is appropriate for the connection.

Very simple serial test code.

// zoomkat 7-30-11 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial test 0021"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(2);  //delay to allow byte to arrive in input buffer
    char c = Serial.read();
    readString += c;
  }

  if (readString.length() >0) {
    Serial.println(readString);

    readString="";
  } 
}
 while (Serial.available()) {
    delay(2);  //delay to allow byte to arrive in input buffer

Aren't the bytes there, if Serial.available is non-zero?

Aren't the bytes there, if Serial.available is non-zero?

Yes, I would think so.

I suggest that you take a look at this example: http://arduino.cc/en/Tutorial/SwitchCase2

Hopefully it will be what you are looking for.