With the code below will the two pin random at the same time with the same random times?
No. Write to both pins then delay(). While you are at it, change the comments to make sense.
With the code below will the two pin random at the same time with the same random times?
No. Write to both pins then delay(). While you are at it, change the comments to make sense.
Is this what you mean?
digitalWrite(smokePin, HIGH); // sets the SMOKE on
digitalWrite(airpumpPin, HIGH); // sets the SMOKE on
delay(onTime); // waits for a random time while ON
digitalWrite(smokePin, LOW); // sets the SMOKE off
digitalWrite(airpumpPin, LOW); // sets the SMOKE off
delay(offTime); // waits for a random time while OFF
Is this what you mean?
That is what I had in mind but preferably with the comments corrected for clarity.
Is there likely to be a requirement for independent control or different delay()s for the two devices ?
Actually after understanding the voltage at the pins, the design changed.
I Connected both the airpump and clearomizer to a N Mosfet because they both draw higher amps than the digital pins can provide.
N Mosfet:
Gate= Connected to digital pin of Audrino
Drain= Connected to both Ground of Airpump & Ground of Clearomizer
Source= Connected to both Ground of the battery & Ground of Audrino
Lipo Battery Positive= Connected Positive to Raw pin of Audrino & Positive of Airpump & Clearomizer.
Now I need to vacuum the airpump tubing to the clearomizer with hot glue and some electrical tape and double check all the connections.
Final code that I am using.
I also found the analog write speed variable which can control the motor speed.
Added that code below.
/*
Random On/Off for (Smoke Machine)
With Analog Motor Speed Control.
Contributions by @J-M-L, PaulS, UKHeliBob
Pin 9, Pwn Analog Pin (smokePin)
Speed Control:
analogWrite(smokePin, 64); //slow
analogWrite(smokePin, 128); //medium
analogWrite(smokePin, 255); //fast
*/
const byte smokePin = 9; // Pin 9 (Pwn Analog) of the Arduino needs to connect to power of fish pump
unsigned long onTime = 0; // variable for the ON time
unsigned long offTime = 0; // variable for the OFF time
void setup() // run once, when the sketch starts
{
randomSeed (analogRead (0)); // randomize
pinMode(smokePin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
onTime = random (5000, 10000); // generate ON time between 5 and 10 seconds
offTime = random (10000, 15000); // generate OFF time between 10 and 15 seconds
analogWrite(smokePin, 255); //sets the Smoke On & Motor Speed- 64 Slow, 128 Medium, 255 Fast
delay(onTime); // waits for a random time while ON
digitalWrite(smokePin, LOW);
delay(offTime); // waits for a random time while OFF
}