It turned out it was a problem with the breadboard. Once I soldered the components on the PCB that I designed, the problem disappeared. It must have been a short or flimsy contact on the breadboard. Sorry for bothering you again. Thank you to everybody for bearing with me.