Issues with activating arduino with a button

Hi, I have been having issue with an Arduino run circuit that is designed to be operated by activating a button which results in a piezoelectric actuator deflecting. Below are two images showing the schematics of the device. The issue we have been experiencing is that when plugging the device into one outlet the button functions as expected, but when plugged into another the device behaves as if the button is constantly depressed which results in a pulse being sent to the circuit every 30 seconds. We were concerned that we have fried the Arduino board because we did have one issue where we exceeded the voltage capacity of an older piezoelectric resulting in the piezo itself being fried. We have replaced the button thinking it was the issue as well but this has still not resolved the problem.

Of note we were only able to get the button to work after changing from pin 7 to pin 8.

Our original code is as follows but was modified to change the pulse interval to 30 seconds:

// These constants won't change:
const int RelayPulsePin = 13;      // pin used to power Relay for pulse waveform (built in LED on board shows when this is toggled)
const int buttonPin = 7;        // pin that the momentary switch is attached to

void setup() {
  // set up the LED pins, one is for power to system while the other is for the pulse:
  pinMode(RelayPulsePin, OUTPUT);
  pinMode(buttonPin, INPUT);
  digitalWrite(RelayPulsePin, LOW);
}


 //  while button is pressed, write the HIGH signal to RelayPulsePin (pin #13 on Arduino), keep HIGH for 250 msec, then write LOW; wait for 1 second, and then go back


void loop() {

 
 //  Monitor pin #7, which is connected to the pushbutton switch
 

 if (digitalRead(buttonPin) == HIGH) {
    digitalWrite(RelayPulsePin, HIGH);
    delay(250);
    digitalWrite(RelayPulsePin, LOW);
    delay(1000);
  }

}

