There's a lot of cases account for your problems. At the first place, keep your SD card clean. If it is clean, then check if your SD card works normally. You can plug it into a card reader and connect to your computer to see if it can be detected. Once you don't find any problem, try checking if metal wires in the card slot get rusty and twisted on your phone. You can also turn to some article about SD doesn't detected by Android.