The conventional electrical grid faces significant issues, which this paper aims to address one of most of them using a proposed prototype of a smart microgrid energy management system. In addition to relying too heavily on fossil fuels, electricity theft is another great issue. The proposed energy management system can simultaneously detect electr. Smart microgrids (SMGs) are small, localized power grids that can work alone or alongside the main grid. A blend of renewable energy sources, energy storage, and smart control systems optimizes resource utilization and responds to demand and supply changes in real-time1. SMGs can improve the resilience and stability of the power supply, reduce fossil fuel use, and lower energy costs. Figure 1 depicts a typical SMG schematic diagram. Power usage and production of the microgrid are monitored and communicated using smart meters which can detect abnormalities in usage patterns, such as spikes or drops, which are signs of energy theft. To prevent hacking and other threats, SMGs need strong cybersecurity like any other digital technology2. Smart microgrids use modern control systems and algorithms to optimize the use of existing resources and respond to demand and supply changes in real-time3. SMGs have the following characteristics,•Demand response management: SMGs can use advanced algorithms to adjust the power consumption of connected devices in response to changes in demand, helping to balance the supply and demand of power.•Energy storage management: SMGs can use energy storage systems to store excess energy generated by renewable sources, and release it as needed to. Internet of Things (IoT)IoT provides real-time data and insights into the performance and operation of SMGs. This enables more efficient control of the microgrid and improves its performance and dependability. IoT monitors microgrids in several ways28:IoT devices can measure and track the amount of energy the SMG generates and consumes.IoT monitoring can detect and diagnose microgrid issues.IoT monitoring can improve grid stability and dependability by integrating renewable energy sources like solar and wind into SMGs, enhancing resilience.IoT devices enable remote monitoring and control of the SMG, especially in inaccessible regions.IoT security solutions must consider real-time details, according to the authors of29. They looked at how IoT protocols might affect the time-sensitive needs of smart grid operations. The authors of30 built an IoT-based remote energy monitoring device for smart grid and household energy management, optimization, and conservation. The device efficiently tracks residential energy usage, reduces energy waste, and reveals energy behaviors. To standardize and unify structure parts, the authors of31 proposed an IoT-based EMS framework. Intelligent energy management and smart building modes allow for formulating relevant guidelines. A discussion of real-time microgrid monitoring was presented by32. The authors use web servers' software, and data was co. The proposed algorithm's primary goal is the minimization of the overall cost (({C}_{total})), with the secondary goal being the electricity bill reduction. The second is to enhance user convenience in order to cut down on delay time or shift peak loads to off-peak times when power reserves are more plentiful. The cost reduction problem is defined as follows, where the deferrable loads are the flexible and movable needs:$$Min.Rightarrow {C}_{total}=sum_{i=1}^{{N}_{app}}sum_{t=0}^{T}({X}_{i}(t) times {PR}_{i}(t) times {EC}_{i}(t))$$(1)Subjected to the following constraints.$$left.begin{array}{l}begin{array}{l}{X}_{i}left(tright)= 0, if tin {T}_{1} {X}_{i}left(tright)= 1, if tin {T}_{2} 1 le tle T end{array} 1 le ile {N}_{app} end{array}right}$$(2)where,. BER optimization is a metaheuristic algorithm that is based on the premise of recreating the process of measuring the radius of the Earth utilizing the method devised by the Persian scholar Abu Rayhan Al-Biruni in the eleventh century. This approach was used to measure the radius of the Earth37. Recently, this optimization algorithm has been developed by38. Al-Biruni performed the calculation that determined the radius of the Earth in the eleventh century. He did this by standing on a hilltop and measuring the distance between the horizon and the ground. Al-Biruni took two separate readings. The first thing he did was measure the height of the peak. He took the angle to the mountain's crest twice, each time measuring it from a different vantage point. Using the following equation, which is depicted in Fig. 4, he was able to determine how high up the slope of the hill.The Al-Biruni method for determining hill height.Full size image$$h= frac{dmathrm{tan}{theta }_{1}mathrm{tan}{theta }_{2}}{mathrm{tan}{theta }_{2}- mathrm{tan}{theta }_{1}}$$(7).