First, we have to have activated the usb debugging option on our android, that option is available in the developer options. To activate developer mode you must investigate on your device.
Download scrcpy from your official site
Once connected we must go to the folder where we have put it and run the terminal in that folder in my case cmd in windows.
Having connected our Android device, run to list all devices connected.
As we can see we see the connected devices, now we run a server in local network.
adb tcpip 5555
It is necessary that the laptop and the mobile are in the same network now in the configurations of the mobile we check the ip of the mobile and run.
adb connect <ip_addres_mobile>:5555
We can check with the command to list and something like this will appear (with the mobile disconnected from the usb).
Now run scrcpy.exe