loading

aurduino slow response why?

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

sort by: active | newest | oldest
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.
harry88 (author)  steveastrouk4 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?
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
harry88 (author)  steveastrouk4 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.
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
harry88 (author)  steveastrouk4 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?
See circuit
harry88 (author)  steveastrouk4 years ago
i think it is fixed but here is the code anyways.
Show your code.
harry88 (author)  steveastrouk4 years ago
my code is just serial read digital in the example section under digital.
Post it. I can't be bothered digging it out.
harry88 (author)  steveastrouk4 years ago
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor

This example code is in the public domain.
*/

// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println(buttonState);
delay(100); // delay in between reads for stability
}

harry88 (author)  steveastrouk4 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
Put a resistor from the digital pin to +5, connect the jumper to ground and try again.
harry88 (author)  steveastrouk4 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
The jumper was to be the "switch" Plug and unplug the jumper. Leave the resistor in place.
harry88 (author)  steveastrouk4 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?
This circuit forces the pin to LOW, until the button pulls it HIGH.
pulleddown.jpg
harry88 (author)  steveastrouk4 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?
No, stick with the 1K.
harry88 (author)  steveastrouk4 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......
buttonval == digitalRead(button);

You've used the EQUAL operator "==", not the ASSIGNMENT operator "="
harry88 (author)  steveastrouk4 years ago
im sorry to keep bugging you...so keep the == the same on the if statement correct?
Yes. THAT'S a comparison, so you use the ==
harry88 (author)  steveastrouk4 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 ):
harry88 (author)  harry884 years ago
nvm i found some.
harry88 (author)  steveastrouk4 years ago
o thx lol see im dumb
harry88 (author)  steveastrouk4 years ago
ignore the e.... i don't know what that is but it isn't part of the code
harry88 (author)  steveastrouk4 years ago
k thx