Assignment 09
Arduino controlled Silly String shooter
Hallowuino!
Due Wednesday, October 31: Use a 9V battery to create a standalone (i.e. not connected to the computer) Halloween prop. It can be part of a costume, or a modification of a commercially available decoration (if you wish). It should be spoooky!
Shoot a video of the object in action; post it on YouTube and embed it in a blog post with the category Assignment-09.
- It should have at least one input: buttons, potentiometer, sensors….
- It should have some kind of output: LEDs and/or servo, etc. etc.
- It should work without a computer attached. Program the Arduino, unplug the USB and plug the 9V cable. You can press the tiny reset button to restart the program.
- You can use alligator clips or wire extensions to separate Arduino + board from sensors and actuators.
- You can check the examples in the manual, like the DC motor…
- LEDs themselves are not that exciting, but you can use all sorts of objects to diffuse their light ping-pong balls, balloons, pumpkins…
Code Example:
Light sensor controlled twitchy servo. Servo twitches randomly when it gets dark.
#include <Servo.h>
Servo servo1;
int pos1 = 0;
int period = 500;
int sensorValue = 0;
unsigned long lastDidItTime = 0;
void setup() {
servo1.attach(3); // attaches the servo on pin 3 to the servo object
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(A0);
unsigned long presentTime = millis();
if(sensorValue < 90){ // if it's dark...
unsigned long elapsedAmount = presentTime - lastDidItTime;
if (elapsedAmount > period){ // do something spooky
pos1 = random (0, 180);
servo1.write(pos1);
lastDidItTime = presentTime;
}
}
}