If you stay on devices for longer than what people would consider a normal sleeping schedule (say, telling yourself you want to try sleeping in at 8-9 PM, but you become restless and grab your phone to complain about it), it just so happens to be the light produced by the mentioned device that can and will pretty much keep you awake, and can make falling asleep a very difficult task.
This is where melatonin comes in. I'll snip a definition of it from umm.edu:
Melatonin is a hormone secreted by the pineal gland in the brain. It helps regulate other hormones and maintains the body's circadian rhythm. The circadian rhythm is an internal 24-hour "clock" that plays a critical role in when we fall asleep and when we wake up.
The melatonin relies on the intake of sunlight during the day to help keep your body awake and energized- even if you start the day off groggy. Think of it as an internal solar panel as well. This is why there's the classic drawing-the-curtains and letting the sunlight in schematic in a lot of shows/movies/etc. This also applies to the lights you intake from your devices- the really important part I'm gonna do my best to cover- whether it be from your PCs, phones, handheld consoles, etc.
The lights from the aforementioned items will make it difficult for you to try and knock yourself out when you want to. Thus, having the habit of staying on them for a long time cultivates a pretty nasty insomnia to deal with. After a while of staying up late, your body gets used to that 'schedule', thus creating a struggle for you when you try to regulate your sleeping schedule again.
It's funny because I have insomnia! Lololol.
Anyway, the first few steps to to help tackle against this may be the hardest. It starts with limiting the usage of your devices. Putting a strain on what you use would be for the best. You'll want to dedicate yourself to a schedule where you stop using your phone/computer/laptop/etc at, say, 8 PM. You'll then want to do an outdoor activity to distract yourself. Like taking a walk in your area, or chilling out on your porch/backyard, just about anything will do. If you don't think you live in an environment that lets you comfortably do that, doing stretches and listening to some chill music can also help out pretty well. Ambient music is pretty great btw. Keep it on a very low volume to let it lull you to sleep.
Also, this may sound really taxing, but having more errands to run throughout the day can also help exhaust you enough to make it easier to sleep at the right time. Hot showers/baths works wonders as well, depending on if you're into that.
These are all mostly suggestions that I have gathered from family members that have had trouble with regulating their sleeping in the past (like my sisters and my aunt, as well as my mother). I can say that a few have helped me pull back to falling asleep at least at around 2-3 AM, which is an achievement for me lol.
I hope this all helps grasp a general understanding of what you have to keep an eye on! Melatonin wants to be your friend, not your enemy.
I apologize in advance if this seems cluttered haha.