Introduction: Simple Chat Program With Arduino Uno

Picture of Simple Chat Program With Arduino Uno

This will be my first post on Arduino projects, so instead of starting with the basics, I shall try something new. In this post, I am going to do a simple chat program using two Arduino Uno.

What you will need for the project:

1. 2 x Arduino Uno (or any other Arduino boards)

2. 2 x Jumper Wires

3. 2 x USB Cables

Step 1: Setup the Hardware

Picture of Setup the Hardware

The hardware setup is actually pretty simple. Just connect pin 10 of each Arduino to pin 11 of the other using the jumper wires. The theory behind this is that pin 10 is the RX pin and pin 11 is the TX. To communicate serially, you have to connect the TX to RX and RX to TX. Once that is done, connect it to your PC.

Step 2: Programming the Arduinos

Once you had successfully connected to your PC, then you can start programming your Arduino boards. I assume that you have your Arduino IDE installed, if not, head to this link here and download it. Arduino IDE download

In your PC, you will need to open two session of Arduino IDE. Make sure they can access two different ports. It must be opened differently and you should not open the other session in the same window. This will not work. The logic is that you need to open two IDE sessions so that your computer can communicate with both your Arduino serially, and print the results in the serial monitor. Once the IDE is up, download the below sketch to both of the Arduino.

/*<br>  Simple Chat Program
 
 Receives from the hardware serial, sends to hardware & software serial.
 Receives from software serial, sends to hardware serial.
 
 The circuit: 
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)
 
 created 16 August 2014
 modified 16 August 2014
 by William Chang Wei Tan
 based on SoftwareSerial example
 */
#include <SoftwareSerial.h>

SoftwareSerial chat(10, 11); // RX, TX

int text;

void setup() { // open hardware serial, TX = 1, RX = 0 Serial.begin(9600); Serial.println("Starting Chat Program..."); // set the data rate for the SoftwareSerial port chat.begin(9600); delay(1000); // delay 1s to stabilize serial ports chat.println("Hello World"); }

void loop() { if (chat.available()) Serial.write(chat.read()); if (Serial.available()) { Serial.print("Me:\t"); while (Serial.available()) { text = Serial.read(); chat.write(text); Serial.write(text); } chat.println(); Serial.println(); } }

Step 3: Run the Program

Picture of Run the Program

Now you can download the sketch to your Arduino and compile it. Once it's complete, open the serial monitor and start chatting with the other Arduino!

You've just created your very first chat program!

For more awesome stuffs, please visit my blog here

Comments

dhaval1994 (author)2016-09-05

Arduino soft help

eshan.wells (author)2015-01-14

Would this work one-way with a laser at one end and an LDR at the other? I think this would be a brilliant way to demonstrate the capabilities of fibre (fiber) optics at a school science fair.

OveT (author)eshan.wells2016-01-19

let me know if you ever did it and succeeded, Im doing a similar project for two way laser communication right now. :)

William Tan (author)eshan.wells2015-01-14

Yes, that would work, definitely! If you are interested, could you email me at cwtan229@gmail.com? and I could help in the science fair. :)

lysschndr_ (author)2015-02-20

How can I code my Bluetooth shield to become a slave? tia :)

Raphango (author)2014-08-19

Great! ^^

You could do this to work with an ethernet module and a 16x2 LCD for instance to add "distance" between the chatters! ;D

Thanks!

Redfinnsdad (author)2014-08-17

William, you should also connect the GND pins of the Arduinos together to provide a reference point. If you attempted to use two separate computers to communicate with your Arduinos they will not work properly if at all. Your solution works because the Gnd pins are connected by the USB ports being both plugged into the same PC.

William Tan (author)Redfinnsdad2014-08-17

Hey, thanks for the feedback. Yes I know that. Perhaps i should just add this point in. This is actually just to get familiarize with arduino. Was planning to make some other projects with two PC next time. Stay tune. :)

Cool!