In some projects Arduino required a distance monitoring or controlling is much more than 100 m. It certainly requires the validity of the data. If you just rely on data cable so it would be a lot of 'error'. One solution is to make communication between 2 Arduino. For example 1 Arduino as 'Master' which will display the sensor readings. At a distance of 300 m for example there is 1 Arduino as' Slave 'which reads the sensor then sends it to' Master. For communication that the distance is quite distant and requires accurate data validation then simply add RS232 module on each Arduino.
Hardware Requirement
- Arduino Uno Board (2 Unit)
- Power supply +5 Volt
- Jumper (Connector Cable)
Schematic
There are two different programs which use for Master (Sender) and one for Slave (Receiver)
Source Code for "Master"
#include <SoftwareSerial.h>
#define SSerialRX 8 //Serial Receive pin
#define SSerialTX 9 //Serial Transmit pin
#define Pin13LED 13
SoftwareSerial SSerial(SSerialRX, SSerialTX); // RX, TX
int byteReceived;
void setup()
{
Serial.begin(9600);
Serial.println("99+ PROYEK ARDUINO");
Serial.println("Master Serial...");
pinMode(Pin13LED, OUTPUT);
SSerial.begin(9600); // set the data rate
delay(3000);
}
void loop()
{
digitalWrite(Pin13LED, HIGH);
if (Serial.available())
{
byteReceived = Serial.read();
SSerial.write(byteReceived);
digitalWrite(Pin13LED, LOW); // Show activity
delay(200);
}
}
#define SSerialRX 8 //Serial Receive pin
#define SSerialTX 9 //Serial Transmit pin
#define Pin13LED 13
SoftwareSerial SSerial(SSerialRX, SSerialTX); // RX, TX
int byteReceived;
void setup()
{
Serial.begin(9600);
Serial.println("99+ PROYEK ARDUINO");
Serial.println("Master Serial...");
pinMode(Pin13LED, OUTPUT);
SSerial.begin(9600); // set the data rate
delay(3000);
}
void loop()
{
digitalWrite(Pin13LED, HIGH);
if (Serial.available())
{
byteReceived = Serial.read();
SSerial.write(byteReceived);
digitalWrite(Pin13LED, LOW); // Show activity
delay(200);
}
}
Source Code for "Slave"
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#define RX 8 //Serial Receive pin
#define TX 9 //Serial Transmit pin
#define Pin13LED 13
SoftwareSerial SSerial(RX, TX); // RX, TX
LiquidCrystal lcd(2,3,4,5,6,7);
int byteReceived;
int byteSend;
void setup()
{
pinMode(Pin13LED, OUTPUT);
SSerial.begin(9600);
lcd.begin(16, 2);
lcd.print(" Serial Slave ");
lcd.setCursor(0,1);
}
void loop()
{
if (SSerial.available())
{
byteReceived = SSerial.read(); // Read the byte
lcd.setCursor(0,1);
lcd.print(char(byteReceived));
digitalWrite(Pin13LED, HIGH); // Show activity
delay(200);
digitalWrite(Pin13LED, LOW);
}
}
#include <SoftwareSerial.h>
#define RX 8 //Serial Receive pin
#define TX 9 //Serial Transmit pin
#define Pin13LED 13
SoftwareSerial SSerial(RX, TX); // RX, TX
LiquidCrystal lcd(2,3,4,5,6,7);
int byteReceived;
int byteSend;
void setup()
{
pinMode(Pin13LED, OUTPUT);
SSerial.begin(9600);
lcd.begin(16, 2);
lcd.print(" Serial Slave ");
lcd.setCursor(0,1);
}
void loop()
{
if (SSerial.available())
{
byteReceived = SSerial.read(); // Read the byte
lcd.setCursor(0,1);
lcd.print(char(byteReceived));
digitalWrite(Pin13LED, HIGH); // Show activity
delay(200);
digitalWrite(Pin13LED, LOW);
}
}
How it Works
1. Connect the Arduino with Peripherals needed
2. Plug in the Power Source on the device
3. Compile and upload the script program above to your arduino
4. The Arduino "Master" stays connected to the serial port of computer / laptop.
5. Open Serial monitor as monitoring data transfer and set the baud rate to 9600 and "No line ending"
6. Type one character with your keyboard and click on send tab, or just press enter keyboard
7. Look at the result on the LCD, that's the the same data like before
8. If you want to apply this for long distance use, just connect each arduino with the RS232 module
RS232 Module | Source
Video for Project V - 37. Serial Communication Arduino to Arduino
Required File
No comments:
Post a Comment