Driver L298N not working

It seems you have the 5volt supply output from the motor driver connected to V-in of the Mega.

V-in is the input of the onboard 5volt regulator of the Mega.
The V-in pin needs at least 6.5volt for the regulator to make a stable 5volt for the MCU.

If you have a reliable 5volt from the motor driver, connect it to the 5volt pin of the Mega, not to V-in.

But then again, Fritzing pictures are rarely an accurate representation of the actual build.
Leo..