When you're using an app you downloaded, you need to grant permission for it to access the microphone. In the iPhone, you control app access in the settings, but you usually are asked to allow access when you first open the app after downloading it. If you ever have a problem using your mic while in a third-party app, though, go to the Settings app to troubleshoot it.
For issues that happen when you aren't in a third-party app, things are a little more complicated. If all is well with your iOS microphone settings, you may have a hardware problem. In some cases, fixing that issue is as simple as clearing away debris that has collected in your device's microphone. If that doesn't resolve it, you need to troubleshoot to see if it's time for a hardware repair.