0

I am trying to get a random triggering of a single relay from an Arduino Uno. I would also ultimately like to be able to adjust the speed that the random triggering happens at. How are the times between the randoms adjusted? I have tried some codes and have the relay hooked up to pin 8 on the Uno, and would like more control. Thanks

void setup () {
pinMode(8, OUTPUT);
}


void loop() {

long randnumber;
long randnumber2;
long randnumber5;
long randnumber6;

randomSeed(analogRead(A0));

randnumber = random(5, 9);
randnumber2 = random(5,9);
randnumber5 = random(3370,498);
randnumber6 = random(537,4370);

digitalWrite(randnumber, HIGH);
digitalWrite(randnumber2, LOW);
delay(randnumber5);
digitalWrite(randnumber, LOW);
digitalWrite(randnumber2, HIGH);
delay(randnumber5);
}
  • 1
    Can you show us the sketch you are using now? – VE7JRO Feb 10 at 19:44
  • 1
    Use the blink-without-delay arduino.cc/en/tutorial/BlinkWithoutDelay Remove the 'const' of the variable interval, and use random arduino.cc/reference/en/language/functions/random-numbers/… for the interval. Set the new random interval inside the if-statement. Adjust the min and max parameters of the random for speed control. – Jot Feb 10 at 19:48
  • VE7JRO, Here is the code I have so far: void setup () { pinMode(8, OUTPUT); } void loop() { long randnumber; long randnumber2; long randnumber5; long randnumber6; randomSeed(analogRead(A0)); randnumber = random(5, 9); randnumber2 = random(5,9); randnumber5 = random(3370,498); randnumber6 = random(537,4370); digitalWrite(randnumber, HIGH); digitalWrite(randnumber2, LOW); delay(randnumber5); digitalWrite(randnumber, LOW); digitalWrite(randnumber2, HIGH); delay(randnumber5); } – Waddy P Feb 10 at 22:40
  • This is my 1st Arduino project – Waddy P Feb 10 at 22:41
  • 3
    @WaddyP consider editing your original post by adding your code section. Non trival code in a comment section is nearly unreadable. – RamblinRose Feb 10 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.