# Serial communication with sensor not working as expected

**URL:** <https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604>\
**Category:** General Guidance\
**Created:** [April 13, 2022, 2:27pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604 "2022-04-13T14:27:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![holder12](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@holder12](https://forum.arduino.cc/u/holder12)\
**Post date:** [April 13, 2022, 2:27pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/1 "2022-04-13T14:27:29Z")

</div>

Hello, please read my post carefully as I've already done a LOT of troubleshooting on this.

So I have a sensor that streams comma delimited ASCII data constantly. It streams at 4800 baud rate on RS-232 protocol. I have gotten this sensor to send data to my PC through a RS232-USB cable. I know that this sensor works correctly.

When I connect this sensor to a MAX232 breakout board ([this board specifically](https://www.mikroe.com/max232-board)) and then connect that to my Arduino uno, I absolutely cannot get it to output any readable data of any kind. I know that the sensor works and streams, I know that the MAX232 board works (I've used it in other projects), and I know that my arduino serial ports/code works (tested with other devices). But none of it works when put together. Here is my code:

```cpp
#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 5, 1); // RX, TX
String content = "";
char character;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Native USB only
  }

  Serial.println("hello");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  //mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  //Serial.println(mySerial.available());
  while (mySerial.available()>0) {
    Serial.print(mySerial.read());
   
  }
  Serial.println();
    
  delay(50);
}

```

It's a super basic serial streaming code, I'm using softwareSerial library to try and read the serial input from the sensor to my PC. What happens is that I will usually get no answer from the sensor even though I know that data is streaming on it, I checked with my oscilloscope and saw the data coming in on the MAX232 serial pin, the arduino just isn't doing anything for some reason?? Or if I fiddle with any small settings, or turn my sensor off then on again, sometimes I can start to get a bit of data in on the port, but it ends up being a stream of numbers that can't be converted properly to ASCII format or anything?? Again, remember, I've connected this sensor directly to my PC and had no problem streaming in the readable ASCII data.

I've found that when I set the softwareSerial to inverse\_logic, I tend to get something more often than if I do not set it to inverse\_logic. Would anyone have an explanation for this?

I have tried with Serial.write() and Serial.print() and neither function gives any readable results, if any results at all.

Also, PLEASE do not come at me with any stuff about "Have you checked that you have the right baud rate?" YES I HAVE THE CORRECT BAUD RATE!! THIS SENSOR WORKS AT 4800 BAUD, IT IS IN THE DATASHEET, IT WORKS WHEN CONNECTED TO MY PC!

This is seriously driving me insane, I can't figure out what is wrong, other people can't figure out what is wrong, why won't this sensor simply stream to the arduino? Is it a timing issue? Am I missing something with converting the incoming data? Why does the data not show up at all when I don't set the inverse\_logic to 1? When it does show up, it is either a stream of integer/decimal numbers, or hex numbers (if I set the serial output to hex), that can't be converted to readable ASCII. Any explanation for this?

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [April 13, 2022, 2:31pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/2 "2022-04-13T14:31:46Z")

</div>

Sounds like you are confused about RS232 voltage levels (-12 to +12V, inverted logic) versus TTL level RS232 serial.

The adapter you linked is for the old style +/- 12V, inverted logic RS232.

Post a complete wiring diagram and a link to the sensor product page or data sheet.

---

<div class="post-metadata">

**Author:** ![holder12](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@holder12](https://forum.arduino.cc/u/holder12)\
**Post date:** [April 13, 2022, 2:36pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/3 "2022-04-13T14:36:50Z")

</div>

Thanks for the reply. I am a bit confused about what you're saying, so even though my sensor communicates through RS-232, my MAX232 board might not be compatible with it? Here is an info sheet for the sensor: [https://www.airmar.com/uploads/Brochures/WX-OFFSHORE.pdf](https://www.airmar.com/uploads/Brochures/WX-OFFSHORE.pdf)

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [April 13, 2022, 2:39pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/4 "2022-04-13T14:39:52Z")

</div>

The sensor data sheet does not state the details for the connection, or the voltage levels of the RS232 connection.

Post a wiring diagram showing how you connected it to a PC and got it to work.

---

<div class="post-metadata">

**Author:** ![wildbill](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wildbill/32/1126438_2.png) [@wildbill](https://forum.arduino.cc/u/wildbill)\
**Post date:** [April 13, 2022, 2:40pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/5 "2022-04-13T14:40:08Z")

</div>

If it's RS232, it may need one of the control signals (DTR, CTS etc.) hooked up too.

---

<div class="post-metadata">

**Author:** ![holder12](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@holder12](https://forum.arduino.cc/u/holder12)\
**Post date:** [April 13, 2022, 2:41pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/6 "2022-04-13T14:41:11Z")

</div>

It does not need CTS or DTR hooked up. When I connect it to PC I only use RX, TX, and GND.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [April 13, 2022, 2:42pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/7 "2022-04-13T14:42:14Z")

</div>

> [@holder12](#):
>
> so even though my sensor communicates through RS-232

This does not mean much to us.

---

<div class="post-metadata">

**Author:** ![holder12](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@holder12](https://forum.arduino.cc/u/holder12)\
**Post date:** [April 13, 2022, 2:44pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/8 "2022-04-13T14:44:02Z")

</div>

The wiring is very straightforward. I have a 12V power supply powering it on PWR and GND pins. The RX pin goes to the RS -232 DB9 pin 2. The TX pin goes to RS-232 DB9 pin 3. The GND is also connected to GND on the DB9, pin 5. The DB9 is plugged in to an RS232-USB cable. The cable goes in to the PC.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [April 13, 2022, 2:46pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/9 "2022-04-13T14:46:38Z")

</div>

That suggests that the device does indeed use +/- 12V levels and inverted logic.

The adapter you linked should work, but you forgot to post a wiring diagram showing how you connected the sensor to the adapter, and the adapter to the Arduino.

If you want help, you need to provide useful information.

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [April 13, 2022, 2:48pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/10 "2022-04-13T14:48:43Z")

</div>

You may be able to dial back your super basic setup even further as a temporary sanity check. I think this will work and simply turns your UNO into a USB-serial adapter.

If you connect your UNO via USB and set the IDE serial monitor to 4800 baud, then connect the MAX232 board to the UNO 5V and GND. Take the MAX232 board RX signal and connect it to UNO pin 1. Press and hold the UNO RESET button. That should keep the 328P in the reset state and allow you to use the serial lines. The IDE serial monitor should show the data coming from the MAX232 board.

---

<div class="post-metadata">

**Author:** ![holder12](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@holder12](https://forum.arduino.cc/u/holder12)\
**Post date:** [April 13, 2022, 2:49pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/11 "2022-04-13T14:49:14Z")

</div>

RX pin on the MAX232 breakout board is connected to digital pin 4 on the uno.  
TX pin on the MAX232 breakout board is connected to digital pin 5 on the uno.  
5V on the MAX232 breakout board is connected to the 5V pin on the uno.  
GND on the MAX232 breakout board is connected to GND on the uno.

I have tried RX/TX connected on pins 2 and 3 of the uno as well just to be thorough, and that did not make a difference. I have also tried swapping RX/TX pins to see if I had them connected backwards. That doesn't _seem_ to be the case but maybe I got them mixed up.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [April 13, 2022, 2:50pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/12 "2022-04-13T14:50:57Z")

</div>

I'm out. Good luck with your project.

---

<div class="post-metadata">

**Author:** ![Paul\_KD7HB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_kd7hb/32/1127958_2.png) [@Paul\_KD7HB](https://forum.arduino.cc/u/Paul_KD7HB)\
**Post date:** [April 13, 2022, 2:52pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/13 "2022-04-13T14:52:31Z")

</div>

Specifically, which Arduino board are you using?

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [April 13, 2022, 2:54pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/14 "2022-04-13T14:54:59Z")

</div>

Hi,  
Have you tried not using the inverted software serial parameter?

```cpp
SoftwareSerial mySerial(4, 5, 1); // RX, TX

```

to

```cpp
SoftwareSerial mySerial(4, 5); // RX, TX

```

Tom... 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![holder12](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@holder12](https://forum.arduino.cc/u/holder12)\
**Post date:** [April 13, 2022, 2:55pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/15 "2022-04-13T14:55:25Z")

</div>

I did that and no data came through on the monitor. So maybe the problem lies with whatever is going on between the MAX232 and the sensor? It's odd because on my scope I do see data coming out on the RX pin of the MAX232, so it's like data is getting through. But maybe it's garbled...?

---

<div class="post-metadata">

**Author:** ![holder12](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@holder12](https://forum.arduino.cc/u/holder12)\
**Post date:** [April 13, 2022, 2:55pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/16 "2022-04-13T14:55:55Z")

</div>

Yes, I have and I end up getting no data whatsoever, no communication at all. I mentioned that step in the original post. If you have any theories for why inverted/not inverted matters I'd like to hear it.

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [April 13, 2022, 2:56pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/17 "2022-04-13T14:56:45Z")

</div>

Can you get a screenshot of your scope showing the data? Even if it's just the amplitude of the signal referenced to GND.

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [April 13, 2022, 2:58pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/18 "2022-04-13T14:58:09Z")

</div>

> [@holder12](#):
>
> I absolutely cannot get it to output any **readable data** of any kind

> [@holder12](#):
>
> I have and I end up getting no data whatsoever, no communication at all.

So you do get some data with your hardware setup?

What do you get?

Tom... 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![holder12](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@holder12](https://forum.arduino.cc/u/holder12)\
**Post date:** [April 13, 2022, 3:00pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/19 "2022-04-13T15:00:19Z")

</div>

When I do inverse\_logic = 1, I get some data, but it is not readable. If I use serial.print it comes in as a line of decimal numbers that I cannot convert to ASCII. If I use Serial.write it comes in as backwards question marks.

When I do inverse\_logic = 0, I get no communication whatsoever. mySerial.available always equals zero. I have no clue about what these findings mean.

---

<div class="post-metadata">

**Author:** ![holder12](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@holder12](https://forum.arduino.cc/u/holder12)\
**Post date:** [April 13, 2022, 3:02pm UTC](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604/20 "2022-04-13T15:02:42Z")

</div>

![SDS2354X Plus_JPG_1](https://europe1.discourse-cdn.com/arduino/original/4X/0/d/d/0dde711e54db5c0522906f45322dc002c4db4af5.jpeg)  
Apologies if it's not a great scope picture, hopefully it contains the info you need.

[Next page](https://forum.arduino.cc/t/serial-communication-with-sensor-not-working-as-expected/980604.md?page=2)
