Reputation: 9585
We've set an Arduino uno that controls a relay board. The relays are excited when set to LOW, and do nothing while receiving a HIGH signal. This relays are used to open/close doors and we're facing a big issue because the doors are being opened "by their own" maybe 1 time per day or maybe 1 time in 2 or 3 days (random fashion)...
We've seen that our system doesn't send (AT) commands to open the doors and we are suspecting that the Arduino HIGH output voltages may drop for some ms and then the relay board detects this as a signal and the relay gets excited...
So, now the software question...
How can I read the real pins output and check if there are any moments where the voltages become LOW while these OUTPUT pins are set to HIGH? To do this, I've read other questions on SO and I've done the following:
const int PIN_GARAGE = 3;
void setup() {
Serial.begin(9600);
pinMode(PIN_GARAGE, OUTPUT);
digitalWrite(PIN_GARAGE, HIGH);
}
void loop() {
// Ommited code that processes commands sent to the Arduino
if (!digitalRead(PIN_GARAGE)) {
Serial.print(millis());
Serial.print(" LOW VOLTAGE ON PIN ");
Serial.println(PIN_GARAGE);
}
}
I'm not sure if doing a digitalRead()
on an OUTPUT
pin set to HIGH will always return 1
instead of the current real value, which is what I do need.
Upvotes: 0
Views: 3405
Reputation: 332
Have you checked that your Arduino is not rebooting for any other reason and this the strange behaviour you are seeing? You can print millis() through the Serial port and see for how long has the Arduino been running.
Upvotes: 0
Reputation: 495
https://stackoverflow.com/a/6487713/2041472 from the question you linked
Why do you want to do that? If you are doing this to validate that the pin is really high, this will not confirm it to you, because maybe there is a short circuit on the high pin from the external circuit, the best way is to create a feedback through another pin; configure another pin as input, and connect the output pin to the new input pin, and read its value. Reading the internal register will always return for you what the controller is trying to put on the pin, not the actual pin value.
If you have a spare pin, set it as an input pin and splice a wire from the output wire into the input wire, and then read the inputs value.
If possible I would also consider changing your circuit around so the arduino pulls high to activate your signal as it would probably be more reliable.
Upvotes: 1