Relay on off need help

Ok got my board set up and attempted to to make it work. At this point I am willing to pay for a written code and map. I am using a uno board from DR. Duino. I would like for it to illuminate a led colored switch when turned on, then when that momentary switch is pressed it will turn off that led, illuminate a second led in the switch and turn on a relay. I already have the 2 colored switch and relay. Just can’t figure it out.

Post your wiring diagram code using the <CODE/> tags so we can help you with this simple code, or ask some moderator to change your category topic.

2 Likes

Would you like to have the thread moved to the Jobs board?

1 Like

Yes please.
Sorry set up from my phone this morning guess I missed that board.

I think you need a third state (what happens when you are done with the relay being on?). You can see the pattern in this code and complete what you need. The button reading is crude, and will only "work" with one button... look into a millis() timing to read several buttons.

byte buttonPin = 3; // arduino pin >> button pin 1 then button pin 2 >> ground
byte curSTATE = 0;  // current state
byte totSTATE = 2; // total states

byte ledRED = 5, ledGRN = 6, relay = 7;

void setup() {
  Serial.begin(115200);
  pinMode(buttonPin, INPUT_PULLUP); // HIGH when not pressed
  pinMode(ledRED, OUTPUT);
  pinMode(ledGRN, OUTPUT);
  pinMode(relay, OUTPUT);

  Serial.print("Button state: 0");
  state_0();
}

void loop() {
  readButton();
}

void readButton() {
  if (digitalRead(buttonPin) == 0) { // read button for PRESSED
    delay(50); // "button debounce" to wait for natural button press ringing
    if (digitalRead(buttonPin) != 0) { // read button for RELEASED
      curSTATE++;
      if (curSTATE == totSTATE)
        curSTATE = 0;
      switch (curSTATE) {
        case 0: state_0(); break;
        case 1: state_1(); break;
      }
      Serial.print(curSTATE); // count button presses from 0 to totSTATE
    }
  }
}

void state_0() {
  digitalWrite(ledRED, HIGH);
  digitalWrite(ledGRN, LOW);
  digitalWrite(relay, LOW);
}
void state_1 () {
  digitalWrite(ledRED, LOW);
  digitalWrite(ledGRN, HIGH);
  digitalWrite(relay, HIGH);
}
1 Like

Done

1 Like

Only using 1 button. Here is what I have sent to a couple that have replied via email.

Here is what I am doing:

I have a RC-522 RFID reader I can send the UID to be included in the code, duino uno board, 2 relay board doth no and nc, and the momentary switch with 2 LED. Yes I also have some resistors that came with a starter kit I purchased

I would like the rfid receiver to turn on the uno board when activated. When the uno board is turned on the button will illuminate red, when the momentary button is pushed it will then illuminate green and turn on a relay that will complete a separate circuit. If the momentary switch is pressed again it will then turn off the relay and the illumination will be red. Lastly if the rfid tag / signal is lost the system will shut off altogether.

I have attempted to do this myself. I do understand the working theory, but the code was just too much for me to grasp. So I am looking for the written code to complete this task as well as a map / diagram to get everything wired together on a project board.


What's the budget?

1 Like

No budget really. If you want to send me an email we can discuss

Then this tread should not be in the "payed" category.

So you're willing to pay but you won't say how much.

Don't expect much in the way of replies here.

Got it taken care of! Thank you to all who offered.

Delta G: Its not that I wasnt willing to say, just didnt know what the service was worth. I would have spent 500 or so, but if the going rate was 1000 I would of had to regroup. Turns out all the quotes I got were 150-200. Which I went with one in the middle.