Parts list:
Power supplySoulBay, model no. UC02U
Buck converter RioRand, model no. 3-01-0076
PotentiometerUxcell, model no. a15082600ux00775VDC
SPST relay Omron Electronics Inc-EMC Div, model no. G6L-1P DC5
Digital voltmeter display Bayite, model no. 3B002x5
Arduino microcontroller Arduino, model no. A000066
Pushbutton amazon, ASIN B0772KYPPM;
OcrtechProportional voltage boosterpiezo dot com, model no. EVB-304
Electrical terminal connector MUYI, model no. 5xSKUMY20973
Non-insulated block spade terminal (Vetco Electronics, model no. SR-SPA-1N)
Polycarbonate sheet (McMaster Carr, model no. 8574K321)
Piezoelectric actuator piezo dot com, low-throughput setup, model no. Q220-A4BR-2513YB
Enclosure LeMotech, model no. Lm201803261111
Panel mount—female jack (BixPower, model no. CNT-W4)
Header pins (Vetco Electronics, model no. VET-HEAD-SR-5
Breadboard (CircuitSpecialists, model no. WB-801)
Solderable breadboard SparkFun Electronics, model no. 12070M2.5
Nylon Hex Standoff FemaleMounting screws 2–56 model no. 92196A079
Mounting screws 4–40model no. 92196A108
22 Gauge wireRSR Electronics Inc model no. 27WK22STR25

@hammy
So for a pull down resistor would this just be a resistor that gets placed between pin 7 and ground? And just to make sure, this wouldn't change any voltage outputs to other areas of the circuit but only control the button so that it fires when pressed?

Yep , 10k would do it Read me

Or as said look at “INPUT PULLUP “

Something must make the pin go HIGH and something must make the pin go LOW.
You can't leave a pin 'floating', because it will likely change randomly all by itself.

A switch could pull the pin to 5volt (or ground), and a resistor could pull it the other way.

You could use a physical resistor, but the Uno has built-in resistors pull up to 5volt.

All you have to do is enable that pull up with pinMode().

pinMode(buttonPin, INPUT_PULLUP); // enable internal pull up

and wire the button between pin and ground.

Note that now the pin is now normally HIGH, and LOW when the button is pushed.
The if() statement must also be changed to reflect that.

if (digitalRead(buttonPin) == LOW) { // button pushed

Leo..

1 Like

Without drawing a proper schematic you wont understand the circuit. What are the labelled parts eg D and H?

SPST relay Omron Electronics Inc-EMC Div, model no. G6L-1P DC5

D seems to be a 5volt/36mA relay, which is directly connected to an I/O pin (yikes).
Leo..

1 Like

Hi John sorry I didn't attach that schematic as well it would only let me choose one or the other when posting and the actual diagram isn't as helpful without context of individual points of connectivity

Most of what I have for actual diagrams are from a nature method's paper so I don't have all of the original schematics made by the designing engineer but the method's that were published in the journal.

I have the circuit diagram attached below:

Thank you for your help, I am going to try the code or resistor fix mentioned by @Wawa this is the first device of this type and if anyone has any other pieces of advice for making this device more reliable for the modulating a piezoelectric, please let me know!

The circuit diagram does not show the arduino controlling anything;
the first image shows 3 wires to the arduino gnd, and Vin, and another connecting "D" to pin 13 (PB6)
then another two to "G" from +5 and a digital pin.

your schematic shows 5 wires - pwr-, pwr+, 5V digital7 & digital13
the symbol for the switch is incorrect.
the connections to the relay should be shown as such

As Leo indicated the way you have connected the realy is guaranteed to fry boards. Partly because the current is close to the absolute max rated for the pin, but mostly because you have no protection when the relay is turned on or off.

Theere are better ways to turn the voltage supply to "H" on and off using a MOSFET

Typical piezo disks can spike 100's of volts taking a hard smack. However a diode, BJT or LED can all tame that.

You want to flex a piezo with an AVR, use FETs to put 12+V across the leads and hold it. It won't conduct.

A smart thing would be to get ATmega328P-PU chips and bootload them for spares while the AVR you have still works. How To is supported by Arduino and the forum. It's cheaper than replacing the board.

Hi Leo,

I just wanted to confirm if this code is appropriate for the pin pull-up function.

// These constants won't change:const int RelayPulsePin = 13; // pin used to power Relay for pulse waveform (built in LED on board shows when this is toggled)const int buttonPin = 7; // pin that the momentary switch is attached to

void setup() {
// set up the LED pins, one is for power to system while the other is for the pulse:
pinMode(RelayPulsePin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP); // enable internal pull up
digitalWrite(RelayPulsePin, LOW);
}


// while button is pressed, write the HIGH signal to RelayPulsePin (pin #13 on Arduino), keep HIGH for 250 msec, then write LOW; wait for 1 second, and then go back


void loop() {

// Monitor pin #7, which is connected to the pushbutton switch

if (digitalRead(buttonPin) == LOW) {
digitalWrite(RelayPulsePin, HIGH);
delay(250);
digitalWrite(RelayPulsePin, LOW);
delay(1000);
}

}

Looks ok.
The digitalWrite in setup isn't really needed, because a pin defaults to LOW
Leo..

1 Like

Hi Leo,

I just wanted to ask about the issue you noted for the relay, is it something where using a MOSFET in the same configuration would fix, or would I have to rearrange the circuit completely. Currently the button fix is working great but regarding a stabilized current flow would a MOSFET unit work better than a relay?

-SR

Never drive a relay directly with an Arduino pin. Always use a transistor in between.
That relay is small enough to use a small-signal NPN transistor.
A 2N3904, BC547, 2N2222 and many more can be used.
Emitter to ground, collector to relay coil, other side of coil to 5volt, base via resistor to pin.
For a 36mA relay I would use a 1k base resistor (470 ohm for larger relays).
The relay coil needs a diode across, cathode/ring to 5volt. 1N4148 or 1N4004 will do.

We commonly use relay modules, where all those parts are already included.
Leo..

Will this design work? My one question is how I would go about hooking this into the ground and the broader circuit itself since the container has limited space and both ground pins on the Arduino are occupied.

Thank you for all your help!
-SR

The BC527 is a PNP transistor. You need an NPN transistor.

The diode in you diagram connects to 5volt
Relay coil connects to collector and 5volt.
Leo..
The-Relay-Driver-Circuit

Sorry the BC527 was a typo on my behalf.
To clarify how this diagram works:

  1. The input from Pin13 runs through the resistor R1(1kOhm) feeding into the BC547 transistor.

  2. The emitter pin then has to be connected into the ground (I'm not entirely sure how that would work so far)

  3. Then the Q1 portion of the diagram has the 1N4148 diode placed on the breadboard in parallel to the relay? Would this be between lanes 10 and 13 in column g or would I need to change the wiring a bit?

Try to avoid pin13 if you have enough other pins left.
Pin13 could toggle during bootup, making your relay chatter.

If you're not sure if you have build it right, then post a picture of it.
Leo..

I know this is a bit of a mess in terms of wiring, its hard to get a better photo because opening the device tends to pull on the pins.

Currently the code we uploaded has output going through pin 13, which pin should we be using as an output? Currently all the pins are wired the same as the initial diagram except the button is now routed through the ground which fixed the problem we previously had.

The diode as I understand it is supposed be going between pins g10 and g14 and the wire coming from the Arduino I am more confused about and how the transistor and resistor need to be placed on the breadboard.

Thank you so much for your help.
-SR

Any pin except 0, 1, 13.
13 will work ok after booting, but could flash for a few seconds during powerup.
That usually is not a problem, but moving to say pin 12 could avoid that.

I can't see on that picture if you have used the transistor correctly.
Leo..

Sorry I no longer have access to the device physically for today but given this image and the old wiring diagram (the one that isn't an actual all wiring diagram but is more a cartoon), this is how I intend to wire it.

I don't have the transistor or the diode yet; the down arrow next to the relay is the diode and the box is the transistor with the emitter at the top.

As per the other diagram, the ground wire goes to the negative line where other parts are also grounded - is this acceptable? My background is biology so my extensive knowledge of circuits pretty much stops at capacitors.

Thank you,
-SR