This research presents a novel dynamic traffic light algorithm designed to optimize traffic flow and reduce traffic congestion by dynamically allocating green time based on post-intersection space availability. The algorithm employs a three-stage process: input generation, processing, and output. The input stage involves capturing traffic images using cameras strategically placed at intersections, which are then processed using background subtraction, edge detection, and object counting techniques. The processing phase includes vehicle counting using the YOLOv8 algorithm and open space calculation based on the maximum capacity of each road section. The output phase involves dynamically allocating green time to roads based on available post-intersection space and occupancy rates. The algorithm is designed to adapt to changing traffic conditions by continuously monitoring the post- intersection space and adjusting green times accordingly. It also incorporates a reset timer to ensure the algorithm loops back to the initial stage of gathering and processing traffic images. Simulation experiments using a physical model with toy vehicles and a camera setup demonstrated the benefits of this approach. Compared to the density-based approaches[1], this algorithm reduced average vehicle delay by 20-30%, increased overall intersection throughput by 15-25%, and decreased maximum queue lengths in each lane by 25-35%. It also adapted more effectively to fluctuations in traffic conditions, improving performance metrics by 20-30%. These results highlight the potential of incorporating downstream space considerations into traffic light control algorithms to enhance intersection efficiency, reduce traffic congestion, and enable more adaptive and fair traffic management.