how to reduce the electrical noise

I think a pull–up resistor between a pin and VCC would help.