logo elektroda
logo elektroda
X
logo elektroda

Want to operate a relay from a change in input; hi to lo or lo to hi

351 21
Best answers

How can I make a relay activate on the first change of an input, whether it goes high-to-low or low-to-high, and then ignore later changes?

Use an edge-detection circuit rather than a level-triggered relay: one reply proposes a CD4013B flip-flop with R tied to ground and S tied to the switch, plus a CD4093B for the needed logic/conditioning [#21665252] Another reply says an embedded microcontroller is an easier way to do it: read the pin’s initial state at startup and use an interrupt-on-change feature so the relay fires when the input changes state [#21665253] The thread also notes that if you want to keep the relay off until reset, you’ll need a separate reset action such as a pushbutton or another input [#21665246][#21665247]
Generated by the language model.
ADVERTISEMENT
  • #1 21665245
    Bill Blesbok
    Anonymous  
  • ADVERTISEMENT
  • #2 21665246
    Stephen Van Buskirk
    Anonymous  
  • #3 21665247
    Steve Lawson
    Anonymous  
  • #4 21665248
    Bill Blesbok
    Anonymous  
  • #5 21665249
    Bill Blesbok
    Anonymous  
  • #6 21665250
    Stephen Van Buskirk
    Anonymous  
  • ADVERTISEMENT
  • #7 21665251
    Steve Lawson
    Anonymous  
  • #8 21665252
    Steve Lawson
    Anonymous  
  • #9 21665253
    Mark Harrington
    Anonymous  
  • #10 21665254
    Bill Blesbok
    Anonymous  
  • #11 21665255
    Steve Lawson
    Anonymous  
  • ADVERTISEMENT
  • #12 21665256
    Bill Blesbok
    Anonymous  
  • #13 21665257
    Steve Lawson
    Anonymous  
  • #14 21665258
    Mark Harrington
    Anonymous  
  • #15 21665259
    Mark Harrington
    Anonymous  
  • #16 21665260
    Mark Harrington
    Anonymous  
  • ADVERTISEMENT
  • #17 21665261
    Bill Blesbok
    Anonymous  
  • #18 21665262
    Mark Harrington
    Anonymous  
  • #20 21665264
    Bill Blesbok
    Anonymous  
  • #21 21665265
    Mark Harrington
    Anonymous  
  • #22 21665266
    Bill Blesbok
    Anonymous  

Topic summary

✨ The discussion centers on designing a simple circuit to operate a relay triggered by a change in input state from a limit switch activated by a rotary cam. The relay should respond only to the first input transition (high-to-low or low-to-high) and ignore subsequent changes until reset. Key considerations include how to reset or turn off the relay, with suggestions for a manual pushbutton reset. Various solutions were proposed: using a single relay with additional logic, employing logic gates such as CD4013B flip-flops and CD4093B NAND gates, or opting for embedded microcontrollers like PIC microcontrollers or Arduino for edge detection and relay control. The PIC microcontroller approach is favored for its flexibility, lower cost, and ease of programming, despite requiring some learning and hardware setup. Flowcharts and example code were shared to illustrate interrupt-driven edge detection and relay control using PIC12F675 or PIC16F628. The use of PLCs was mentioned but considered overkill and more expensive. Component cost and availability were discussed, with clarification that CD4093B ICs are inexpensive when sourced from reputable suppliers. The conversation also touched on programming tools such as MPLAB X IDE and PIC programmers like PICKIT2 or PICKIT3, with some users exploring programming PICs via Arduino on Linux systems. Overall, the thread guides toward a microcontroller-based edge-triggered relay control circuit with manual reset, supported by example flowcharts and code.
Generated by the language model.

FAQ

TL;DR: To trip a relay on any input change (hi→lo or lo→hi), use edge detection with either a tiny PLC (< $100) or a PIC with “interrupt-on-change.” “PLCs were invented because complex relay logic makes your brain hurt.” [Elektroda, Stephen Van Buskirk, post #21665246]

Why it matters: This FAQ shows hobbyists and technicians how to build a one-shot, edge‑triggered alarm trigger without wasting time or budget.

Quick Facts

What does “edge-triggered relay” actually mean here?

Edge-triggered means your circuit reacts to a change in the switch signal. A rising edge closes or opens the relay once; a falling edge does the same, per your chosen case. Define whether rising, falling, or both edges should generate the single output pulse before you build. This avoids ambiguous behavior when the cam or limit switch dwells. [Elektroda, Steve Lawson, post #21665247]

Can I do this with just one relay and no logic?

Pure relay-only edge detection becomes complex fast. You’d need impulse relays, cross-coupling, and extra contacts to detect both transitions reliably. A tiny PLC or microcontroller simplifies design, wiring, and later changes. “PLCs were invented because complex relay logic makes your brain hurt.” [Elektroda, Stephen Van Buskirk, post #21665246]

What’s the simplest solid‑state solution with logic ICs?

Use a CD4093B Schmitt NAND for conditioned pulses and a CD4013B D‑flip‑flop for one‑shot or latch behavior. In the shared sketch: CD4013B has Reset tied low and Set tied to the switch; CD4093B handles the input shaping. Drive the relay through a transistor from the logic output. [Elektroda, Steve Lawson, post #21665252]

How much do those logic chips cost?

They’re inexpensive. A CD4093B is roughly $0.39–$0.48 in single‑unit quantities from mainstream distributors. That keeps a discrete logic build well under a few dollars in silicon, excluding the relay and power supply. [Elektroda, Steve Lawson, post #21665255]

Is a small PLC really worth it for this job?

Yes, if you want fast, robust results. A basic PLC handles power regulation, mounting, and programming in one package, often under $100. Ladder logic makes it easy to add timing, latching, and manual reset later without rewiring. [Elektroda, Stephen Van Buskirk, post #21665246]

Can a PIC microcontroller detect both hi→lo and lo→hi transitions?

Yes. PIC12Fxx and PIC16F88 series support “interrupt on change.” Initialize the input state at startup, enable IOC, and in the ISR compare old vs new to fire a single relay pulse. This approach is compact and reliable for cams and limit switches. [Elektroda, Mark Harrington, post #21665253]

Do you have a quick 3‑step how‑to for the PIC approach?

  1. Configure the input pin and store its initial state; enable interrupt‑on‑change.
  2. In the ISR, if state toggled, call a one‑shot routine to energize the relay, then update the stored state.
  3. Map a pushbutton to a separate interrupt or poll to reset/unlatch the relay. [Elektroda, Mark Harrington, post #21665260]

How do I add a manual reset for the alarm relay?

Provide a momentary pushbutton tied to a reset input. In PLC code, unlatch the coil. In the PIC design, handle reset in a separate ISR or routine that de‑energizes the output and clears the latch state. This mirrors standard alarm zone reset behavior. [Elektroda, Mark Harrington, post #21665258]

Are CMOS logic gates too ESD‑sensitive for a one‑off build?

They’re fine if handled correctly. Store them in anti‑ESD packaging, then solder into a proper circuit. Once installed with proper biasing and protection, they aren’t unusually vulnerable. “Once the part is in circuit, it’s no longer vulnerable to ESD.” [Elektroda, Steve Lawson, post #21665257]

Can I program a PIC if I don’t have a PICkit?

Yes. Use an Arduino Uno with a small shield and Linux to program certain PICs. Community guides show the wiring and tools. This is handy if parts are scarce locally and you already own an Arduino. [Elektroda, Bill Blesbok, post #21665266]

Any gotchas when flashing PICs for this project?

Before erasing, read and note the calibration value at address 0x3FF. It tunes the internal RC oscillator. Losing it can cause timing errors in your one‑shot or debounce routines. “Don’t be tempted to wipe the chip unless you have done the above.” [Elektroda, Mark Harrington, post #21665265]

Is there a ready-to-use microcontroller project I can copy?

Yes. A complete single‑PIC single‑shot bi‑stable relay project was shared, including HEX, PCB, and flowcharts. You can adapt the input stage to your limit switch and reuse the timing and reset logic. [Elektroda, Mark Harrington, post #21665265]

What is a PLC in this context?

A Programmable Logic Controller is an industrial control unit that reads inputs and drives outputs based on a user program. Here, it detects edges and energizes a relay for alarms. It reduces wiring and speeds iteration compared to relay‑only logic. [Elektroda, Stephen Van Buskirk, post #21665246]

What are CD4093B and CD4013B?

CD4093B is a quad Schmitt‑trigger NAND for clean edge shaping and simple timing. CD4013B is a dual D‑flip‑flop for latching or one‑shots. Combined, they create a compact, discrete edge‑triggered relay driver front end. [Elektroda, Steve Lawson, post #21665252]

What is an impulse relay?

An impulse relay toggles or pulses its output when it receives a brief control signal. Using only impulse relays to sense both edges becomes complex and costly compared with a PLC or a small MCU approach. [Elektroda, Stephen Van Buskirk, post #21665246]

How do I unzip the design files on Linux?

Install the 7‑Zip package and extract. On Debian/Ubuntu, run: sudo apt‑get install p7zip‑full. Then use your file manager or the 7z command to open .7z archives. [Elektroda, Bill Blesbok, post #21665261]
Generated by the language model.
ADVERTISEMENT