Oscar Ortega-Hernandez of Idaho appeared in a Pittsburgh court after his arrest on Wednesday at a hotel in Pennsylvania, according to the US Secret Service.
No one was hurt in the shooting on Friday night and Mr Obama and wife, Michelle, were not in Washington at the time.
The Secret Service said one bullet broke a White House window but was stopped by protective ballistic glass, and the other round struck the exterior of the building.
Two cars were seen racing from the scene. One vehicle was found abandoned nearby with a semi-automatic rifle on board, authorities said.
Ortega-Hernandez was charged with attempted assassination of the president, Assistant US Attorney James Kitchen said at the court hearing. Authorities said they will be moving him to custody in Washington.