Resuming on 33-1, Machan (81) and Wells put on 134 for the second-wicket before Machan was bowled by Ravi Patel (4-42).
Wells fell to Patel shortly after for 61, but Yardy's innings of 70 at Lord's helped the visitors up to 300 all out - a first innings lead of 66.
At stumps, Middlesex were 47-0, with Sam Robson racing to 41 not out, trailing by 19 runs.
A worn-looking pitch made Machan's fine knock all the more impressive, with Yardy and Wells taking a more workmanlike approach to their innings.
Patel was not introduced to the Middlesex bowling attacking until 150 runs were on the board but in just his second over he removed Machan, going on to add Wells, Chris Nash and Ben Brown.
Just as the home side were threatening to take control at 216-6, a Sussex fight back began, with Ashar Zaidi putting on 38 with Yardy, followed by a useful 40 from Yardy and Ollie Robinson.
James Harris finished off the Sussex tail with the wickets of Yardy and Chris Liddle in three balls, leaving the match finely balanced, and allowing Middlesex's batsmen to make vital ground before stumps.
Half-centuries from Luke Wells, Matt Machan and Michael Yardy gave Sussex a first innings lead against Middlesex.