hello. how do i program the rs485 module with arduino mega? i need your help if you dont mind. thank you.

Which rs485 module would that be ?

the one that use on PC

I’ve never seen a consumer PC with RS485… Aka, more details please! It’s a XY-problem :wink:

i want to connect arduino with rs485 as a serial communication between smart transmitter with attached a load cell. how would i program them?

Step 1, learn to program
Step 2, break it up into little pieces
Step 3, learn how to ask specific questions

Rarely any problem can be described in just two lines like you try.

do you know rs485 right? i bet u know how the sketch looks like when it connects with arduino to make them communicate. that is why i asked you simple question cause i have googled about rs485 and tried but i dont get it.

i have googled about rs485 and tried

Please post what you tried, how the devices are connected and what happened when you ran the program.

I do know what RS485 is. And if I just connect it to an Arduino for single direction communication it looks like

Serial.print("Hello word!");

there is nothing happen. the load cell didnt read anything. wondering if my code is wrong or the connection.

wondering if my code is wrong or the connection.

If only we could see any of that ::slight_smile:

sorry i just re-sketch it.
so here is the code.

#include <SoftwareSerial.h>

int serialRX = 0;
int serialTX = 11;
int controlbutton = A8;

SoftwareSerial RS485(serialRX, serialTX); //receive pin, transmit pin

float loadA = 100; //g
float analogvalA = 1020; //analog reading taken with load A on the load cell
float loadB = 50; //g
float analogvalB = 510;
float analogValueAverage = 0;
long time = 0;
int timeBetweenReadings = 200;

void setup() 

void loop()
  int analogValue = analogRead(controlbutton);
  analogValueAverage = 0.99 * analogValueAverage + 0.01 * analogValue;

  if (millis() > time + timeBetweenReadings)
    float load = analogToLoad(analogValueAverage);

    Serial.print("analogValue: ");
    Serial.print("      load: ");
    Serial.println(load, 5);
    time = millis();

float analogToLoad(float analogval)
  float load = mapfloat(analogval, analogvalA, analogvalB, loadA, loadB);
  return load;

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
  return (x - in_min ) * (out_max - out_min) / (in_max - in_min) + out_min;

int serialRX = 0;It may not be such a good idea to use the hardware Serial Rx pin with SoftSerial, but it would certainly be a good idea to have

RS485.begin(your baud rate here);

somewhere in the program.

used that it says RS485 is not declare. so it needs to declare first?

used that it says RS485 is not declare. so it needs to declare first?

Where did you add it ?

You have an instance of SoftwareSerial named RS485 in your program.

Add the RS485.begin(your baud rate here); in setup() to set the baud rate for the RS485 object