478Views29Replies

Author Options:

aurduino slow response why? Answered

i finally figured out my new seeed relay shield for my aurduino uno i went to make a simple program to turn a relay on and off corresponding with a button. when i pressed the button the relay would activate. when i released the button the relay would stay on for about 10 more seconds and start randomly turning on and off. i decided to take the shield off and run the serialRead digital example to see if it was just the shield that has issues... apparently not the serial read box would be something like this

(button not pressed) 0000000000000000000000000100000000100000000000000101100000000000

(button pressed)1111111111111111111111111111111111111111111111111111111111111111111

(button released)111111111111111111111111111011111111011111111111111111111111111111

(10-20 more seconds after button is released)0001111110000010111000011110111010100111111000000101010000000010100000

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.
0
steveastrouk
steveastrouk

Best Answer 8 years ago

Show your circuit. It looks to me like you have noise present. Do you have pullups on the button pin ?

Another likely cause is a bad or missing ground between the two boards.

0
harry88
harry88

Answer 8 years ago

after a little more testing it is still doing it but not as much this time it does it like 1/10 times any other magical tricks?

0
steveastrouk
steveastrouk

Answer 8 years ago

What value of resistor did you use ? Put a 0.1uF cap between the pin and ground. What you're seeing is probably "contact bounce" - there are pin debouncing routines for Arduino. Try them.

Steve

0
harry88
harry88

Answer 8 years ago

i used a 1k resistor. and im sorry i put that wrong let me say it like this after pressing the button once i get a string of ones after releasing i get a string of zeros after pressing it again i get a string of ones after releasing it again i still get a string of ones.

0
steveastrouk
steveastrouk

Answer 8 years ago

You SHOULD get a string of ones. The resistor FORCES it to be ones. Connect the resistor from GROUND to the pin, and use the switch to pull it UP to 5V

0
harry88
harry88

Answer 8 years ago

than you a bunch i am sorry for me being a noob and a newb at this truth is im only 13.so what your saying is it wont return to 0 unless there is a ground present?

0
harry88
harry88

Answer 8 years ago

i think it is fixed but here is the code anyways.

0
harry88
harry88

Answer 8 years ago

my code is just serial read digital in the example section under digital.

0
harry88
harry88

Answer 8 years ago

i currently don't even have the shield on the board it is just a plain aurduino hooked up to my laptop with a jumper going across 5 volts to digital pin 2

0
steveastrouk
steveastrouk

Answer 8 years ago

Put a resistor from the digital pin to +5, connect the jumper to ground and try again.

0
harry88
harry88

Answer 8 years ago

thanks a bunch that worked i don't understand were you wanted the other end of the jumper though so i removed it but putting a resistor between +5 and the digital pin worked. now when i remove the resistor it goes to 0 instantly

0
steveastrouk
steveastrouk

Answer 8 years ago

The jumper was to be the "switch" Plug and unplug the jumper. Leave the resistor in place.

0
harry88
harry88

Answer 8 years ago

and i want to also add tx is pulsing like every 5 seconds i don't remember if this is normal for the digital read program if so could you tell me?

0
steveastrouk
steveastrouk

8 years ago

This circuit forces the pin to LOW, until the button pulls it HIGH.

pulleddown.jpg
0
harry88
harry88

Answer 8 years ago

thank you you were a big help! i apologize for my stupidity. would you recommend using a higher resistance resistor like in the schematic?

0
steveastrouk
steveastrouk

Answer 8 years ago

No, stick with the 1K.

0
harry88
harry88

Answer 8 years ago

i have 1 more question and plus i discovered pull-up sorry i didn't do that earlier but could you help me with this code buttonval wont go high when i have the jumper across pin 2 and +5 here is the code

const int r1 = 4;
const int r2 = 5;
const int r3 = 6;
const int r4 = 7;
const int button = 2;
int buttonval = 0;
const int ledheat = 12;
const int ledcool = 13;


void setup() {
Serial.begin(9600);
pinMode(r1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(r3, OUTPUT);
pinMode(r4, OUTPUT);
pinMode(ledheat, OUTPUT);
pinMode(ledcool, OUTPUT);
pinMode(button, INPUT_PULLUP);
}
void loop() {
buttonval == digitalRead(button);
if (buttonval == HIGH) {
digitalRead(button);
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r3, LOW);
digitalWrite(r4, LOW);
digitalWrite(ledcool, HIGH);
digitalWrite(ledheat, LOW);
}
else {
digitalRead(button);
digitalWrite(r3, HIGH);
digitalWrite(r4, HIGH);
digitalWrite(r2, LOW);
digitalWrite(r1, LOW);
digitalWrite(ledheat, HIGH);
digitalWrite(ledcool, LOW);
}
Serial.println(buttonval);
}e......

0
steveastrouk
steveastrouk

Answer 8 years ago

buttonval == digitalRead(button);

You've used the EQUAL operator "==", not the ASSIGNMENT operator "="

0
harry88
harry88

Answer 8 years ago

im sorry to keep bugging you...so keep the == the same on the if statement correct?

0
steveastrouk
steveastrouk

Answer 8 years ago

Yes. THAT'S a comparison, so you use the ==

0
harry88
harry88

Answer 8 years ago

this will b my final question...to you at least is there any easy way to hook up jumpers to a shield that does not have the ummmm....bread boardy things without soldering? because i am out of butane for my soldering iron ):

0
harry88
harry88

Answer 8 years ago

nvm i found some.

0
harry88
harry88

Answer 8 years ago

o thx lol see im dumb

0
harry88
harry88

Answer 8 years ago

ignore the e.... i don't know what that is but it isn't part of the code

0
harry88
harry88

Answer 8 years ago

k thx