<p>The growing demand for sustainable and efficient energy solutions has led to research on optimizing renewable energy sources within microgrid systems. This study presents a comparative analysis of two prominent optimization techniques, particle swarm optimization (PSO) and genetic algorithm (GA), to enhance solar photovoltaic PV and wind production in microgrids. The aim is to achieve a balanced and efficient energy generation that closely matches the load demand, thereby minimizing energy wastage and ensuring a reliable energy supply. The two algorithms are employed using data representing PV and wind production, as well as load consumption, over a 24-hour period. The results are evaluated based on their ability to reduce the gap between energy production and load demand. Our findings reveal compelling insights into the performance of GA and PSO in the context of microgrid optimization. To validate the results obtained from the simulation, the PSO algorithm is implemented on an actual cart Digital Signal Processor DSP platform, using a processor-in-the-loop (PIL). This successful real-world application highlights the practical viability of utilizing PSO to improve solar PV and wind energy generation within microgrids.</p>