Category: Assignment-09

Luo Yi Tan – Hallowuino

I made a horrifying ghoul for halloween, using a box, leds, servos, ping pong balls, vampire teeth and an arduino.

There is a photoresistor in its nose, which detects the amount of light in the environment. When the lights are off, the servos twitch at random angles to move the eyes and mouth. I used the autotune function from the circuit 6 in the SIK book so I didn’t have to calibrate it in different lighting environments.

Video of it in action:

 

Here’s a diagram of my circuit:

and my code:

#include 
Servo servo1, servo2, servo3;  // servo control object
int pos1 = 0;
int pos2 = 0;
int led1 = 11;
int led2 = 6;
int input = 3; 
 
int period = 500;
int sensorVal = 0;
unsigned long lastDidItTime = 0;
int high = 0, low = 1023;
 
void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(input, INPUT);
  servo1.attach(9);
  servo2.attach(10);
  servo3.attach(3);
  Serial.begin(9600);
} 
 
void loop() {
  sensorVal = analogRead(A0);
  autoTune();
  unsigned long presentTime = millis();
  Serial.println(sensorVal);
  if(sensorVal > 0){  
    unsigned long elapsedAmount = presentTime - lastDidItTime;
    if (elapsedAmount > period){
      pos1 = random (50, 140); 
      pos2 = random (30, 70);
      servo1.attach(9);
      servo2.attach(10);
      servo1.write(pos1);
      servo2.write(pos1);
      digitalWrite(led1, HIGH);
      digitalWrite(led2, HIGH);
      lastDidItTime = presentTime;
      servo3.write(pos2);
    }
  }
  else {
    servo1.write(90);
    servo2.write(90);
    servo3.write(90);
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
  }
 
}
 
void autoTune()
{
  if (sensorVal < low)   {     low = sensorVal;   }     if (sensorVal > high)
  {
    high = sensorVal;
  }
 
  sensorVal = map(sensorVal, low+30, high-30, 0, 255);
  sensorVal = constrain(sensorVal, 0, 255);
 
}

Minnar – Halloweeno!

Timid Ghostie: Description

I wanted to create on object that would encourage and react to certain types of interaction. The ghost I created will move forward to your hand smoothly and sweetly when you approach it slowly, but freaks out (jerky movement backward and forward fast) when you approach it too quickly. I’m using an infrared distance sensor to detect where someone is in relation to ghostie, and then I also calculate the rate at which someone is approaching ghostie.

 Video

 

Code & Fritzing Diagram

#include  
Servo servo1;
 
float runningAverage = 0;
int startTime = 0;
int spookyDuration = 1000; // one second
boolean bAmBeingSpooky = false;
 
void setup()
{
  Serial.begin(9600); 
  servo1.attach(9);
 
  Serial.println("Program Starting"); 
  pinMode (13, OUTPUT);
}
 
void loop(){  
  delay(50); 
  int sensorVal = analogRead(2);
  int previousAverage = runningAverage;
  runningAverage = 0.91*runningAverage + 0.09*sensorVal; // higher previous runningAvg = slower movement
  //Serial.println(runningAverage); 
 
  if (runningAverage > 400){
    startTime = millis();
  }
 
  int prevPos = map(previousAverage, 0, 800, 0, 180);
  int curPos = map(runningAverage, 0,800, 0,180); 
 
  if (curPos - prevPos > 5){
    servo1.write(0);
  } else {
   servo1.write( curPos );
  }
 
}

 

 

Sarah Anderson Hallowino – My Precious

My Hallowino project was heavily influenced by J.R.R. Tolkien and in anticipation of the upcoming “Hobbit” movie. I crafted a little box that is a “cage” for Gollum, a creepy and dangerous creature from Tolkien’s famous series. I placed two red LEDs in his eyes and I placed a force sensing resistor on the inside of a ring that looks like “the one ring”, the famous and coveted ring of power, from the books. When you put on the ring (and flex your hand or make a fist), Gollum sees that you have his Precious and his eyes glow red with rage!!!

