Hi ida261,
Thanks for reaching out in Apple Support Communities. It sounds like you're trying to connect your Mac and iPhone with your Apple TV so you can take advantage of mirroring and AirPlay. I know how convenient it is to use your devices with each other; I'd like to help. First, I'd like to clarify that you can only AirPlay from a Mac or iPhone to an Apple TV device, it's not possible to AirPlay or mirror from a Mac to iPhone.
If you're attempting to use the Mac or iPhone with an Apple TV device and you're not seeing the code appear on your Apple TV, or you're not being prompted on your iPhone or Mac to enter the code, I'd recommend taking a look at this resource to verify that you're set up properly to use AirPlay and mirroring: How to AirPlay video and mirror your device's screen
Once you've verified your set up, if you're still having trouble, take a look at the steps here for further troubleshooting: If AirPlay or screen mirroring isn’t working on your device
If I've missed the mark on the issue you're having, please feel free to reply with additional details.
Best Regards.