Floating output voltages?

Hi @ All! I have an arduino uno board. In the past I programmed with processing a program to control by keyboard the outputs on the uno. By launching arduino and uploading the standardfirmata program, the uno became able to listen to my program in processing. When I run my processing program, it works seriously fine with an output of 5 V(when I press a key). Now I need to program in the arduino software because it has to run on itself, however when I program a small program with only 2 switch inputs it doesn't work properly. When I program that it has to read pin 2 and if High, pin 4 needs to be high which has to pull up a relays. However sometimes the LED instead of relays I've connected in test phase blinks randomly? When I push the switch and release it stays on for 2 seconds sometimes and fades out. How come? arduino board is new and tried mega and another uno, same problem.

Thanks in advance, Egbert van Veen

Hi, welcome to the forum.

We like to know everything 8)
How is the button connected ? What do you use for pullup resistors ? Did you use the internal pullup resistors ? Can you show us the complete sketch between [code][/code] tags ? What do you do for debouncing ?

Hi thanks for the welcome, For the switch I use the fixed 5V output on the arduino and pin 2 input and gnd. code is not nearly finished yet, however, stuck on the first part already:

const int Fullthrottle = 2; const int STOP = 3; const int relays = 4; int FTbutton = 0; int STOPbutton = 0;

void setup(){ Serial.begin(9600); pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); } void loop(){ FTbutton = digitalRead(2); if (FTbutton == HIGH){ digitalWrite(4, HIGH); } else{ digitalWrite(4, LOW); } }

So, what am I doing wrong?

I don't know how you have connected the button. Can you upload schematics or photos ?

Your sketch is not wrong, but there is no delay. And when the button bounces the output generates bursts of pulses to the relay. That will make the relay go nuts, perhaps causing a lot inductive and electrical noise.

Do you know about bouncing buttons ? Even good buttons or switches do not just go on and off like that, but they have jitter when making contact and the mechanical part inside bounces for a while. It is a lot worse than you would expect.

Using the INPUT_PULLUP enables the internal pullup resistor. But that internal resistor is weak, and with a lot of electrical noise and long wires to the button you can get wrong inputs. Is the relay connected to the Arduino ? That introduces inductive voltage peaks. You need a transistor or mosfet and flyback diode for a relay. Or is it a relay module ?

Please disconnect the relay. You can use a led + resistor to show the button state. Show in the serial monitor the state of the button.

  if (FTbutton == HIGH) {
    digitalWrite(4, HIGH);
  else {
    digitalWrite(4, LOW);
  delay (100);

Well, I've connected the LED + resistor instead of the relays. Now the LED already burns without even having a switch connected. How should I connect the switch onto pin 2? it's a push switch with 5 cm wire, all on breadboard. as easy as it is i can't figure it out somehow

Pin 2 to switch, switch to ground.

When the switch is not closed, the internal pullup should make pin 2 high. When the switch is closed, it pulls pin 2 to ground and pin 2 should be low.

Perhaps you can adapt the sketch, and test if the FTbutton is LOW. Pin 2 being 'LOW' is switch being pressed. So 'LOW' is "active".

(I have editted my previous post, and rewritten the part about bouncing, can you read that again ?)

It works thanks, Kind off strange that when you google on; switch arduino, It all states that the 5V is needed onto the switch, from there connect it to the GND and the 2nd pin. well, doesn't matter, thanks a lot!

Kind regards, Egbert

Well done.

When you use an external pull*down* resistor to ground (and do not set the internal pullup resistor), the switch can be connected to pin 2 and +5V. But most of us feel better when one side of the button is connected to ground instead of the +5V.

epper202: relays

What relay?

Almost all relays need to be driven from a transistor. Directly connecting a relay is a good way to blow-out a pin.

I've installed a reversed diode, isn't that enough? It works fine actually

I’ve installed a reversed diode, isn’t that enough? It works fine actually

The diode protects against back EMF, not too much current.

More than 40mA of current will destroy the IO pin. What current is the coil of your relay rated for?