The example you gave (link), I think just checks for a car at or near the stop line? It's got absolutely bugger all to do with "traffic density". There's no count, which is presumably why you said it's not what you want.
Coding specifics aside for a moment, how do you count cars when the traffic's stopped on that leg? There's no increment to the count since it's not passing the sensor, but there's a line of cars...
Can you describe for us "a day 10 minutes in the life" of this intersection, from a starting point where (say) there's been no traffic for ages and the lights are in some default state, perhaps giving each side equal time or whatever. What do you want to happen as cars start to arrive on each leg? Where will you be doing the counting?
the time for the traffic lights to lit up depents upon the counting of the sensors.
That's not a coding issue; that's a deciding how you want this thing to work, issue.
Get hold of a traffic engineering handbook and read up on the ways to monitor traffic and time the lights accordingly. The coding (as is very often the case) will be quite straightforward: the real challenge is for you to write down in words what it is you want to happen.
In another thread about line monitoring and obstacle avoidance, I suggested that poster lay out his or her path and walk around it. You could do the same: chalk out your intersection on your driveway or draw it on flip chart sheets on the floor, and get a pile of stones to be cars. Move them around and get it clear in your head how counting the movement of cars will actually translate into something you can use to adjust the timing. (It may not need to be too scientific: a sort of fuzzy approach might work- if the traffic is "a bit heavier" on one side, give that side "a bit more" green; if it's "way heavier" give it "way more" green.)
This is a classic case of trying to Don't put the coding horse before the application understanding cart; pardon the cliche. (I normally avoid cliches like the plague....) (edit: apology: Was a bit harsh there, you are asking in Project Guidance after all, not Programming, and your question is about the approach to turning the count into time, not the lines of code that do that.)
Edit... There are very likely to be state machines in your future.