Sorry for my English, from the Netherlands you know
I think I have a simple question but I am a real arduino-noob.
I want this:
I have a Arduino Uno, a 5v relais and a button.
The Button is located at 2 (and ground).
The relais on 5v, gnd and the output to trigger the relais is located at 10.
Can someone make a code for me????? I have searched the whole internet and tried a lot of scripts. I changed in those scripts the way I thought it must be. But I am going crazy.
It's very simple, i think.
Normally the relais must be closed, so the led is on.
When I push the button one time the led must go off foor 5 seconds and than turn on again, forever.
When I push the button again the same thing.
So...
Led on.
push button (very short)
Led off 5 seconds than on.
push button (very short)
Led off 5 seconds than on.
push button (very short)
Led off 5 seconds than on.
And so on :D.
Please can someone help me. I will be very happy!!!
int pbuttonPin = 2;// connect output to push button
int relayPin = 10;// Connected to relay (LED)
int val = 0; // push value from pin 2
int lightON = 1;//light status
int pushed = 0;//push status
void setup() {
// Robojax.com code and video tutorial for push button ON and OFF
Serial.begin(9600);
pinMode(pbuttonPin, INPUT_PULLUP);
pinMode(relayPin, OUTPUT);
}
void loop() {
// Robojax.com code and video tutorial for push button ON and OFF
val = digitalRead(pbuttonPin);// read the push button value
I made a motor in his arm and this motor will move his middlefinger up and down.
So when he shows his middlefinger it must wait 5 seconds... When finger down also 5 seconds.
Hahahahaha I am crazy, I know. But when it works I will show a movie
hi~
maybe using relay( DPDT) .
Normally the relais,1ch Relay (COM-NC) LED is on.
When I push the button relayPin set HIGH, Led off 5 seconds and than turn on again.
Yes, this is the classic newbie problem. When you use delay(), nothing else can happen until the delay has finished. Buttons being pressed or released will not be detected during that time. Instead, you must re-write your code to use millis() for timing, and no using delay() (expect for perhaps the occasional short delay).
There used to be some sticky posts explaining how to do this. I wonder if they are still there after the forum upgrade....
First on
Push button turn off relais directly 5 seconds then turn on
Push button turn off relais directly 5 seconds then turn on
Push button turn off relais directly 5 seconds then turn on
int pin = 2;
int relais = 10;
void setup()
{
pinMode(pin, INPUT_PULLUP);
pinMode(relais, OUTPUT);
attachInterrupt(0, isr, FALLING);
}
volatile long last = 0;
volatile bool turnOff = true;
volatile long offAt = 0;
void isr()
{
if( (millis() - last ) > 20 ) //if at least 20 ms has passed since last press, this is not a dup
{
last = millis(); //note the time, for ignoring duplicate presses
turnOff = true;
offAt = millis() + 5000; //save a variable of now + 5 seconds
digitalWrite(relais, LOW); //turn off
}
}