In 3e, traps had CRs (I believe) but in 5e they are now classified as setback, dangerous, and deadly. Given a random dungeon, how do you DMs plan out traps based on the party's level? Is there a good rule of thumb way similar to experience point budgets? I'm new to DMing and don't want to murder the party with traps.
I would highly recommend the AngryGM article here.
Having traps for trap's sake is a bad idea and doesn't lend itself to organic flow. As AngryGM details they should be logically placed for a reason, either to funnel enemies to a desired location or path or to delay them long enough for a response. I warn you it is a long read but well worth it for newer DMs.
I personally use traps (depending on the creature that set them) to delay or harass a party, to use up a bit of their resources and soften them up before a combat encounter. Makes the party think a bit more about whether they should engage or fall back and try another approach.
Unearthed Arcana also published some testing material that I have found useful as well on designing and placing of traps.
There isn't really a good way to do it mathematically, so the answer comes down to how you usually end up actually running your dungeons.
If you want a dangerous crawl, then you'll need to map out the dungeon in full and place traps and monsters within. In this case a lot of it comes down to how your party is built. A group with two rogues and a barbarian is going to be able to handle significantly more dangerous traps than a group with four wizards.
If you want to try to "balance" it as an encounter of their level, look at how much damage an equal-level monster is going to do during a fight, on average. The trap should deal about that much damage to be considered equal XP value to the monster, because that's all a dungeon encounter is — something that makes the party expend resources (here hit points) before reaching their goal.
If you want a fun adventure where the party doesn't have to take things too seriously, you don't have to do much work at all! Just come up with a bunch of traps at each "danger level," as it were (setback/dangerous/deadly), and toss one in whenever there's a significant lull in the action.
Remember that there's a difference between a trap encountered in a random hallway and a trap in a combat. A trap on its own isn't usually a huge problem, especially if the party has a way to spot it. If the trigger is visible (like a differently-colored floor tile) then they can either find a way around the trigger, disable it, or try to find and block the payload. If the payload is visible (like a giant stone sphere), they can either try to find and avoid/disable the trigger or position themselves so that the payload won't hit them. You can take advantage of this to shape the party's actions. Want to make sure they find out what's in that side room? Pave the hallway straight ahead with really weird tiles — trap or not, they're not going down there until they have no other choice.
In combat, it's a different beast entirely. Now the party has significantly more limited options because of the presence of an active enemy, as opposed to the passive traps. You could either treat these as lair actions or tie them to specific tiles/triggers in the environment. For instance, a fight might take place in a long hallway. Halfway down this hall (and unbeknownst to the party) there is a section of floor that will fall away into a 10' pit when someone steps on it. Outside of combat, this would be a minor inconvenience, as you'd have a PC taking 1d6 damage at the worst. In combat, however, this is a powerful tool for the enemy to use, because now one of the PCs — probably a fighter, barbarian, or similar — has to basically lose a turn falling into the pit and climbing back out. Always consider the effects of a trap's surroundings, both from environment and creatures, on its effectiveness.
I'm sorry I couldn't really give a more mathematical answer, but there really isn't a reliable way to do it. The Unearthed Arcana article Slagmoth linked gives some advice about damage by level and the like, but the numbers really depend on your party composition. (I also just disagree with some of the things it says. A trap that deals more damage should be more likely to hit you? What? But that's a matter of personal preference.)
I would also urge you to avoid running traps as "make a perception check or you don't see it." Include descriptive elements that will provide players with a hint that something is wrong. The oddly-tiled floor described above is one such element, but it can be more subtle. The engravings of dancing men on the walls might have holes in their mouths, or there may be paintings hung on the walls, all looking at some object in the room. (Not mystically, just designed that way.) You don't even have to just say it without prompting, but if the players ask ("Is there anything unusual about the paintings?") don't make them roll for it; getting blown up because you rolled a 4 on a single check just isn't fun.