Photo of the arduino in action:

sarah_2

Video of the arduino in action:

 

Arduino circuit diagram:

 

Arduino code:

 

 //Sarah Anderson, seanders
//Hallowino
 
const int sensorPin = 0;
const int ledPin = 9;
const int ledPin2 = 10;
 
int pressLevel, high = 900, low = 1300;
 
void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);  
}
 
void loop()
{
  pressLevel = analogRead(sensorPin); 
  manualTune();  
  analogWrite(ledPin, pressLevel);
  analogWrite(ledPin2, pressLevel);
}
 
void manualTune()
{
  pressLevel = map(pressLevel, 1000, 900, 0, 255);
  pressLevel = constrain(pressLevel, 0, 255);
}

Connie : Hallowuino

For this project I created a rather dramatically lit scene of a grizzly animal sacrifice to an elder god. There are red LEDs that fade up, as well as a single bright white one that blinks on a variable time setting – both these are hooked up to a photo sensor – so as a person approaches the piece and blocks the light the lighting gets more frenetic and creepy.

 

connie_1

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const int sensorPin = 0;
const int ledPin[ ] = {5, 6, 9, 10, 11};
const int blinky = 13;
 
int lightLevel, high = 0, low = 1023;
int flashTime;
 
void setup()
{
  Serial.begin(9600);
  for (int i=0; i<5; i++){
   pinMode (ledPin[i], OUTPUT); 
  }
  pinMode (blinky, OUTPUT);
}
 
