Code review? Anyone interested in reviewing my code?

I tested on the my desk for a week, everything seemed okay.
Now that I have installed it I am having a recurring problem. Not sure if it related to my sensors and relays or my code.

Any volunteers?

You have a better chance at getting feedback if you post the code and state what the problem is. Just a friendly tip!

Sure! I just wanted to know if anyone was willing to help.

Are you offering Luke?

I’ll look but I’m a relative beginner. There are some great people on the community with much more experience that will probably chime in though.

I posted my project on Hackster.io

It is a garage door opener project.

The problem I am having is sometimes my garage door is stuck open and the button on the wall is “off” (not lit up) and does not work or does sent the photon the open command. The remote works to close it. When I do send the photon the “push” command I can see the light on the relay energize, but the opener does not trigger. I assuming that it has something to do with the relay. The odd thing is my door status (based on the reed switch) is also reports the wrong status. I reset the photon manually and everything starts working again.

One thing I’d suggest on first look is to change pinMode(reed, INPUT); to pinMode(reed, INPUT_PULLDOWN); since your reed will let the pin float when open.

A next thing is here

int openDoor(String command){
    if (statusCheck() == "CLOSED"){ 
    relayPulse(command);
    return 1;
    }
};

You need to return a value in this function, but you only do in case the door is closed.

Since you have an unconditional delay(interval) you would not necessarily need the one inside your if-block.

I’d also guess that this branch never will be executed, since digitalRead() will only ever have two possible states.

        return "OFFLINE";
    }

And I would get rid of all the Strings for your status reports - rather go for an enum for states.

Instead of unconditionally setting the relays after bootup, I’d check the current state of the door and set the relays accordingly - unless you really want the door to move after a reboot (for whatever reason it might have happened).

Thank you!

I made the quick fix reed pinMode. Love being able to update without going up the ladder to disconnect it.

I get the offline status with the curl script, so you are correct I don’t need it on the photon.

I set the relays so that it doesn’t open on bootup. I used the makemagazine article as a guide to wiring the double relay to prevent it from opening when both are high or low.

1 Like