In this paper, the problem of distributed uplink random access is studied for an Internet of Things (IoT) system, composed of heterogeneous group of nodes compromising both machine-type devices (MTDs) and human-type devices (HTDs). The problem is formulated as a noncooperative game between the heterogeneous IoT devices whose goal is to find the transmission probabilities and service rates that meet their individual quality-of-service (QoS) requirements. To solve this game while capturing the heterogeneity of the devices, in terms of resource constraints and QoS needs, a novel approach based on the behavioral game framework of cognitive hierarchy (CH) theory is proposed. This approach enables the IoT devices to reach a CH equilibrium concept that adequately factors in the various levels of rationality corresponding to the heterogeneous capabilities of MTDs and HTDs. Simulation results show that the proposed CH solution can significantly improve the performance, in terms of energy efficiency, for both MTDs and HTDs, achieving, on the average, a 67% improvement compared to the traditional Nash equilibrium-based game-theoretic solutions.