By default Raspberry Pi kernel uses the serial port to print boot-up information. In some cases you may want to control the serial port from your application code. to do this first you need to stop kernel from using the serial port for printing boot-up information. You can disable the serial port using raspi-config. Remember that you need to reboot the raspberry pi once you have changed the configurations.
Run the following command
you can find the serial port option in Advanced option(option 8)
you can read more about using serial port here