void loop()
{
 
  lightLevel = analogRead(sensorPin); // 0....1023
 
  autoTune(); // this modifies lightLevel
 
  for (int i=0; i<5; i++){
    analogWrite(ledPin[i], lightLevel); // 0....255
  }
 
  //flashing();
  delay (1);
 
  flashTime = map (lightLevel,0,255, 2000, 65);
  int sec = millis()/flashTime;
  int whatToDo = sec %2;
  if (whatToDo == 0){
    digitalWrite(blinky, HIGH);
  } else {
    digitalWrite(blinky, LOW);
  }
 
}
 
 
void autoTune()
{
  if (lightLevel  high){
    high = lightLevel;
  }
 
  lightLevel = map(lightLevel, low+30, high-30, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
}

 

Rosey – Assignment 9

Description:

For my project, I was first inspired by the way servo motors seemed to have a similar range of motion as a wrist. Since the project was Halloween themed, I decided to make some skeleton-like hands to attach to the servos. From there, I just kept adding in more parts to make it seem like some robotic skeleton, including two red LEDs as eyes. The last thing I put in to make it slightly more interactive was a photocell that increased the speed of the servo and intensity of the light when covered.

Video:

hallowuino_rosey_1

Fritzing:

 

 Code:

#include 
const int sensorPin = 0;
const int ledPin1 = 5;
const int ledPin2 = 6;
Servo servoBlack;
Servo servoBlue;
int lightLevel;
int lightLevel2, high = 0, low = 1023;
int servoDelay;
int ledBright;
 
void setup(){
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  servoBlack.attach(10);
  servoBlue.attach(11);
  Serial.begin(9600);
}
 
void loop(){
  lightLevel = analogRead(sensorPin);
  lightLevel2 = analogRead(sensorPin);
  Serial.println(lightLevel);
 
  autoTune();
  analogWrite(ledPin1, ledBright);
  analogWrite(ledPin2, ledBright);
 
  servoDelay = map(lightLevel, 273, 700, 100, 20);
  int position;
  for(position = 0; position < 120; position += 2)
  {
    servoBlack.write(position);
    servoBlue.write(position);
    delay(servoDelay);
  }
}
 
void autoTune(){
  if (lightLevel2 < 700){     low = lightLevel;   }   if (lightLevel2 > 273){
    high = lightLevel;
  }
 
  ledBright = map(lightLevel2, 273, 675, 20, 255);
  ledBright = constrain(ledBright, 20, 255);
}

Hallowuino

I decided to make a mutant Baby Pumpkin Monster in celebration of Hallowuino. If you leave ze monster alone, it is a peaceful jack-o-latern. But, if you push his button, he will seek revenge. His eyes will switch from a yellow glow to flashing red, and his arms will swing with the intent to attack you.

mackenzie_1

If I were to put this piece in gallery, there would be a spooky night background behind it, and a metal link chain would be wrapped around it making it look as if it is being restrained. There would also be a sign next to it that reads: “Beware of Monster: DO NOT PUSH HIS BUTTON”. For some reason it is a natural instinct for people to rebel and press the button in this case, thus making the piece interactive.

Here is the video of my monster:

 

Here is the Arduino Fritzing diagram of my monster:

Here is the code for my monster:

#include   // servo library
Servo servo1;  // servo control object
Servo servo2;  // servo control object
 
int redLED = 12;
int yelLED = 13;
const int buttonPin = 2;
 
//-----SCARY SETTINGS-----
int redEyeFlashTime = 75;
int motorCalls = 4;
 
void setup()
{
  pinMode(redLED,OUTPUT);
  pinMode(yelLED,OUTPUT);
 
  pinMode(buttonPin, INPUT);
 
  servo1.attach(9);
  servo2.attach(6);
 
  normalMode ();
}
 
void loop()
{
  //-----Check Button State-----
  int  buttonState = digitalRead(buttonPin);
 
  if (buttonState == LOW)
  {
    scaryMode();
  }
  else
  {
    normalMode();
  }
}
 
void normalMode ()
{
  digitalWrite(redLED, LOW);
  digitalWrite(yelLED, HIGH);
}
 
void scaryMode ()
{
  //-------SERVO CODE-------
  for(int i = 0; i < motorCalls; i++)
  {
    //int position1 = constrain(random(0, 180), 0, 180);
    int position1 = constrain(random(0, 180), 110, 180);
    servo1.write(position1);  // Move to next position
 
    int position2 = constrain(random(0, 180), 110, 180);
    servo2.write(position2);  // Move to next position
 
     //-------LED CODE----------
    digitalWrite(yelLED, LOW);
    digitalWrite(redLED, HIGH);
 
    delay(redEyeFlashTime);
 
    digitalWrite(redLED, LOW);
 
    //-------SERVO CODE-------
    position1 = constrain(random(0, 180), 0, 70);
    servo1.write(position1);  // Move to next position
 
    position2 = constrain(random(0, 180), 0, 70);
    servo2.write(position2);  // Move to next position
 
    delay(redEyeFlashTime);
  }
}

Michael Importico – HALLOWUINO!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include  
 
// Create a servo "object", called servo1. Each servo object
// controls one servo (you can have a maximum of 12):
 
Servo servo1;
const int flexpin = 0; 
const int motorPin = 5;
 
void setup() 
{   
  Serial.begin(9600);
  servo1.attach(9);
  pinMode(motorPin, OUTPUT);
} 
 
void loop() 
{ 
  int motospeed;
  int flexposition;    // Input value from the analog pin.
  int servoposition;   // Output value to the servo.
 
  // Read the position of the flex sensor (0 to 1023):
 
  flexposition = analogRead(flexpin);
 
  servoposition = map(flexposition, 760, 938, 0, 180);
  servoposition = constrain(servoposition, 0, 180);
  motospeed = map(flexposition,760,930,0,255);
  servo1.write(servoposition);
  analogWrite(motorPin, motospeed);
 
  //serial sensor info
  Serial.print("sensor: ");
  Serial.print(flexposition);
  Serial.print("  servo: ");
  Serial.println(servoposition);
  delay(20);  // wait 20ms between servo updates
}
The guts of my Mummy
1
This was an exciting project.  I used one flex sensor, one motor and a servo.  The action is activated by "hurting the mummy" - this means bending him in places he does not want to bend.  This upsets the Mummy and as you hurt him, he begins to writhe in pain - flailing his arms as his head spins.

Oliver – Hallowuino!!

I decided to make a creepy doll arm “graveyard” where the ground is made of (fake) fur. Three plastic doll arms are connected to Servo motors, and they rotate at a speed controlled by a sliding potentiometer. If the potentiometer is at its lowest value, the arms twitch instead of rotating.

Photo:

 

Video:

 

Fritzing diagram:

 

Code:

#include Servo.h 
// WordPress will not allow the less than / greater than 
// symbols that normally go around Servo.h 
 
Servo servo1, servo2, servo3;
const int sensorPin = 0;
int sensorValue, delayTime, position;
 
void setup() {
  // servos are connected to pins 7, 8 and 9
  servo1.attach(9);
  servo2.attach(8);
  servo3.attach(7);
  Serial.begin(9600);
}
 
void loop() {
  sensorValue = analogRead(sensorPin);
  Serial.println (sensorValue); 
  moveServos();
}
 
void moveServos() {
  // rotate to 180 degrees
  for(position = 0; position = 0; position -= sensorValue) {       
    changePositions();         
  }
}
 
void changePositions() {
  // test for the sensor value as servo rotates to see if it should 
  // change speed
  sensorValue = analogRead(sensorPin);
  // map potentiometer values to speeds 1-7
  sensorValue = map(sensorValue, 0,900, 1,7);
  servo1.write(position);
  servo2.write(position);
  servo3.write(position);
  // test for delay time as servo rotates to see if it should 
  // switch to twitching
  delayTime = testDelayTime();
  delay(delayTime);  
}
 
int testDelayTime() {
  // if the potentiometer value is less than 2, switch to the 
  // twitching motion by setting delay time to zero
  if (sensorValue < 2) {
    delayTime = 0;
  }
  else {
    delayTime = 20;
  }
  return delayTime;
}

Josh Lopez-Binder, Assignment 09

joshua_1

A little wire monster with a movable jaw, eyes that blink in various ways, and a motor with an off-center weight that causes the monster to shake.

#include <Servo.h>
Servo servo1;
 
int numLeds = 2;
int ledPins[2] = {
  13,12};
int sensorPin = A0;
int motorPin = 2;
int elapsed = 0;
int startMilli = 0;
int timeBlink = 100; //millis
boolean eyesAreOn =false;
boolean buttonWasPressed = false;
 
void setup(){
  Serial.begin(9600);
  for(int i = 0; i < numLeds; i++){
    pinMode(ledPins[i], OUTPUT);
 
  }
  pinMode(motorPin, OUTPUT);
  //pinMode(sensorPin, INPUT);
  servo1.attach(9);
}
 
void loop(){
 
  int sensorVal = analogRead(sensorPin);
  Serial.println(sensorVal);
  if(sensorVal <10){
    rawr();
  }
}
 
void rawr(){
 
  startMilli = millis();
  for(int angle = 0; angle= timeBlink){
      startMilli = millis();
      for(int i = 0; i< numLeds; i++){
        if(eyesAreOn){
          digitalWrite(ledPins[i], LOW);
        } 
        else {
          digitalWrite(ledPins[i], HIGH);
        }
      }
      eyesAreOn = !eyesAreOn;
    }
    servo1.write(angle);
    delay(20);
 
    for(int i = 0; i< numLeds; i++){
      digitalWrite(ledPins[i], LOW);
 
    }
 
  }
  digitalWrite(motorPin, HIGH);
  //freak out eyes, freak out motor
  for(int i = 0; i<45; i++){
    int ledRand1 = random(0,100);
    int ledRand2 = random(0,100);
    if(ledRand1<=50){
      digitalWrite(ledPins[0], HIGH);
    } else{
      digitalWrite(ledPins[0],LOW);
    }
    if(ledRand2 <=50){
      digitalWrite(ledPins[1],HIGH);
    } else{
      digitalWrite(ledPins[1],LOW);
    }
    delay(70);
  }
  digitalWrite(motorPin, LOW);
 
  servo1.write(10);
 
}

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;
    }
  }
 
}
Comments Off on Assignment 09 Posted in