Date: 202107
Local time of day: 0601-1200
Location: ZZZ.Airport, US
Flight conditions: VMC
Weather elements / visibility: 10
Light: Daylight
Aircraft: DA40 Diamond Star
Operator: Personal
Operating under: Part 91
Flight plan: None
Mission: Training
Flight phase: Initial Approach
Airspace: Class D ZZZ
Second aircraft: Piper Aircraft Corp Undifferentiated or Other Model
Reporter organization: Personal
Reporter function: Pilot Flying; Instructor
Reporter qualification: Flight Crew Instrument; Flight Crew Commercial; Flight Crew Flight Instructor
Human factors: Situational Awareness; Communication Breakdown
Anomaly: ATC Issue All Types; Conflict NMAC; Deviation - Track / Heading All Types; Deviation / Discrepancy - Procedural Clearance
Detector: Automation Aircraft TA; Person Air Traffic Control; Person Flight Crew
When detected: In-flight
Result: Air Traffic Control Provided Assistance; Air Traffic Control Separated Traffic; Flight Crew Took Evasive Action
Contributing factors: Human Factors; Procedure
Primary problem: Human Factors

Narrative: On the way back from the practice area with a student after practicing steep turns; slow flight and stalls; I called ZZZ Tower 12 miles out asking for full stop taxi back intending to do some landing practice with my student. We were advised to report our position when we are inbound over the landfill. As we are about to report the landfill inbound when my ADS-B traffic lit up and advised me of traffic same altitude opposite direct less then half a mile. Looking up I immediately saw the Piper twin on a collision course and immediately began a hard right turning decent. At the time I was aware of a TBM aircraft behind and faster then me on an GPS approach for an avionics check; as well as another aircraft 500 ft. below me passing right to left. Tower was extremely busy at the time and I was unable to report the near miss immediately due to frequency volume and traffic. Adding to the confusion there was another aircraft in the area with the abbreviated tail number being Aircraft Y; while my tail number being Aircraft X. Tower told me to turn base which did make sense to me considering I was 5 miles out. I reported to Tower that there were two [similar N-numbers] on frequencies. He then told Aircraft Y to turn base followed by an instruction to me to turn to a heading of 070. I read back 070 but confirmation bias; and still rattled by the near miss; I turned to a heading of 170 thinking that he wanted me to turn an extended base to final; essentially cutting off the faster TBM closing on me. Tower asked me to read off my current heading and I reported flying 175 only then realizing the mistake. I was advised to make a right turn to intercept the final of Runway XX and report turning through 270 degrees. Already heading south this happened in less than 30 seconds. Now inbound on final for landing I was advised to copy a phone number on the ground for a possible pilot deviation. Finally on a half mile final I asked Tower twice if I was cleared to land Runway XX; and they advised me that I was 'still cleared to land XX' when I had not previously been given a landing clearance. Once on the ground I contacted Tower via phone and we discussed the situation; agreeing that parties were at fault a that a lot of events contributed to the situation.I believe that there were 3 main human factors causes that led to this incident.First the Tower was overloaded with inbound; transit; and outbound traffic and was unable to properly give traffic advisories to inbound and departing traffic.Second that Tower instructed me turn base when an aircraft with a similar call sign was the intended recipient even though it didn't make sense to me and at the time. Lastly that because of confirmation bias I expected to receive a base to final clearance when in reality he wanted me to intercept a left downwind entry into the pattern.




Synopsis: Pilot reported a Near Mid Air Collision and took evasive action and that action resulted in airborne conflict with other aircraft due to a loss of situational awareness.