I've always been of the belief that Heimerdinger is literally the most unhealthy champion in the game. He's like the Rengar of mages. You ask yourself if you have the prerequisites to beat him, and, assuming you don't, you just try to avoid confrontations with him as much as possible. This is because their damage is both high and extremely reliable, thus there's little counterplay beyond playing outside of their threat range. In Rengar's case, the prerequisite for beating him is to survive his burst then outstat him. For Heimerdinger, you must have the ability to remove his turrets without losing half of your health bar. Luckily, reaching that goal is doable with time.
To achieve that goal, you'll first need gold to purchase MR/HP. You should let Heimerdinger push the wave to you, then farm under tur. Don't bother trying to contest him if you don't think he'll die to an all-in; It'll just result in you eating damage and being guaranteed to die if you try to all in him again. You use that gold to buy an Adaptive Helm or Spirit Visage. Assuming he hasn't taken a large amount of plates or FAR more CS than you, you can then proceed to run him down with something like a Nasus. Step 1 to that is removing his turs, you'll know he's out when he starts to sit on 2 or 1 turs for extended periods of times. That is your time to strike. I have no advice for ADCs, though they should be capable of taking his turrets down at any stage in the game.