You don't specify the exact type of the device you have and I cannot find a link to a datasheet in you post too. I have to guess therefor. On the producers web site I cannot find a type of the sensor putting out TTL level signals. You may get 5V with a multimeter but most of the interfaces are differential or have at least positive and negative voltage levels. If you're connecting this device directly to your Arduino you may have already burned some of your pins, at least you won't get what you expect.
Post a link to the datasheet of the exact device you're connecting to and a photo or a drawing of the circuitry. The code you posted is very basic (but nevertheless badly formatted, try the auto format feature of the IDE) and probably not the problematic part in your project.
This meanns you have a RS232 version of the device. You need some kind of converter (e.g. MAX232) to generate the negative voltages even if you measure a 5V level with your multimeter for a logical 1, the logical 0 has to be negative and your Arduino cannot generate such levels itself, you may even destroy it's ports if you connect such a device directly.
I already have here the MAX232.
but I already have a MAX232
I haven't to build it.
Houston we have a (communication) problem.
A MAX232 is a chip, unless you have a billion-dollar fabrication facility you can't build one. You buy one, plug it into a circuit board with 4 capacitors, and connect it to an RS-232 line on one side and 5v serial on the other.
I will assume that you are really referring to the sensor when you say MAX232, please say "sensor" or something so there's no confusion.
That sensor communicates using three things.
RS-232 voltage levels (about +-12v)
Certain pin connections on a connector.
A protocol that defines the format of the data that is exchanged between the sensor and your computer (the Arduino in this case).
The RS-232 voltages are well defined and can be converted for your Arduino with a MAX232 chip which you will have to buy (do not connect the sensor directly to your Arduino).
However you need to determine the connector type, the pins used on the connector, and most importantly the protocol used before you have a hope of interfacing with this sensor.
That PDF is a sales brochure that tells us nothing useful, you need to get the above information from somewhere before we can do anything.
That's a start and it can replace the MAX232 chip I mentioned, but it has a DB9 connector (or headers) and your sensor does not, you still need to figure out how to connect it to the sensor and you still need to know the protocol used by the sensor.
Unless someone else has done this and is willing to divulge the information you have to get it from the sensor's manufacturer, I had a look around their web site and such details were not forthcoming so I suspect they consider it proprietary. They do have a development kit for the sensor, presumably that has the details.
Another alternative is to try and reverse engineer the sensor, this may not be too difficult if you have access to the inside of the box.
Ok but I have access to the protocol used by the sensor. Which information do we need?
Out of the specific problem, could you explain me why I need to put a circuit between the sensor with RS232 and the Arduino board to obtain the right voltage?
I ask this because on the data sheet they say that the IMU sensor could work between 4,5 V and 30 V.
So if I connect the red wire to the 5V pin (on the Arduino) where is the problem? I shouldn't have 12 V anywhere, isn't it?
In my reasonment there is surely something wrong but I can't see it for now.
I ask it to learn this things, I'm not an expert in electronics...so be patient please!
Ok but I have access to the protocol used by the sensor. Which information do we need?
All of it :), can you post the document?
So if I connect the red wire to the 5V pin (on the Arduino) where is the problem? I shouldn't have 12 V anywhere, isn't it?
It may do, if it is true RS-232 the voltage levels are +-12v even if you only supply 5v to the sensor. This is done with some magic circuitry that is normally inside a MAX232 chip.
As they call it an RS-232 sensor we have to assume that those voltages are present until it's proven otherwise. And +-12v will kill your Arduino.
So that looks like a pretty easy protocol to deal with, but you're a way's from that yet.
You need to get data into the Arduino and to do that you have to get the hardware working.
Identify the three wires you need from the sensor, GND, VCC (5V) and the RS-232 signal.
Connect GND and VCC to the Arduino and the RS-232 dongle.
Connect the serial signal from the sensor to either pin 2 or 3 or the DB9 connector on the RS-232 dongle. I don't know if it will be pin 2 or 3 because the stupid Microbot documentation doesn't have the pinout and there's no way of telling if they conform to the standard.
Connect Tx of the RS-232 dongle to Rx (digital pin 0) of the Arduino. Note that this connection will stop you from programming the Arduino so it must be removed every time you download a new program, another option is to use SoftwareSerial on another pin.
So the first thing to do is get some wires hooked up to the sensor, to do that you need more information about connecting to it.
Ok, I have to say that I already have a driver that is able to read the protocol. I've projected it in simulation, with the recorded signal of the sensor in input.
Now I have to try the driver in the real case substituting the simulated input with the real input arriving from the sensor through Arduino. I can't do it correctly if Arduino reads wrong values from the sensor.
For the connection, sorry again, I've just 4 wires arriving from the sensor without any DB9 connected to them; the 4 wires are ready to be connected.
These wires are: GND, VCC, TX, RX and I already have identified them.
At your 2) point: ok i connect the GND and VCC to Arduino ; but what do you mean with RS232 dongle? As I wrote upper in this post I've 4 "free" wires. So i could connect the wires directly inside the pins of the DB9 F if this is what you suggest.
With these new information, could you explain to me the points 2) and 3) of your post?
The yellow bits are only needed if you have to transmit to the sensor as well as read from it, is that the case?
The "Arduino in/output" pins are for using the hardware serial port with the restriction I mentioned before about programming the Arduino, if you use SoftwareSerial substitute 0 and 1 for any other pins, in this case there are no restrictions to programming.
I cannot tell you exactly which pins to connect to on the RS-232 gadget because it was/is common for people to swap pins 2 and 3. You will have to determine that by other means, measure with a DVM or get the data from Microbot.