I'm using LCD display and keypad to control my stepper motor. My stepper motor uses a 12Volts, 2Amperes power supply and I used L298N as its driver. My code functions well but the problem is everytime I plug in the power source for the stepper, the LCD starts malfunctioning. The display texts disappears but the light is still on. LCD gets its power source in arduino mega 5v, the l298N driver also utilizes the same 5v source from it. I think that's the problem, currents jamming in because l298N also has a pin connected the the 12Volts, 2Amperes power source..... I'm not sure if that's the problem guys pls help me fix it. THANKS
Clearly the combination of the loads that you are placing on the +5V pin is causing a sag of the voltage to a level that is lower than the LCD can still remain functional. This could be a constant sag with too much load or it could be a transient fault that happens when a load switches or you try to hot plug a load.
A constant sag situation would require that you find a separate hefty 5V supply to drive some of your load requirement.
For the transient type situation stop hot plugging. And for a transient due to the load switching you can benefit from adding bulk capacitance to the 5V line to GND at the loads that are switching.