It clearly said in the comments that the code posted was a mess with several errors. The OP never responded to any questions so I would consider it to be useless.
Now if you want to ask a question then please supply a link to your board, and the data sheet for the device, along with a schematic showing how you have connected it all up the Arduino you are using, and we can start to see if we can help you.
Thanks, it looks straightforward enough. So exactly what do you want to do with it?
The first thing is to get the Arduino reading some data and then take it from there. So first of all how are you powering this and your Arduino?
The data sheet says
Connect sensor pin Vin-RXD-TXD-GND with 12V-TXD-RXD-GND.(Customers must use 3.3v/5vTTL level.
Why on Earth are you doing that? You have a Mega and that contains four serial ports so use one of the spare three ports available to you. Pin 14 is the TX output for Serial3 and Pin15 is the RX input for Serial3.
The first thing you need to establish on your sensor is which pin is sending data because the TX pin on the sensor could be an input or an output depending on if it is classed as a terminal or a computer. You need to connect the RX pin of the Arduino, which is an input to the Pin that is sending data.
The simplest way is to power up your sensor and look with an oscilloscope and see if you are getting pulses sent on the TX or RX pin of your sensor. If you haven’t got an oscilloscope the simplest way is to take a resistor and LED and connect one end to the 5V pin on the Arduino, connect the Arduino ground to the sensor’s ground and put the other end on the sensor’s TX and RX in turn. On one of them you should see the LED flicker every half second. The one that flickers should be connected to the Arduino’s RX3 pin and the other one to the TX3 pin.
Test that the LED lights up when you connect the other end of the resistor / LED to ground.
Connect sensor pin Vin-RXD-TXD-GND with 12V-TXD-RXD-GND.(Customers must use 3.3v/5vTTL lev
Oh, but I'm a newb, don't have code. I'm from Mechanical Engineering, trying to upload code for my DIY Oxygen Concentrator. If you can help me with any code source, it will be of great use for me.
I doubt very much if you will find any code for this. Therefore you will have to write it yourself. I have not got that device so I can't write code for you. The best I can do is to mentor you and we can work together to try and write it.