Hi,
I build a small arduino project but I am having issues with interrupts and gpio values on a nodemcu v3 board.
In simple terms I have the following setup:
A nodemcu v3 board where two pins, pin D5 and D2 configured as input_pullup. On the D5 I have connected a normally close contact of a 240v relay and on the D2 pin I have connected a normally close contact of a 12v relay.
The 240v relay is closing its contact when an external motor is working and the 12v relay is closing its contact when a photocell is detecting movement.
On the arduino software I am defining the following code
const uint8_t MOTOR_STATUS = D5;
const uint8_t STOP_STATUS = D2;
in setup function
pinMode(MOTOR_STATUS, INPUT_PULLUP);
pinMode(STOP_STATUS, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(MOTOR_STATUS), motorMovement, CHANGE);
attachInterrupt(digitalPinToInterrupt(STOP_STATUS), forcedStop, CHANGE);
My problem is that when the motor is working (and only the 240v relays is closing its contacts) I see in arduino code that both motorMovement and forceStop function are being fired multiple times. When the motor is stop working then neither of the functions is being fired unless I use the photocell and operate the 12v relay. In this scenario only the forcedStop is being fired.
In the scenario when the motor is working I tried to check in the code whether the actual value of either pin is being changed multiple times and it appeared that it did. I then tried to measure the actual pin voltage on the nodemcu v3 board during the time that the motor was working but neither pin show any changes. For example when motor is working the voltage of the motor pin (D5) goes to 0 and the voltage of the stop pin (D2) is 3.3v as it should. When the motor is stop working the voltage of the motor pin (D5) goes to 3.3v.
I tried "replacing" the internal pullup resistors with a 4.7k external resistors by defining the pins just as INPUT instead of INPUT_PULLUP and adding the external resistors but the result was the same.
I also tried changing the arduino board with another one just to make sure is not hardware related but the result again the same.
Does anyone have any idea why this is happening? I have no other clue as to what might be the issue here. Could it be an issue with the arduino board that is being affected but the motor that is working? Please if someone can clarify.
Regards,
Phanos