I have been working on a NodeMCU project. The objective of the project is to turn a DC motor clockwise and anticlockwise from Alexa commands. The coding and connection part is done as shown in the image above. I have achieved the expected result. But there is one issue in supply distribution.
When I give command to Alexa to rotate clockwise then,
The signal goes from D1 in NodeMCU to Relay1 will be activated and the motor rotates clockwise. (since the motor connected to Relays as shown in the pic).
When I give command to Alexa to rotate anti-clockwise then,
The signal goes from D2 in NodeMCU to Relay2will be activated and the motor rotates anti-clockwise.
This is the working principle and this process is working fine.
The problem is
I am giving 9v supply. It will be regulated to 5v and that will goes to Node MCU and Relay module. Motor consumes direct 9v.
When the motor is rotating, the complete supply is going towards motor itself. There is no supply going to NodeMCU.
In short, the NodeMCU is turning OFF when the motor is running.
I am a newbie to electronics. Please show some light and help me in fixing this