Narrative:

I was taking a student to ZZZ for a checkride. I was the pilot flying so he could relax a bit before the ride. Our route of flight was direct zzzzz direct ZZZ. We departed ZZZ1 at roughly xa:00am local time. After departing the area to the north I went direct zzzzz that way we will stay clear of all parts of the bravo at 7;500 feet. The GPS looked good; zzzzz was in the right spot; the course looked good; so we continued direct. We arrived at out destination about an hour and a half later. Flight on the way back was the same route. Upon looking at the flight in foreflight; some time later; I had discovered I did not fly direct zzzzz. The GPS showed zzzzz; but we were far from it. When we were approximately 3.5 NM to the north east of [track] I was within 200 feet of the bravo laterally at 7;500 feet next to the 7000/1;2000 foot shelf. After thinking about how this could have happened I came to the conclusion that the obs button was hit sometime before I hit direct zzzzz. I had not noticed the obs was on; and taking us on a different route. This entire situation could have been avoided if I would have done one of a few things. First; I could have seen the obs was on. Second; I should have been with flight following. They would have helped us out to get squared away. Third; if I had foreflight open I could have seen we were not on our planed route. From this experience I will be with flight following when that close to the bravo; and I will always be checking my surroundings more no matter the flight.

Google
 

Original NASA ASRS Text

Title: C172 instructor was pilot flying and reported not following published procedures; causing a track deviation.

Narrative: I was taking a student to ZZZ for a checkride. I was the Pilot Flying so he could relax a bit before the ride. Our route of flight was direct ZZZZZ direct ZZZ. We departed ZZZ1 at roughly XA:00am local time. After departing the area to the north I went direct ZZZZZ that way we will stay clear of all parts of the Bravo at 7;500 feet. The GPS looked good; ZZZZZ was in the right spot; the course looked good; so we continued direct. We arrived at out destination about an hour and a half later. Flight on the way back was the same route. Upon looking at the flight in ForeFlight; some time later; I had discovered I did not fly direct ZZZZZ. The GPS showed ZZZZZ; but we were far from it. When we were approximately 3.5 NM to the north east of [track] I was within 200 feet of the Bravo laterally at 7;500 feet next to the 7000/1;2000 foot shelf. After thinking about how this could have happened I came to the conclusion that the OBS button was hit sometime before I hit direct ZZZZZ. I had not noticed the OBS was on; and taking us on a different route. This entire situation could have been avoided if I would have done one of a few things. First; I could have seen the OBS was on. Second; I should have been with flight following. They would have helped us out to get squared away. Third; if I had foreflight open I could have seen we were not on our planed route. From this experience I will be with flight following when that close to the bravo; and I will always be checking my surroundings more no matter the flight.

Data retrieved from NASA's ASRS site and automatically converted to unabbreviated mixed upper/lowercase text. This report is for informational purposes with no guarantee of accuracy. See NASA's ASRS site for official report.