Urban air quality, impacted by human-made pollution, impacts health and requires continuous monitoring. MQ sensors are the preferred air quality sensors despite their high energy consumption due to their cost, requiring the use machine learning to classify different types of air. The aim of this paper is to evaluate a monitoring solution with low-cost and low-energy consumption to classify urban and rural air. A single MQ sensor will be used with a network with edge and fog computing to balance the energy consumption. Edge computing was included in the node for feature extraction, and fog computing was applied in the smartphone to classify the data using machine learning. Different sensors and time buffers are compared in order to find the adequate sensor for data generation and time buffer for feature extraction. The results indicate that it has been possible to achieve accuracies of 100% using a single sensor, the MQ2, with time buffers of 45 to 60 measures. With this proposal, it is possible to reduce the energy consumed by data gathering to 25% of the original consumption due to the use of a single sensor, thanks to the reduction in the sensors used in the previous prototype. Moreover, it has been possible to reduce the energy linked to data forwarding by almost 97 % due to using a time buffer