Air pollution is a big concern in developing countries due to its negative effects on both human well-being and the environment. Collecting real-time values of air quality is challenging using traditional methods. Because they have limited coverage and may not accurately reflect pollution levels in a specific location. However, Advances in Internet of Things (IoT) technology and Machine Learning (ML) algorithms, can play a vital role in collecting and analyzing large amounts of air quality data, resulting in a more complete and exact knowledge of pollution levels. Throughout this work, based on several air pollutants including sulfur dioxide (SO2), ozone (O3), nitrogen dioxide (NO2), particulate matter (PM) 2.5, particulate matter (PM) 10 and carbon monoxide (CO) across a large urban region, we establish an IoT-based framework to collect real-time data. After collecting the real-time values, we applied two types of machine learning algorithms named regression and classification models including linear regression, decision trees (DT), random forest (RF), K-Nearest Neighbours (KNN), Naive Bayes (NB), and gradient boosting (GB), to analyze the gathered data and estimate pollution levels into good, satisfactory, moderate, poor and very poor. Among the machine learning models, RF outperforms the result. This work and the dataset will be helpful for researchers, environmental practitioners and agencies.