Home > Arduino > Send serial data (strings) from Arduino

Send serial data (strings) from Arduino


So I have some spare time, so I looked at the Serial Communication using the Arduino device. I was able to successfully send messages from the Arduino board to the Arduino Serial Monitor on my laptop. I was able to send simple  hard coded values as well as dynamically generated string messages.

#include <stdio.h>

char serialstring[35];

void setup() {  
   Serial.begin(9600);
}

void loop() {  
 //print string directly  
 Serial.println("This is a hardcoded string");
    delay(1000);  
 //setup string in a variable  
    strcpy(serialstring,"This is a string inside a variable");
    Serial.println(serialstring);//print string variable  
    delay(1000);

    for(int j=0; j<3; j++) {   
 //print the value of the variable J 
        sprintf(serialstring,"Dynamic Message. Variable J = %d",j);    
        Serial.println(serialstring);    
        delay(500);    
    }  
    delay(10000);
}

Once uploaded the results are as expected

And this concludes the Serial Communication Test for now. I think I will look at sending strings to the Arduino next time.

About these ads
  1. No comments yet.
  1. No trackbacks yet.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: