Internet of Things (IoT) is utilized as an emerging sample for defining the future of technology in which physical items like sensors, radio-frequency identification tags, mobile phones, actuators, and so on, can have interaction together and have cooperation with their neighbors for obtaining joint objectives. The performance of the deployed tasks and applications on the network is considered as one of the critical goals in this model, which is achieved by the task allocation mechanism. Task allocation in the IoT is so complicated due to the intricate connection among machines. The task allocation problem is considered as an NP-hard problem, so a new task allocation algorithm in the IoT environment is proposed using the combination of Simulated Annealing (SA) and Particle Swarm Optimization (PSO) algorithm. Also, the issues of the PSO algorithm, such as getting stuck in local optimization and not achieving an optimal response, forced us to present a method based on the combination of SA and the PSO algorithms. The results of simulation in MATLAB environment illustrated that the suggested method performs better compared to the PSO and SA-based methods.