Need help changing the on and off duration of an output with a pushbutton.

Back story, and sorry for its length. I'm currently working to commission over 50 pieces of new machinery at a facility. The old machinery was previously removed when sold. All of the equipment at this facility has one prox sensor connected to a PLC(s). The PLC data is fed into an SQL server for production analysis. I have to label each piece of equipment I install and commission with the PLC number, and its discreet input number. I’m using the Prox cables that were connected to the old equipment that was sold and removed. And to no surprise, none of the Prox cables are labeled. There are 100’s of Prox sensors connected to multiple PLC’s throughout the facility, and none of the Prox cables are labeled. It’s easy enough to determine which PLC the input is connected to by following the bundles of wire throughout the facility, but nearly impossible to identify the discrete input as it travels through conduit, pull boxes and bridle rings.

To aid in identifying each discreet input, I built a simple little box which has the same connector as the Prox sensors. I just plug the box into an unused Prox cable that is closest to the machine I am installing. I took the 24VDC that is supplied by the Prox cable and Plc, and converted it to 5VDC to power an Arduino Mini. The Arduino program powers an Led on the box, along with a NPN transistor to mimic the NPN Prox sensor input to the Plc. I loaded the Blink program, which turns on an LED and transistor for one second, off for one second, repeatedly. It’s a pretty handy piece of test equipment as its self-powered and it works great, except when the Plc happens to have an active blinking input that closely matches the timing on the Arduino. I would like to add a normally open up and down button for each the “on time”, and “off time”. Each time the button is pressed it would either add or subtract 100ms from the one second base timing.

This was a fun and useful project, but needs modification. I also design and build control systems for industrial machinery, but this modification to the Arduino code is clearly over my head. I could have easily accomplished this with a separate Plc/Ladder Logic, Power Supply, with HMI,Push Buttons etc. But I really did not want to lug all that stuff around with an extension cord to identify 50 Plc inputs.

Any help would be greatly appreciated!

Thank You!

Capture.JPG

In order to get any help you need to post the code

Please follow the advice given in Read this before posting a programming question

// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 7 as an output.
pinMode(7, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(7, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

MachineGear:
// the setup function runs once when you press reset or power the board

You will do much better if you read the how to post section and use code tags for any code.

Sorry

// the setup function runs once when you press reset or power the board
void setup() {
 // initialize digital pin 7 as an output.
 pinMode(7, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
 digitalWrite(7, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(1000);                       // wait for a second
 digitalWrite(7, LOW);    // turn the LED off by making the voltage LOW
 delay(1000);                       // wait for a second
}

So, four switches. Wire them to unused digital I/O and specify internal pullup (S3 in the diagram below) in the pinMode statements. Once you've verified switch operation with the serial monitor add switch debouncing, IDE -> file/examples/digital/debounce and state change detection (one-shots in PLC parlance). Use the state change to inc/decrement a variable which is used in the delay() statement(s).

You'll need to make new, unique, variables - descriptive names advised - for the things added above.

You know there is equipment that does this and you don't need to look at lights? Phone technicians use them all the time. Clip the sender to the wires at one end and then wave the probe over the cable bundle. It makes a noise when it is near the wire being sought.

I forget the name though. I think it is named for the noise it makes. "Warbler" or "pinger" or something. A quick search for PABX tools will find it.

I understand what you are saying, but please understand all these Plc inputs are activated by an NPN (grounded) input. I can't take the chance of frying a Plc input card by injecting a signal of any kind into the inputs. But thanks for responding!

They probably have protection up to 48V since that is a common voltage in PLC type stuff. At least 24V in any case.

Thanks dougp! I don't know if I can pull this off, but I will certainly give it a try when I get to work.
Thanks Again!

dougp:
So, four switches. Wire them to unused digital I/O and specify internal pullup (S3 in the diagram below) in the pinMode statements. Once you've verified switch operation with the serial monitor add switch debouncing, IDE -> file/examples/digital/debounce and state change detection (one-shots in PLC parlance). Use the state change to inc/decrement a variable which is used in the delay() statement(s).

You'll need to make new, unique, variables - descriptive names advised - for the things added above.

This example should do the job:

/**
 * This examples shows how to use two push buttons to set the frequency at which
 * an LED blinks.
 * 
 * @boards  AVR, AVR USB, Nano 33, Due, Teensy 3.x, ESP8266, ESP32
 * 
 * Connections
 * -----------
 * 
 * - 2: Momentary push button (other pin to ground)
 * - 3: Momentary push button (other pin to ground)
 * 
 * The internal pull-up resistors will be enabled.
 * 
 * Behavior
 * --------
 * 
 * - If you press the first push button, the LED blinks faster.
 * - If you press the second push button, the LED blinks slower.
 * - You can press and hold one of the push buttons to change the frequency by
 *   multiple steps.
 * - If you press both buttons at the same time, the frequency is reset to the
 *   initial default frequency.
 * 
 * Written by PieterP, 2019-12-10  
 * https://github.com/tttapa/Arduino-Helpers
 */

#include <Arduino_Helpers.h>

#include <AH/Hardware/IncrementDecrementButtons.hpp>
#include <AH/Timing/MillisMicrosTimer.hpp>

const unsigned long maxInterval = 2000;    // ms
const unsigned long minInterval = 100;     // ms
const unsigned long defaultInterval = 500; // ms
const int intervalDelta = 100;             // ms

IncrementDecrementButtons buttons = {2, 3};
Timer<millis> timer = defaultInterval;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  buttons.begin();
  Serial.begin(115200);
}

void loop() {
  // toggle the LED when the given number of milliseconds have passed
  if (timer)
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));

  // read the buttons, and change interval accordingly
  switch (buttons.update()) {
    case IncrementDecrementButtons::Increment:
      timer.setInterval(max(timer.getInterval() - intervalDelta, minInterval));
      break;
    case IncrementDecrementButtons::Decrement:
      timer.setInterval(min(timer.getInterval() + intervalDelta, maxInterval));
      break;
    case IncrementDecrementButtons::Reset:
      timer.setInterval(defaultInterval);
      break;
  }

  // print the new interval if a button was pushed
  if (buttons.getState() != IncrementDecrementButtons::Nothing)
    Serial.println(timer.getInterval());
}

Pieter