Agricultural activity is the most important economy in Morocco, and in the world, because it is the only source of food security. This activity faces a real threat due to the climatic changes and the inappropriate use of irrigation, which threatens the life of many people in Morocco and North Africa. In order to meet the increasing demand for water for agriculture, we must consider alternative techniques to rationalize this rare and vital substance. This paper proposes a "Smart Irrigation System" based on the internet of things (IoT) and cloud computing to supervise in real-time and wirelessly the environmental parameters such as temperature, humidity, moisture, and water level in a smart agricultural. This system uses as techniques special sensors (DHT22, water level sensor, moisture sensor) wired to a popular control board ESP32. As communication between the device and the user, the apparatus uses a ThingSpeak platform on the network. The ESP32 controller is also connected to a water sprinkler irrigating the soil and a water pump for recharging the tank when it runs dry. Based on the values of different environmental parameters, the water pump is automatically controlled. The data collected by the sensors is communicated in real-time to the ThingSpeak platform and the ThingView app. This will allow the farmer to see all of the farm's data from afar and from any location, allowing him to irrigate the crops more accurately and increase production. On the other side, we will present a mathematical function to calibrate the water level sensor by a percentage, a function called linear interpolation. In this system, the soil is irrigated as needed and accurately, and this will reduce water consumption by a very important percentage of more than 70 percent, unlike traditional irrigation, which drains the water bed and drowns agricultural crops.