It used to be that dryers functioned purely on timed settings. You would choose a cycle and it would run for a predetermined time. Modern dryers still have that, but the default setting is now a cycle that lengthens and shortens based on how wet the actual clothing is. This is thanks to the addition of a moisture sensor. This little strip detects the moisture level of the clothing that brushes past it and stops the cycle accordingly.
Unfortunately, if it is not working, this can result in the dryer running non-stop or not running at all. If you think the moisture sensor is not working correctly, you can actually test it first.
To test your moisture sensor, run your dryer with a few pieces of completely dry cloth. This will see that your dryer will run for about five minutes at most before it shuts off. You will also need to run a test to check the opposite function. In this, you want to put wet clothing in that is all the same material and roughly the same density. This is a pretty good time to dry a load of towels, for example. The dryer should run until everything is dry. You can be more conclusive by using less wet cloth, but you need to use enough so that it is regularly triggering the sensor.
Your dryer needs to pass both of these tests in order for you to conclude that the moisture sensor is working properly. If it does pass, you may want to consider that it is actually a problem heating properly or rotating. Sometimes it is just that clothing gets too packed together that it won’t dry properly. If it doesn’t pass, you unfortunately need to disassemble quite a bit of the dryer in order to replace a faulty moisture sensor.