Hey guys,
i am looking for a way to send many Sensors Values from an arduino Mega to an other Mega.
like Temperature, pressure...
can you plz help me ? ![]()
A serial link is probably the easiest, particularly as the Mega has 4 hardware UARTs
Can you read and print the sensor values on one Mega ?
You can get yourself two Bluetooth modules (like hC-05 or HC-06, but make sure they are both the same) and set them up as master/slave. This will allow you to send a lot of information across. Additional information such as what your project is and the distance you need to send the data over will help us a lot more
yes i can read and print
so how can i use the serial link ?
the problem is i need just a communication without any other device ![]()
Over what distance ?
they are almost next to each other . i need a way to send many values from an arduino to an other without using any other device like bluetooth or Wlan ...
Try this
Connect pin 18 on Mega 1 to pin 19 on Mega 2 and vice versa
On Mega #1 print the values to Serial1
On Mega #2 if Serial1.avalable() is true then read a byte from Serial1 and print it on the Serial monitor
There is more to it, but what do you see on Mega #2 Serial monitor ?
i did it before but the problem if i write on Mega 1:
Serial1.print(Sensor1);
Serial1.print(Sensor2);
then how can i print them on arduino 2 ??
if (Serial1.avalable() ) {
aa = Serial.parseInt();
Serial.print(aa)}
do you have both arduinos connected to the PC each with an IDE open?
arduino 1 is coonected to the PC and arduino 2 is connected with arduino 1 :
GND to GND and 5v to VIN
didn't you correctly (tx->rx and rx<-tx) the serial1 pins of both arduinos together, as well?
i did
Serial1.println ()
or do you mean print from arduino2 to the PC?
in arduino 2 i have a tft touch screen.
so wehn i use Serial1.println how can i separate the Values ?
because they are may
if (Serial1.avalable() ) {
aa = Serial.parseInt();
Serial.print(aa)}
The data is arriving on Serial1 not Serial.
Use Serial1.parseInt()
you mean when you do a read Serial1?
what's the format of the data? (provide example of what you send)
ok this is an exemple: (Arduino1):
a=bme.readTemperature()*1010;
b=bme.readPressure()*10;
Serial1.println(a);
Serial1.println(b);
(Arduino2):
if (Serial1.avalable() ) {
aa = Serial1.parseInt();
Serial.print(aa);}
i want to print a spearated to b not together .
becausei will print them on a tft touch screen
how do you synchronize to know which is a and which b?
why not
Serial1.print (a);
Serial1.print (" ");
Serial1.println(b);
so you might receive 12.34 56.78
then read a complete line (\n terminated) and then extract two values from the received string.
you can print them separately on the tft screen
This tutorial demonstrates the procedures of sending two float type numbers from MEGA-1 to MEGA-2 and then MEGA-2 receives and shows them on its Serial Monitor.
1. Build the following UART link between MEGA-1 and MEGA-2.

Figure-1:
2. Upload following sketch in MEGA-1 (untested).
float x = 13.57;
float y = 57.68;
void setup()
{
Serial.begin(9600);
Serial3.begin(9600);
}
void loop()
{
Serial3.print(x); //send 13.57
Serial3.print('\n');
Serial3.print(y);
Serial3.print('\n');
//------------------
delay(1000);
}
3. Upload the following sketch in MEGA-2 (untested).
void setup()
{
Serial.begin(9600);
Serial3.begin(9600);
}
void loop()
{
byte n = Serial3.available(); //check if a data byte has come from InputBox
if (n != 0) //three bytes have arrived from InputBox For example: 0(MSB)10
{
Serial.print(Serial3.read());
}
}
4. Open SM2 with "Line ending tab" with "No line ending" option. Check that the OutputBox of SM2 shows the received float numbers.
5. If you want to store the received numbers of MEGA-2 into two float type variables, then you have to add some more codes with the sketch of MEGA-2. Also, you will be required to modify the codes of the sketch of MEGA-1 to send the float data in the following format:
0x02x,y0x0A //0x02 = start mark x=data1 , =data seperator y=data2 0x0A=end mark