Max232 with Arduino communication

Hello

I am trying to receive data from Max232 module via software serial and switch on LED connected to Arduino

the pin connection is as follows
Max232 Arduino
Rx 6 (Software serial)
Tx 7( Software Serial)
Gnd Gnd
+5V +5V

#include <SoftwareSerial.h>
#include <string.h>
#include <stdio.h>
uint8_t recv_char;
char recv_str[20];
int i=0;

SoftwareSerial mySerial(6, 7); // RX, TX
#define LED 8
void setup()
{
  
  Serial.begin( 2400 );                   //Set the baund rate as 2400 for arduino serial 
  Serial.println("USB Serial is ready");
  mySerial.begin( 2400 );                 // set the baund rate for the SoftwareSerial port
  pinMode(LED, OUTPUT); 
  digitalWrite(LED,HIGH);   
}

void loop()
{ 
  if ( mySerial.available() )
  {
    recv_char =  mySerial.read();
    if(recv_char == '\r'){
      recv_str[i] = '\0';
      if(!strcmp(recv_str, "ON")){
        digitalWrite(LED,HIGH);
        Serial.println("high");
      }
      if(!strcmp(recv_str, "OFF")){
        digitalWrite(LED,LOW);
        Serial.println("low");
      }
      Serial.println(recv_str);       // Write the serial from MAX3232 to Arduino serial 
      i=0;
      memset(recv_str, 0, sizeof(recv_str));
    }
    else{
      if(recv_char == '\r' || recv_char == '\n'){
    } 
      else{
        recv_str[i++] = recv_char;
        }
    }
   
  }

  if ( Serial.available() )
  {
   recv_char =  Serial.read();
    if(recv_char == '\r'){
      recv_str[i] = '\0';
      mySerial.println(recv_str);       // Write the serial from MAX3232 to Arduino serial 
      i=0;
      memset(recv_str, 0, sizeof(recv_str));
    }
    else{
      if(recv_char == '\r' || recv_char == '\n'){
    } 
      else{
        recv_str[i++] = recv_char;
        }
    }
     
  }
}

1. Are you using software serial port (SUART) of Arduino UNO to receive data from a remote device which delivers RS232 signal?

2. What type of remote device/controller you have?

3. What type of signal (string, single character, byte, float) you are expecting to receive from the remote controller?

4. In the above process, what is the problem you are facing?

Yes I am using software serial to receive data from rs232
I am using Arduino Uno and for Rs232 , I am using Max232 IC module with DB9 connector
Data expecting to receive is string

I am not receiving any data at the arduino when I send data from rs232 port

1. What kind of device is connected at the other side (the sender) -- is it another Arduino?

2. Are you using the following RS232<----> TTL conversion module (Fig-1) or a stand-alone MAX232 chip (Fig-2)?


Figure-1:


Figure-2:

3. If you have two Arduino (UNO/NANO/MEGA), you may connect them together using hard/soft serial port to exercise the process of writing sketches to exchnage string type data. Sometimes, it is difficult to debug 3rd party's codes without having basic understanding of the communication protocol used.

Yes i have connected the Max232 module (fig 1) with Software serial pins of arduino uno .

The data is sent via serial monitor.

this is the connector used between betweeen RS232 module and PC
image

Is there any other way i could check whether the module is working ?

please show pictures of your wiring - each wire - each module must be clearly visible.

there are two potential problems (potential - as we can't see on your desk):

  • the wiring between the Arduino and the MAX232 Module
  • the wiring between the MAX232 Module and your device

This is the connection between arduino uno and DB9 module

the connector used for PC is db9 to USB connector

1. Make the following setup (Fig-1):


Figure-1:

2. Do not connect USB-2 cable with PC. Connect only the USB-1 cable.
3. From start menu, open an IDE; be sure that correct COM port has been assigned for UBS-1 cable. After that Upload the sketch of your post #1. Open the Serial Monitor-1 at Bd = 2400.

4. Connect USB-2 cable.
5. From start menu, open a second IDE; be sure that correct COM port has been assigned for USB-2 cable. After that open the Serial Monitor-2 at Bd = 2400. Choose Carriage return option for Line ending box of Serial Monitor-2 (Fig-2).


Figure-2:

6. Enter Hello in the InputBox of Serial Monitor-2 and click on the Send Button.
7. Check that Hello has appeared on the OutputBox of Serial Monitor-1.
8. If the above steps work, then it is fine; else, wait to receive help once I return home from my works.

Good luck!

Check if the Max232 module is functioning correctly. You might want to test it with another device or use an oscilloscope/logic analyzer to inspect the signals.

Thank you for elaborated explanation let me test this

Let me test the module as well

it's difficult to see, but change the connection to
Pin 6 --> TX on the board and
Pin 7 --> RX on the board

what happens?

Thank you i am able to see the response but data is shown as numbers... is it becos of ASCII code conversion ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.