This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
laser_tripwire_rubber_band_shooter [2018/07/16 16:58] glassgiant created |
laser_tripwire_rubber_band_shooter [2018/08/09 16:38] glassgiant [Arduino Code] |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== How it works ====== | ||
+ | A laser constantly shines on a [[https:// | ||
====== Wiring Diagram ====== | ====== Wiring Diagram ====== | ||
Line 6: | Line 8: | ||
{{: | {{: | ||
+ | ====== Arduino Code ====== | ||
+ | <code c> | ||
+ | #include < | ||
+ | |||
+ | int lightPin = A0; //define a pin for Photo resistor | ||
+ | int ledPin=13; | ||
+ | int threshold = 800; //define threshold value. Below this, the beam is assumed to be broken | ||
+ | int servoPin = 11; //define a pin for the servo | ||
+ | int fireposition = 40; | ||
+ | int homeposition = 150; | ||
+ | |||
+ | Servo myservo; | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(9600); | ||
+ | pinMode( ledPin, OUTPUT ); | ||
+ | myservo.attach(servoPin); | ||
+ | myservo.write(homeposition); | ||
+ | delay(10000); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | | ||
+ | | ||
+ | while (analogRead(lightPin) > threshold){ | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | </ |