From ArduinoInfo
Jump to navigation Jump to search



This sketch uses a potentiometer to change the speed of a Strobelight that uses LEDs. Example shown uses the YourDuino RoboRED (Comes with free cables like those shown) and the BRIGHT! White 3 Watt LED and the Slide Potentiometer (Click).

You can use other potentiometers of 1K ohms to 100K ohms, and other not-so-bright LEDs, but you'll need a fairly dark room and close spacing to see the strobe effect. With other LEDs use a small value series resistor such as 100 ohms, or two 200 ohms in parallel. Also notice that TWO pins (12 and 13) can be used for LEDs.

The adjustable timing Strobe Light can make rotating wheels, FIDGET SPINNERS, fans etc. appear to "stop". Falling series of drips can be made to appear stopped. See: NOTE: The code for RPM is UNDER CONSTRUCTION .. YMMV

(Copy and Paste the sketch below into a blank Arduino IDE Window)

/* YourDuinoStarter Example: Controllable Time Strobe LED V3 "SpinnerStrobe"
  - WHAT IT DOES: Flashes an LED with variable timing set by a potentiometer
   - Can "stop" motion of rotating wheels, fans etc.
   - Works best with a High Output LED like this:
   - Can tell you the "RPM" of a device with 1, 2 or 3 "legs"
  - INFO: See
  - SEE the comments after "//" on each line below
   - LED: Pin 13
   - Potentiometer: Pin A2
  - V1.06 05/31/2015
   Questions: */

/*-----( Declare Pin Numbers )-----*/

#define potentiometerPin 2   // Pot connected to ANALOG Pin 2 will control strobe speed.
#define ledPin           13  // Same as the small built-in LED, also use for separate bright LED
#define otherLedPin      12  // Optional for more LEDs, not-so-bright LEDs

/*-----( Declare Constant Values )-----*/

// Set the minimum delay between flashes in milliseconds (thousandths of a second)
#define minDelay  1   // 1/1000 of a second

#define maxDelay  500  //SO: That's 200/1000 right? 1/5 of a second. 5 flashes per second.

// How long should the each flash be?
#define onTime  500    //SO: 500/1000000 hmm.. reduce fraction: .5/1000  1/2 of 1/1000 of a second

/*-----( Declare Variables )-----*/

int potPosition ;  // Value from analogRead of the pot.  Values from 0..1023
int strobeDelay ;  // How long between flashes? Changed by Pot position

void setup()   /****** SETUP: RUNS ONCE AT THE BEGINNING ******/
  Serial.begin(115200);          // Start the serial port (Watch on serial monitor)
  pinMode(ledPin,      OUTPUT); // Set up ledPins as an output.
  pinMode(otherLedPin, OUTPUT);
  Serial.println("START Strobe for Fidgit Spinner etc.");
}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
  potPosition = analogRead(potentiometerPin);  // Read the pot position

  // convert the 0 to 1023 range we get from analogRead, into our strobe delay range of 1 to 200
  strobeDelay = map(potPosition, 0, 1023, maxDelay, minDelay); // Clockwise is faster??
  Serial.print("StrobeDelay(Milliseconds) = ");
  Serial.print("  Revolutions per second) = ");
  Serial.print(1000 / strobeDelay);
  Serial.print("  Revolutions per minute) = ");
  Serial.println(60 * (1000 / strobeDelay));

  /*---( Blink the LED ON and OFF )-----*/
  for (int i = 0; i < 10; i++)
    digitalWrite(ledPin,      HIGH); // Switch the ledPin to HIGH, turn it on!
    digitalWrite(otherLedPin, HIGH); // Switch the ledPin to HIGH, turn it on!
    delayMicroseconds(onTime); // Delay while on, for onTime.
    digitalWrite(ledPin,      LOW); // Switch the ledPin to LOW, turn if off!
    digitalWrite(otherLedPin, LOW); // Switch the ledPin to LOW, turn if off!
    delay(strobeDelay); // Delay while off, for strobeDelay
}//--(end main loop )---

//*********( THE END )***********