The Internet of Things (IoT) has become a popular computing technology paradigm. It is increasingly being utilized to facilitate human life processes through a variety of applications, including smart healthcare, smart grids, smart finance, and smart cities. Scalability, interoperability, security, and privacy, as well as trustworthiness, are all issues that IoT applications face. Blockchain solutions have recently been created to help overcome these difficulties. The purpose of this paper is to provide a survey and tutorial on the use of blockchain in IoT systems. The importance of blockchain technology in terms of features and benefits for constituents of IoT applications is discussed. We propose a blockchain taxonomy for IoT applications based on the most significant factors. In addition, we examine the most widely used blockchain platforms for IoT applications. Furthermore, we discuss how blockchain technology can be used to broaden the spectrum of IoT applications. Besides, we discuss the recent advances and solutions offered for IoT environments. Finally, we discuss the challenges and future research directions of the use of blockchain for the IoT.