error using rx

hi for my project I need to use RX port to receive data from the sensor & parallelly I'm using sd card also.

the main task is to synchronize both but due to rx pin from the sensor I'm getting an error called programmer is not responding

when I remove the rx pin from the board, there is no such error

sensor PORTS Info( TX-OUT,5V,GND), PLEASE HELP ME WITH SOLUTION

Nothing can be connected to the Serial port while programming.

Consider using a Mega with multiple Serial ports.

DrDiettrich:
Nothing can be connected to the Serial port while programming.

Consider using a Mega with multiple Serial ports.

Thanks

Instead of using Arduino Mega 2560, you should get value from your sensor using Software Serial. Mega is costly plus bigger in size. Software Serial in Arduino is not that difficult, you will find example code in Arduino IDE.

jackthom41:
Instead of using Arduino Mega 2560, you should get value from your sensor using Software Serial. Mega is costly plus bigger in size. Software Serial in Arduino is not that difficult, you will find example code in Arduino IDE.

That depends on baudrate, number of databaits and stopbits and parity. SoftwareSerial does not perform well (to my understanding) at higher baudrates and does only support 8N1.

#include <SoftwareSerial.h>
int sensorValue; // variable to store the value coming from the sensor

SoftwareSerial serial(19,18);

char sbuffer[14], ch;
unsigned char pos;
unsigned char read1, read2, read3;
boolean newData=false;

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

Serial.println("");
}

void loop() {

Serial.println("C0");

if (Serial.available() > 0)
{
Serial.println("C1");
while(Serial.available()>0)
{
ch = Serial.read(); //loop till character received
if(ch==0x0A) // if received character is , 0x0A, 10 then process buffer
{
pos = 0; // buffer position reset for next reading
newData=true;
// extract data from serial buffer to 8 bit integer value
// convert data from ASCII to decimal
read1 = ((sbuffer[1]-'0')*100) + ((sbuffer[2]-'0')*10) +(sbuffer[3]-'0');
read2 = ((sbuffer[6]-'0')*100) + ((sbuffer[7]-'0')*10) +(sbuffer[8]-'0');
read3 = ((sbuffer[11]-'0')*100) + ((sbuffer[12]-'0')*10) +(sbuffer[13]-'0');

Serial.println("C3");

}
else
{ //store serial data to buffer
sbuffer[pos] = ch;
pos++;
}
}
}
showNewData();
}

void showNewData() {
if (newData == true)
{
Serial.println("Calculating Results ... ");
Serial.println(read1);
Serial.println(read2);
Serial.println(read3);
newData = false;
}
}

output i can get as arduino is ready, c0 (no errors, using mega connected with sd card)

Please read How to use this forum - please read. - Installation & Troubleshooting - Arduino Forum, specifically point #7 how to post code. Next modify reply #5 and add the code tags.
2)
You're using a mega; there is no need to use SoftwareSerial on a hardware serial port (pins 18 and 19 are Serial1).
3)
Do not differentiate variables based on capitalisation (Serial vs serial).

==============

Your code reads data from the serial port that is connected to the PC; do you actually send something? What is your line-ending set to in serial monitor; it needs to be newline or carriagereturn plus newline.

Assigning values to readX should actually be done in showNewData and not in the serial communications part of the code.

sterretje:
1)
Please read How to use this forum - please read - Website and Forum - Arduino Forum, specifically point #7 how to post code. Next modify reply #5 and add the code tags.
2)
You're using a mega; there is no need to use SoftwareSerial on a hardware serial port (pins 18 and 19 are Serial1).
3)
Do not differentiate variables based on capitalisation (Serial vs serial).

==============

Your code reads data from the serial port that is connected to the PC; do you actually send something? What is your line-ending set to in serial monitor; it needs to be newline or carriagereturn plus newline.

Assigning values to readX should actually be done in showNewData and not in the serial communications part of the code.

i'm reading the data & using that data to do something(which i cannot tell),

i didnot understand this line "Assigning values to readX should actually be done in showNewData and not in the serial communications part of the code."

can you please send me the code what exactly u mean?

sterretje:
3)
Do not differentiate variables based on capitalisation (Serial vs serial).

It looks to me like that is exactly what has come to bite the OP :slight_smile:

kammatisai:
i didnot understand this line "Assigning values to readX should actually be done in showNewData and not in the serial communications part of the code."

You should have two (or more) layers. The function of the first layer is solely to read data from the serial port. The function of the second layer is to parse the received data which e.g. includes the conversion from ascii to numbers so it's ready for further processing. There should be a third layer that does the actual processing of the parsed data; if so inclined, you can do that in the second layer.

kammatisai:
i'm reading the data & using that data to do something**(which i cannot tell)**,

Why not?