The 36-year-old is due to appear at Edinburgh Sheriff Court after a gun was fired in Dalkeith in the early hours of Sunday morning.
No-one was injured and police said it did not appear any damage was caused to the property on Woodburn Road.
Searches took place on Meadowfield Terrace in Edinburgh and Kippielaw Steading in Dalkeith on Monday in connection with the investigation.
A firearm has since been recovered.
Ch Insp Kenny Simpson, of Police Scotland, said: "I want to stress this was an isolated incident and we are not looking for anyone else as part of this investigation.
"Nevertheless, we fully appreciate the impact this had on the local community and extensive inquiries were launched along with dedicated high-visibility patrols.
"A swift arrest has now been made and I want to thank residents for their assistance and support.
"Offences involving firearms will not be tolerated and should such crimes occur we will use all resources at our disposal to bring anyone found to be involved to justice."
A man has been charged after a firearm was discharged in Midlothian.