Posts | Comments

Planet Arduino

Archive for the ‘Arduino Sketch’ Category

Contest Entry by Joe Cochran
In another project, I created a way to control a 8×8 RGB Matrix using an Atari Joystick. While waiting for one of the components to arrive, I had an idea that a maze could be constructed on the RGB Matrix and a user could go through the maze with a joystick.

Most maze algorithms assume that the maze can have “paper-thin” walls. That is, that the occupiable spaces don’t occupy the same amount of space as the walls. However, with the RGB Matrix the walls have to be represented by a whole LED being turned on. So in essence each LED is marked as a “wall” or as an “occupiable space”
Joe has created a page that contains the detailed instructions on how to create your own JoyLite Maze. I am posting the link to it, rather than recreating it all again.

JoyLite Maze “How To”.

Joe Says:Arduino has been a fantastic opportunity to for me rediscover the creative process. I became a software developer because I get a lot of satisfaction from turning an idea into reality. When you get down to it though, professional software development ends up being little more than manipulating some bits in databases and RAM. Nothing tangible. Arduino has allowed me to move beyond the “cyberspace” and into the “real world”, opening the door to physical computing with motors, switches, lights and dials. And while I may be short on knowledge in regards to the electrical and mechanical engineering aspects of these projects, the Arduino community is so healthy, friendly and capable that they help make learning this stuff a real treat too.
Share/Bookmark
Arduino Start Here Robot

Arduino Start Here Robot

Contest entry by Dane Edmonds. This is my first robot using Arduino , it uses a l239d motor driver and is basically my attempt at making a “start here” robot.

This is my first time using Arduino so I decided to build a robot that would help me learn arduino’s code , I wanted to start small and build up to harder things so I made the robot expandable , as I get better with coding I will add more things .  So I hope other people who are new to arduino can learn from this robot to

Dane says: Arduino has meant a cheap and easy to use micro controller, giving people a chance to achieve their goals and has helped make school holidays less boring for me .

YouTube Video Available Here.

Parts list :

Things you can add :

Build It! instructions:

  • 1) cut thin scrap wood (about 8 millimeters thick) in to 2 squares of 13.5 cm x 13.5 cm
  • 2) in one of the squares cut hole the same size as your servo base , about 1cm from one of the edges .
  • 3) paint desired colour
  • 4) using a hot glue gun glue the motors in place (as shown in top picture), with some small screws ,screw in the Arduino to the breadboard will have adhesive tape on the back, peel of plastic and stick in place.
  • 5) using this walk through set up your motor controller http://letsmakerobots.com/node/2074
  • 6) drill 2 holes in the back corners of the wood to fit your spacers and one above the Arduino (do the same for the 2nd piece of wood .
  • 7) put your servo in place , and screw into wood
  • 8)  made a pan/tilt system with a bit of scrap metal , (you can do the same if you wish but is not needed )
  • 9) screw in your infrared sensers(as shown below) attach header pins (look on the sensor connect VIN and GND to the bread board power lines  and OUT to a digital pin on your arduino.

Arduino Sketch

const int infra=3; 

const int infra2=4;  

  void setup()

 {    

Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode (11,OUTPUT);
pinMode (10,OUTPUT);
pinMode (infra,INPUT);
pinMode (infra2,INPUT); 

} 

 void loop()    {
if (digitalRead(infra)== HIGH)
{         driveforward();   

   }        

if(digitalRead(infra) == LOW)   

{       

  stopmot();      

  delay (500);      

  reverse();      

  delay (500);       

 right();        

delay (2000);  

  }         

  else if (digitalRead(infra2)== LOW)   

   { stopmot();       

 delay (500);      

  reverse();     

   delay (500);       

 left();        

delay (2000);     

 }   

         }             

  void driveforward()

 {   digitalWrite(13,HIGH);   

digitalWrite(10,HIGH);  

 digitalWrite (11,LOW); 

  digitalWrite (12,LOW);

 } 

 void stopmot()

 {    

digitalWrite(13,LOW);  

 digitalWrite(12,LOW);   

digitalWrite(11,LOW);  

 digitalWrite(10,LOW);

 } 

void reverse() 

{ 

  digitalWrite(12,HIGH);  

 digitalWrite(11,HIGH); 

  digitalWrite (13,LOW); 

  digitalWrite (10,LOW);

 } 

 void right()

 {   

digitalWrite (10,HIGH); 

  digitalWrite (13,LOW);  

 digitalWrite (12,LOW);  

 digitalWrite (11,LOW);

 } 

 void left()

 {  

 digitalWrite (13,HIGH); 

  digitalWrite (11,LOW);  

 digitalWrite  (12,LOW); 

  digitalWrite (10,LOW);

}
Share/Bookmark
Dic
06
7-Segment LED

7-Segment LED

Fun with Arduino contest entry submitted by Jeff.

For a while now I’d been interested in things like networked objects and gps/location-awareness, and I think that soon enough we’re going to see a lot of ‘intelligent objects’ out and about in the world.

I love the idea of being able to actually build something like that, but there’s a lot I don’t know about the hardware side of things. What little electronics I studied was long in the past; I’d done a little coding for microcontrollers, but only a little. But there was something about the Arduino that made it seem more accessible.

So my wonderful wife, who is wonderful if I didn’t mention that, bought me the “Arduino Advanced Starter Kit” and the accompanying book “Getting Started with the Arduino” for my birthday. Yay!

I have had enough hardware exposure that nothing in the package was a total mystery, and I understood the concept of breadboarding a circuit, so it only took maybe 15 minutes to get the software installed, a basic circuit built (ok, I stuck a LED onto two pins on the board), and wrote my first ‘hello world’ blinky-light program. The Arduino uses the aptly named Arduino language — it seems to be C with a light wrapper and a library, so it came pretty naturally.

Following along with the exercises in Getting Started, I experimented with the with the various inputs and outputs, got some hands-on-experience building the circuits out. It didn’t take me long at all to start wandering off-script and just building out random ideas that involved an LED and a button.

After a few hours, I thought it would be fun to do something a little more challenging. I went and went and picked up an 7-segment LED (Radio Shack part 276-075). With the pin designations, it was pretty easy to hook the 7 segments up to 7 outputs on the Arduino board.

On the software side, I mapped the segments onto bits – bit 0 maps to anode A, bit 1 to anode B, etc. — so the state of all 7 segments can be represented in a single byte. With the relatively small amount of memory available, compact representations are a good thing. Going the other way, I can look at that byte, and read each of the bits with bitRead() function, then set the LED segment appropriately.

Now that I had a working numeric LED, I needed a value to show on it. Borrowing a simple example from Getting Started, I wired up a photoresistor and had it report it’s state to Arduino’s analog input 0.

Arduino and 7-Segment LED

Arduino and 7-Segment LED

The analog inputs report a value from 0-1023 but my LED can only display 0-9, so I used the map() function to convert the input range to the output range and get the corresponding value back out — then display that. To help stabilize the number and keep it from flickering between values too quickly, I only update the LED if the value has changed, and then hold for a moment.

The full source code is below:

#define PHOTO 0

void setup()
{
  pinMode(0, OUTPUT); // -> Anode A, bit 0 in the definitions
  pinMode(1, OUTPUT); // -> Anode B, bit 1
  pinMode(2, OUTPUT); // -> Anode C, bit 2
  pinMode(3, OUTPUT); // -> Anode D, bit 3
  pinMode(4, OUTPUT); // -> Anode E, bit 4
  pinMode(5, OUTPUT); // -> Anode F, bit 5
  pinMode(6, OUTPUT); // -> Anode G, bit 6
}

// encode the on/off state of the LED segments for the characters
// '0' to '9' into the bits of the bytes
const byte numDef[10] = { 63, 6, 91, 79, 102, 109, 124, 7, 127, 103 };

// keep track of the old value
int oldVal = -1;

void loop()
{
  // grab the input from the photoresistor
  int input = analogRead(PHOTO);

  // convert the input range (0-1023) to the range we can
  // display on the LED (0-9)
  int displayVal = map(input, 0, 1023, 0, 9);

  // if the value has changed, then update the LED and hold for a
  // brief moment to help with the debouncing.
  if (displayVal != oldVal)
  {
    setSegments( numDef[displayVal] );
    delay(250);
  }
}

void setSegments(byte segments)
{
  // for each of the segments of the LED
  for (int s = 0; s < 7; s++)
  {
    int bitVal = bitRead( segments, s ); // grab the bit
    digitalWrite(s, bitVal); // set the segment
  }
}

Jeff also has another great Arduino tutorial for

Using the 555 timer as an external clock for the Arduino

Share/Bookmark
Dic
02
LED Cube with Arduino

LED Cube with Arduino

Fun with Arduino contest entry submitted by Gamaiel Zavala.

There are other Instructables about building LED cubes, this one is different for several reasons:

1. It’s built with a low number of off-the-shelf components and hooks up directly to the Arduino.
2. A clear, easy to reproduce circuit diagram is provided with plenty of photos.
3. A unique approach is used for the software which makes programming the cube easier and more expressive.

Parts needed:

-   1 Perfboard
-   3 NPN Transistors (2N2222, 2N3904, BC547, etc.)
- 12 Resistors (~220 ohms and ~22k ohms)
- 13 Headers (male or female)
- 27 LEDs
- Jumper wires

Prepare the LEDs

LED Jig

LED Jig

This step largely follows the LED Cube 4×4x4 but we’ll be building a 3×3x3 cube instead. A cube of this size is about as big as it gets without introducing additional circuitry and complexity. We’ll need a total of 27 LEDs that will be grouped into three sets of nine.

Each set of nine LEDs will share a common connection amongst their cathodes (negative leads). I’ll refer to each of these sets as a “level”. Each of the nine LEDs on a level is connected to the corresponding LED on the other two levels through their anodes (positive leads). These will be referred to as “columns”. If that didn’t make sense it will become self explanatory as we build the cube.

To start we’ll use a drill to create a jig out of a small piece of scrap wood. The jig will hold the LEDs in place while we solder them. I decided to space the holes around 5/8 of an inch apart (~15 mm) but the exact distance isn’t critical. The hole should have a tight fit around the LED since we don’t want them to move around while soldering.

Preparing the LEDs

Preparing the LEDs

Once the jig is done we’re going to bend the cathode of each LED in a 90 degree angle. The cathode is identifiable in three ways: 1) It’s the shorter leg, 2) It’s on the flat side of a round LED, 3) it’s connected to the larger piece inside the LED. Make sure you bend the cathode in the same direction for all of the LEDs.

Now we’re ready to begin soldering.

Solder the LEDs

LEDs ready to solder.

LEDs ready to solder.

First place nine of the LEDs in your newly built jig. Position them so that the legs point in the same counter-clockwise direction. The photos show the cathode pointing clockwise with the anode facing out, but I’d turn the LEDs around if I did it again in order to keep the leg from obstructing the view of the LED.

Solder the sides together, one pair on each side. Use small clips to keep the legs clamped together while applying the solder.

Once each of the four sides are soldered, move the clips to hold the corners together and apply solder to each. Lastly, solder the cathode of the middle LED to one of the sides and trim away the excess.

Repeat three times.

You should now have three sets of nine LEDs. Position two of the sets one on top of the other. Keep the distance equal to the spacing already established between LEDs. Once you’re comfortable with the spacing you can clamp each set of legs using two clips, one in each direction, to keep the legs firmly in place while soldering. You may need to bend around a LED to get a good connection. Solder each of the nine pairs, one at a time.

Do this one more time and you’re done with the cube.

Place the cube on one side of the the perfboard. Make sure the nine legs are positioned apart evenly while you guide each one through a hole. My board has five holes between each set of legs. You want to leave as much room as possible on the other end of the perfboard to fit the various components.

Add a few clips to hold the legs in place once you’re happy with the positioning. Leave plenty of leg poking through the bottom since this will make it easier to solder the resistors later. Turn the board over and solder each of the legs to keep them in place. Flip the cube back over once all the legs have been soldered.

Lastly we need to solder a lead from each of the levels down through the bottom of the board. Strip a piece of solid wire and bend a small hook on one end. Hang the hook on one of the center LEDs legs and guide it through a hole on the perfboard. Solder the hook end to keep the wire in place. Repeat again for the other two levels.

The next step is to build the rest of the circuit.

Build the Circuit

LED 3x3x3 Cube

LED 3x3x3 Cube

The circuit is pretty simple. Each of the nine columns will connect to a pin on the Arduino through a current limiting resistor. Each of the three levels connects to ground via a PNP transistor when activated by an Arduino pin.

We’ll be using 12 output pins total on the Arduino but there are 18 LEDs to power. The trick is that only a single level can be lit at a time. When a level is connected to ground, each of the LEDs on that level can be powered individually through one of the nine other Arduino pins. If we light the levels fast enough it will appear as if all three levels are lit at the same time.

Let’s build the circuit.

The first step is to prepare the nine current limiting resistors. I’m using 220 ohms per pin which will draw around 22mA. The value may vary depending on the LEDs that are being used but stay between about 135 and 470 ohms. Each pin is capable of sourcing up to 40mA.

In order to save room we want to solder the resistors in a vertical position. Bend one lead down so that both leads are parallel to each other. Do this for all nine of the resistors.

Once the resistors are ready we’ll solder them one by one. To make it easy we’re going to solder the resistor leads directly to the other components instead of using a separate wire for each. One end of the resistor will connect to a column and the other will connect to a header. Start with the first row of LEDs which is closest to the resistors and work your way back.

Once each row is finished you can use a small piece of tape to isolate the overlapping leads in order to prevent a short. Refer to the photos and diagram to see what this will look like once it’s finished.

Now that the columns are out of the way, the next step is to solder the components which control the levels. The base of a NPN transistor will be activated by an Arduino pin through a current limiting resistor of 22k (or thereabouts). This will connect the corresponding level to ground which will allow current to flow through the LEDs. Refer to the photos and diagram.

The circuit is now complete, time to move on to the software!

Using the Software

I was found a few code examples to control LED cubes on the net. They all required large arrays of binary or hex data to instruct the LEDs. I figured that there must be an easier way to program a cube so I set out to write my own software.

The first decision was to make the software mirror the hardware. That meant addressing each LED by column and level instead of using raw port data or the traditional x, y, z. The second decision was to start with basic functions, like turning a single light on or off, and building up from there.

Lastly I decided to introduce two features that are useful for effects. One is a buffer feature which allows the basic functions to build up more complex patterns, and the other is a sequence function which lights an array of lights one at a time or all at once.

This grew organically as procedural code and loose functions. It was very easy from there to follow the library tutorial in order to encapsulate the functionality into a class and create a reusable Arduino library.

Be sure to check out the class and example sketch or download the library .

Share/Bookmark

This is a repost of a previous project. I am still working to get the older post back online from when we upgraded Wordpress.

The robot was basically built using a Parallax Boe Bot chassis. Rather than using the Basic Stamp we added an Arduino with a proto shield to control the robot functions.

You can use any type of chassis for this project. The robot moves about using a ping sonar and IR sensors to avoid running into any objects. As you can see in the video, it was a bit thrown off by our kitten. We added additional items such as a wireless camera that sends audio/video back to our TV.The original design for this was created by an Instructable’s member and can be found here.

Items you will need for this project:

Arduino Autonomous Robot

Arduino Autonomous Robot

The standard servo will be used to mount the Ping Rangefinder. This will give you a back and forth sweep motion as the robot travels around. The two continuous rotation servos are used for the wheels. You do not need to use the Parallax brand of servos, other brands will work. You may have to adjust the PWM values in the source code to go with the servos you are using.

It is also possible to use DC motors and edit the code, which would be considerably cheaper. You could use a SN754410 Quad Half H-Bridge to drive two DC motors. Tutorial for how to do this is available here.

The Arduino hook up is pretty simple. You will have the following:

  • Pin (Analog) 0: Left Sensor
  • Pin (Analog) 1: Center Sensor
  • Pin (Analog) 2: Right Sensor
  • Pin 5: Pan Servo
  • Pin 6: Left Drive Servo
  • Pin 7: Ultrasonic Rangefinder ( ‘Ping)))’ )
  • Pin 9: Right Drive Servo
  • Pin 11: Piezo Speaker
Shield Close-up

Shield Close-up

Radioshack sells an RC car battery as well as connector repair kit. You can solder the repair kit connector onto the shield, and then be able to hook up your battery to power the servos with. You can use a separate battery holder to power the Arduino.

Make all your connections onto the shield. This way everything can remain in place if you need to use your Arduino for something else and save you from needing to tear apart everything.

for power to the shield, you won’t need any extra filter capacitors since the 5V switching  regulator has them built in. We used a small project box to hold the battery in place, and was able to attach the wireless camera on top of it.

The Arduino and camera are power source 1, while the servos and sensors are power source 2 (the RC battery). A small piece of PVC pipe mounted onto a cable clip will help you to keep your wires all organized to a central point and be less likely to get caught or tangled up into something as the robot is moving around.

Arduino Sketch

// Begin Robot Code
int micVal;
int cdsVal;
int irLval;  // Left IR
int irCval;  // Center IR
int irRval;  // Right IR

int i;   // Generic Counter
int x;  // Generic Counter
int PLval;  // Pulse Width for Left Servo
int PRval;  // Pulse Width for Right Servo
int cntr;  // Generic Counter Used for Determining amt. of Object Detections
int counter; // Generic Counter
int clrpth;  // amt. of Milliseconds Of Unobstructed Path
int objdet;  // Time an Object was Detected
int task;  // Routine to Follow for Clearest Path
int pwm;  // Pulse Width for Pan Servo
boolean add;  // Whether to Increment or Decrement PW Value for Pan Servo
int distance;  // Distance to Object Detected via Ultrasonic Ranger
int oldDistance;  // Previous Distance Value Read from Ultrasonic Ranger

float scale = 1.9866666666666666666666666666667;  // *Not Currently Used*

int LeftPin = 6;  // Left Servo
int RightPin = 9;  // Right Servo
int PiezoPin = 11;  // Piezo
int PingServoPin = 5;  // Pan Servo
int irLPin = 0;            // Analog 0; Left IR
int irCPin = 1;            // Analog 1; Center IR
int irRPin = 2;            // Analog 2; Right IR

int ultraSoundSignal = 7; // Ultrasound signal pin
int val = 0;              // Used for Ultrasonic Ranger
int ultrasoundValue = 0;  // Raw Distance Val
int oldUltrasoundValue;  // *Not used*
int pulseCount;        // Generic Counter
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13

#define BAUD 9600
#define CmConstant 1/29.034

void setup() {
  Serial.begin(9600);
  pinMode(PiezoPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(LeftPin, OUTPUT);
  pinMode(RightPin, OUTPUT);
  pinMode(PingServoPin, OUTPUT);
  pinMode(irLPin, INPUT);
  pinMode(irCPin, INPUT);
  pinMode(irRPin, INPUT);
  for(i = 0; i < 500; i++) {
    digitalWrite(PiezoPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(PiezoPin, LOW);
    delayMicroseconds(1000);
  }
  for(i = 0; i < 20; i++) {
  digitalWrite(PingServoPin, HIGH);
  delayMicroseconds(655 * 2);
  digitalWrite(PingServoPin, LOW);
  delay(20);
  }
  ultrasoundValue = 600;
  i = 0;
}

void loop()
{
  //Scan();
  Look();
  Go();
}
void Look() {
  irLval = analogRead(irLPin);
  irCval = analogRead(irCPin);
  irRval = analogRead(irRPin);
  //if(counter > 10) {
    //counter = 0;
    //readPing();
  //}
  if(irLval > 200) {
    PLval = 850;
    PRval = 820;
    x = 5;
    cntr = cntr + 1;
    clrpth = 0;
    objdet = millis();
  }
  else if(irCval > 200) {
    PLval = 850;
    PRval = 820;
    x = 10;
    cntr = cntr + 1;
    clrpth = 0;
    objdet = millis();
  }
  else if(irRval > 200) {
    PLval = 650;
    PRval = 620;
    x = 5;
    cntr = cntr + 1;
    clrpth = 0;
    objdet = millis();
  }
  else {
    x = 1;
    PLval = 850;
    PRval = 620;
    counter = counter + 1;
    clrpth = (millis() - objdet);
    if(add == true) {
      pwm = pwm + 50;
    }
    else if(add == false) {
      pwm = pwm - 50;
    }
    if(pwm < 400) {
      pwm = 400;
      add = true;
    }
    if(pwm > 950) {
      pwm = 950;
      add = false;
    }
    digitalWrite(PingServoPin, HIGH);
    delayMicroseconds(pwm * 2);
    digitalWrite(PingServoPin, LOW);
    delay(20);
    readPing();
    if(ultrasoundValue < 500) {
      cntr = cntr + 1;
      switch(pwm) {
        case 400:
          x = 7;
          PLval = 650;
          PRval = 650;
          Go();
          break;
        case 500:
          x = 10;
          PLval = 650;
          PRval = 650;
          Go();
          break;
        case 600:
          x = 14;
          PLval = 850;
          PRval = 850;
          Go();
          break;
        case 700:
          x = 10;
          PLval = 850;
          PRval = 850;
          Go();
          break;
        case 950:
          x = 7;
          PLval = 850;
          PRval = 850;
          Go();
          break;
      }
    }
  }
  //Serial.print("clrpth: ");
  //Serial.println(clrpth);
  //Serial.print("objdet: ");
  //Serial.println(objdet);
  //Serial.print("cntr: ");
  //Serial.println(cntr);
  if(cntr > 25 && clrpth < 2000) {
    clrpth = 0;
    cntr = 0;
    Scan();
  }
}
void Go() {
  for(i = 0; i < x; i++) {
    digitalWrite(LeftPin, HIGH);
    delayMicroseconds(PLval * 2);
    digitalWrite(LeftPin, LOW);
    digitalWrite(RightPin, HIGH);
    delayMicroseconds(PRval * 2);
    digitalWrite(RightPin, LOW);
    delay(20);
  }
}
void readPing() {  // Get Distance from Ultrasonic Ranger
 timecount = 0;
 val = 0;
 pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

/* Send low-high-low pulse to activate the trigger pulse of the sensor
 * -------------------------------------------------------------------
 */

digitalWrite(ultraSoundSignal, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ultraSoundSignal, LOW); // Holdoff

/* Listening for echo pulse
 * -------------------------------------------------------------------
 */

pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
val = digitalRead(ultraSoundSignal); // Append signal value to val
while(val == LOW) { // Loop until pin reads a high value
  val = digitalRead(ultraSoundSignal);
}

while(val == HIGH) { // Loop until pin reads a high value
  val = digitalRead(ultraSoundSignal);
  timecount = timecount +1;            // Count echo pulse time
}

/* Writing out values to the serial port
 * -------------------------------------------------------------------
 */

ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue

//serialWrite('A'); // Example identifier for the sensor
//printInteger(ultrasoundValue);
//serialWrite(10);
//serialWrite(13);

/* Lite up LED if any value is passed by the echo pulse
 * -------------------------------------------------------------------
 */

if(timecount > 0){
  digitalWrite(ledPin, HIGH);
}
} 
void Scan() {   // Scan for the Clearest Path
  oldDistance = 30;
  task = 0;
  for(i = 1; i < 5; i++) {
    switch(i) {
      case 1:
        //Serial.println("Pos. 1");
        pwm = 1125;    ///  incr. by 100 from 1085
        break;
      case 2:
        //Serial.println("Pos. 2");
        pwm = 850; //// increased by 100 from 850
        break;
      case 3:
        //Serial.println("Pos. 3");
        pwm = 400;
        break;
      case 4:
        //Serial.println("Pos. 4");
        pwm = 235;
        break;
    }
    for(pulseCount = 0; pulseCount < 20; pulseCount++) {  // Adjust Pan Servo and Read USR
      digitalWrite(PingServoPin, HIGH);
      delayMicroseconds(pwm * 2);
      digitalWrite(PingServoPin, LOW);
      readPing();
      delay(20);
    }
    distance = ((float)ultrasoundValue * CmConstant);   // Calculate Distance in Cm
    if(distance > oldDistance) {  // If the Newest distance is longer, replace previous reading with it
      oldDistance = distance;
      task = i;   // Set task equal to Pan Servo Position
    }
  }
  //Serial.print("Task: ");
  //Serial.println(task);
  //Serial.print("distance: ");
  //Serial.println(distance);
  //Serial.print("oldDistance: ");
  //Serial.println(oldDistance);
  distance = 50;  // Prevents Scan from Looping
  switch(task) {   // Determine which task should be carried out
    case 0:  // Center was clearest
      x = 28;
      PLval = (850);
      PRval = (850);
      Go();
      break;
    case 1:  // 90 degrees Left was Clearest
      x = 14;
      PLval = (650);
      PRval = (650);
      Go();
      break;
    case 2:  // 45 degrees left
      x = 7;
      PLval = (650);
      PRval = (650);
      Go();
      break;
    case 3:  // 45 degrees right
      x = 7;
      PLval = (850);
      PRval = (850);
      Go();
      break;
    case 4:  // 90 degrees right
      x = 14;
      PLval = (850);
      PRval = (850);
      Go();
      break;
  }
}

// End Robot Code
Share/Bookmark
Bridge Passage,courtesy of Professor Tom Robbins, Architecture

Bridge Passage, photo courtesy of Professor Tom Robbins, Architecture

The bridge, “Passage” by L. Brower Hatcher at Columbus State, is one of the most outstanding and notable landmarks on campus. Connecting the main parking garage and Davidson Hall over Spring Street, the bridge offers safe passage above the fast moving one-way traffic below. Painted bright red, it also adds a strong visual contrast against the blue sky above and the green grass below.

The bridge contains many educational symbols and decorative metal icons mounted along the passage, which at one time were lighted at night by fiber-optics, creating a moving array of colors and light. This night-time light display has been noticeably absent for several years, apparently due to the mechanical failure of the high-powered “luminaries” which project colored light through the fiber optic cables.

Bridge Icons

Bridge Icons

As a class project, we designed a Solar Powered LED Lighting system to replace the existing outdated system that no longer works. (I can’t reveal the design yet here until things are approved) After thorough investigation, our class determined that the luminaries, located on the side of the bridge, most likely failed due to heat build-up, and possibly corrosion from exhaust and salt water mist from the traffic below. By contacting the vendor, we discovered that the 277 VAC model PH-3001 luminaries installed when the bridge was commissioned are no longer manufactured, and the replacement units would not be compatible with any of the PH-3001 units which still may be repairable on the bridge.  This means that to light the bridge again using the high-powered Metal-Halide luminaries, all 14 units would need to be replaced, at a minimum cost of $13,000.00 USD, not including labor.

It is also important to note, that the PH-3001 units are extremely difficult to maintain. Maintenance is very labor intensive, and consumes a large block of time for maintenance personnel who obviously have a multitude of other important tasks, maintaining a large campus the size of Columbus State. The bulbs burn out frequently, with a replacement cost of $211.00 each, or approximately $3000.00 USD per year. The units are also located in a difficult to reach location, and the fragile glass color wheels which require frequent cleaning and maintenance because of pollution from the traffic below, are easily damaged during maintenance.

Cost Benefit Analysis:

As noted earlier, the old Metal Halide lighting units are very labor intensive, and difficult to maintain. Due to heat buildup inside the enclosed units (Metal Halide bulbs run very hot), the bulbs would need to be changed yearly at a material cost of $3000.00 USD. Added to this amount would be a minimum of 28 hours of labor at $40 per hour, or $1120 in labor costs. The 14 units each consume approximately 200 watts of power per hour, or a total of $3.36 per day, $1226 per year. This would bring the approximate operating costs for the old lighting units to $3000 + $1120 + $1226 = $5346.00 per year operating cost.

Since the Solar Powered LED illuminated bridge runs off of the Sun’s energy, electrical costs and Carbon footprint would be Zero. LED light bulbs have an average MTBF (Mean time between failure) of 50,000 to 100,000 hours, or approximately 20 times that of the metal halide bulbs. By eliminating the mechanical rotating color wheels, valuable maintenance costs for an LED lighting system would be greatly reduced, to possibly only several hours per year. The estimated cost savings for the Solar Powered LED lighting system would be over $5000.00 USD per year.

So far the school has seemed to drag their feet with getting things done. Each day when I go to class and walk across the bridge I day dream about more stuff to add to the design which brings me to my original intent for this post, which is how to connect a PIR sensor to an Arduino.

The bridge has lighted square panels along the walkway. What I would like to see added is the ability for each panel to light up as a person gets close and then turn off as they move further away. This I feel will add to the cost savings since the walk way lights will only be in use at night when there is traffic on the bridge. If nobody is on the bridge, there is no need for them to be on at that time since the only purpose they serve is to see where you are walking.

Arduino with PIR Sensor

Arduino with PIR Sensor

Connecting a PIR sensor to an Arduino board can be done easily. PIR sensors consist of 3 pins, Vcc (Positive Voltage), Vss (Ground), and Signal. Interfacing it to the Arduino only requires +5v, GND and a digital input pin.

I put a short video clip on YouTube showing how the sensor works and the code is below.

I am thinking I could easily put together a small board and have each one located throughout the bridge with PIR sensors connected to them to control the individual squares. Or possibly have one central location for a control station and each PIR sensor runs to it.

Then as you walk, each panel will light up and turn off a few seconds later as you move away from it. The panels are staggered all the way down the walkway, so this would give a nice effect at night as someone is walking across the bridge.

Another thought I had was to tie all the walkway panels into one PIR at the entrance and one PIR at the exit of the bridge (maybe one in the middle also) and then the bridge would light up in 2-3 stages, rather than individual panels. Kind of boring, but serves its purpose for safety.

Additional Resources:

Parallax PIR Sensor Datasheet

Arduino PIRsense

Arduino Sketch:

// Parallax PIR sensor's output

//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;        

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 5000;  

boolean lockLow = true;
boolean takeLowTime;  

int pirPin = 3;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;

//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
  }

////////////////////////////
//LOOP
void loop(){

     if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
       if(lockLow){
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;
         Serial.println("---");
         Serial.print("motion detected at ");
         Serial.print(millis()/1000);
         Serial.println(" sec");
         delay(50);
         }         
         takeLowTime = true;
       }

     if(digitalRead(pirPin) == LOW){
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause, 
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause){
           //makes sure this block of code is only executed again after 
           //a new motion sequence has been detected
           lockLow = true;
           Serial.print("motion ended at ");      //output
           Serial.print((millis() - pause)/1000);
           Serial.println(" sec");
           delay(50);
           }
       }
  }
Share/Bookmark
Side view

Side view

Contest Entry by Steve Hoefer

How many times have you seen a secret hideout with a secret knock?  It’s a staple of cheesy dramas, Saturday afternoon movies, and tree houses throughout the world.

While working on another project I ran across the Arduino knock sensor tutorial.  Sensing a single knock is a great little project for learning about microcontrollers, but what about sensing specific knocks?  Seeeeecret knocks?  And if we could detect a secret knock, shouldn’t it unlock a door?   If you can’t tell by looking this was cobbled together from spare stuff around the lab, it’s not much more than a piezo speaker, a tiny gear reduction motor, and an Arduino. And PVC pipe.

**Disclaimer: This was built with stuff I had lying around the lab.  How about a video to explain:

A microphone (okay, really a speaker) presses against the door and listens for knocks.  If it hears the right number of knocks in the right cadence it triggers the motor to turn the deadbolt and unlock the door.  If the sequence isn’t recognized, the system resets and listens for knocks again.

The default code is Shave and a Hair Cut but if that’s too obvious you can enter a new knock sequence by holding down the red button and knocking your new secret knock (up to 20 knocks).  The rhythm of your favorite song, Morse code, whatever!  The widget will play back your knock (by blinking the lights) so you can be sure it heard everything correctly.

The whole thing is attached to the door with suction cups

The components are simple, most of the work is done in the microcontroller.  The source code for the Arduino is available at the bottom of the page if you’re curious.

How does it work?

First it records the time between knocks.  If there is a long wait for a knock it stops listening and starts analyzing.

Basic circuity

Basic circuity

First it checks the number of knocks.  If that’s right, we go on to more vigorous authentication.   First it converts the absolute timing of the knocks to the rhythm of the knocks.  This lets us knock fast or slow and as long as we get the rhythm right it will unlock.  That way I can still unlock the door if I’m tired or full of caffeine.  After this it compares the timing with the secret key and if any individual knock is off by too much or the whole thing is off by a certain average amount the door stays locked.  If not, we trigger the motor to turn and the lock to unlock.  If the programming button is pressed it saves the rhythm information and then plays it back.

The detection is surprisingly accurate and can even be dialed up so it’s precise enough  to detect an individual person’s variation on a knock, similar to a Morse coder’s ‘fist‘.  (Though when the verifying is this tight it also triggers false negatives which are annoying.)

To keep things simple (and it’s because it’s what I had available) a motor is attached to the deadbolt using two pieces of spring steel bolted across the D shaft of the motor so that the connection will slip when the lock turns as far as it can. A more precise (and probably durable) way to do it would be to use a servo to turn the lock or have a detector sense when the lock had reached its extent.  Or replace the dead bolt with a solenoid.  Or whatever else you can think of.

Circuit fitting

Circuit fitting

The rest of the electronics are nothing special.  Its so simple that just adding feedback LEDs almost doubled the parts count.  The Arduino has a lot of unused potential on this project.

No proper schematic yet, but there’s a layout and parts list at the bottom of the page. Look for a fully documented Instructable soon.

With some extra electronics (an H-bridge) it would be possible to have the door automatically lock as well as unlock. Other improvements or changes that someone could do:

  • Adding a knob to adjust the sensitivity.
  • Building it into an actual door knocker.
  • Using a more economical microcontroller and enabling a sleep mode for better battery life.
  • Making the whole package small enough to fit inside the door.
  • Storing several knocks so several people can have their own private knocks.
  • Adding a real-time clock and using different knocks for different days of the week or times of day.
  • Listening for door bell presses rather than door knocks.
  • Adding a servo or solenoid powered knocker to provide feedback through the door.  It could then offer a challenge-response security where the door starts a knock sequence and the user has to finish it correctly.
  • Rather than listening for knocks, putting a photoresistor in the peep hole and detecting flashes of light from a pocket flashlight or simply by placing your hand over the peephole. Or an infrared receiver and use special key presses on a remote control.
Knock sensor layout (click for larger view)

Knock sensor layout (click for larger view)

Do I have to point out that this is not a great security measure since overhearing a knock sequence is pretty trivial?  No.  But it’s fun to make and play with.

Here’s my code: If you have trouble with cut and paste below you can download the .pde file here.

  1. /* Detects patterns of knocks and triggers a motor to unlock
  2. it if the pattern is correct.
  3.  
  4. By Steve Hoefer http://grathio.com
  5. Version 0.1.09.10.24
  6. Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0
  7.  
  8. Analog Pin 0: Piezo speaker (connected to ground with 1M pulldown resistor)
  9. Digital Pin 2: Switch to enter a new code.  Short this to enter programming mode.
  10. Digital Pin 3: DC gear reduction motor attached to the lock. (Or a motor controller or
  11. a solenoid or other unlocking mechanisim.)
  12. Digital Pin 4: Green LED.
  13. Digital Pin 5: Red LED.
  14. */
  15.  
  16. // Pin definitions
  17. const int knockSensor = 0;
  18. // Piezo sensor on pin 0.
  19. const int programSwitch = 2;
  20. // If this is high we program a new code.
  21. const int lockMotor = 3;
  22. // Gear motor used to turn the lock.
  23. const int redLED = 4;
  24. // Status LED
  25. const int greenLED = 5;
  26. // Status LED
  27.  
  28. // Tuning constants.
  29. // Could be made vars and hooked to potentiometers for soft configuration, etc.
  30. const int threshold = 4;
  31. // Minimum signal from the piezo to register as a knock
  32. const int rejectValue = 25;
  33. // If an individual knock is off by this percentage of a knock we don’t unlock..
  34. const int averageRejectValue = 15;
  35. // If the average timing of the knocks is off by this percent we don’t unlock.
  36. const int knockFadeTime = 150;
  37. // milliseconds we allow a knock to fade before we listen for another one. (Debounce timer.)
  38. const int lockTurnTime = 450;
  39. // milliseconds that we run the motor to get it to go a half turn.
  40.  
  41. const int maximumKnocks = 20;
  42. // Maximum number of knocks to listen for.
  43. const int knockComplete = 1200;
  44. // Longest time to wait for a knock before we assume that it’s finished.
  45.  
  46. // Variables.
  47. int secretCode[maximumKnocks] = {50, 25, 25, 50, 100, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  48. // Initial setup: "Shave and a Hair Cut, two bits."
  49. int knockReadings[maximumKnocks];
  50. // When someone knocks this array fills with delays between knocks.
  51. int knockSensorValue = 0; // Last reading of the knock sensor.
  52.  
  53. void setup() {
  54. pinMode(knockSensor, OUTPUT);
  55. pinMode(lockMotor, OUTPUT);
  56. pinMode(redLED, OUTPUT);
  57. pinMode(greenLED, OUTPUT);
  58. pinMode(programSwitch, INPUT);
  59.  
  60. //Serial.begin(19200);
  61. // Uncomment the Serial.bla lines for debugging.
  62. //Serial.println("Program start.");  // This line too.
  63.  
  64. digitalWrite(greenLED, HIGH);
  65. // Green LED on, everything is go.
  66. }
  67.  
  68. void loop() {
  69. // Listen for any knock at all.
  70. knockSensorValue = analogRead(knockSensor);
  71. if (knockSensorValue >=threshold){
  72. listenToSecretKnock();
  73.   }
  74. }
  75.  
  76. // Records the timing of knocks.
  77. void listenToSecretKnock(){
  78. //Serial.println("knock starting");    // debug.
  79. int i = 0;
  80. // First lets reset the listening array.
  81. for (i=0;i=threshold){   //got another knock…
  82. //record the delay time.
  83. now=millis();
  84. knockReadings[currentKnockNumber] = now-startTime;
  85. currentKnockNumber ++;   //increment the counter
  86. startTime=now;
  87. // and reset our timer for the next knock
  88. digitalWrite(greenLED, LOW);
  89. delay(knockFadeTime);
  90. // again, a little delay to let the knock decay.
  91. digitalWrite(greenLED, HIGH);
  92. }
  93.  
  94. now=millis();
  95.  
  96. //did we timeout or run out of knocks?
  97. } while ((now-startTime < knockComplete) &amp;&amp; (currentKnockNumber < maximumKnocks));
  98.  
  99. //we’ve got our knock recorded, lets see if it’s valid
  100.  
  101. if (validateKnock() == true){
  102. triggerDoorUnlock();
  103. } else {
  104. //Serial.println("Secret knock failed.");
  105. digitalWrite(greenLED, LOW);
  106. // We didn’t unlock, so blink the red LED as visual feedback.
  107.     for (i=0;i<4;i++){
  108.       digitalWrite(redLED, HIGH);
  109.       delay(100);
  110.       digitalWrite(redLED, LOW);
  111.       delay(100);
  112.     }
  113.     digitalWrite(greenLED, HIGH);
  114.   }
  115. }
  116.  
  117. // Runs the motor (or whatever) to unlock the door.
  118. void triggerDoorUnlock(){
  119. //Serial.println("Door unlocked!");
  120. int i=0;
  121.  
  122. // turn the motor on for a bit.
  123. digitalWrite(lockMotor, HIGH);
  124. digitalWrite(greenLED, HIGH);
  125. // And the green LED too.
  126.  
  127. delay (lockTurnTime);   // Wait a bit.
  128.  
  129. digitalWrite(lockMotor, LOW);  // Turn the motor off.
  130.  
  131. // Blink the green LED a few times for more visual feedback.
  132. for (i=0; i < 5; i++){
  133. digitalWrite(greenLED, LOW);
  134. delay(100);
  135. digitalWrite(greenLED, HIGH);
  136. delay(100);
  137.   }
  138.  
  139. }
  140.  
  141. // Sees if our knock matches the secret.
  142. // returns true if it’s a good knock, false if it’s not.
  143. // todo: break it into smaller functions for readability.
  144. boolean validateKnock(){
  145. int i=0;
  146.  
  147. // simplest check first: Did we get the right number of knocks?
  148. int currentKnockCount = 0;
  149. int secretKnockCount = 0;
  150. int maxKnockInterval = 0;
  151. // We use this later to normalize the times.
  152.  
  153. for (i=0;i 0){
  154. currentKnockCount++;
  155.     }
  156. if (secretCode[i] > 0){  //todo: precalculate this.
  157. secretKnockCount++;
  158.     }
  159.  
  160. if (knockReadings[i] > maxKnockInterval){
  161. // collect normalization data while we’re looping.
  162. maxKnockInterval = knockReadings[i];
  163.     }
  164.   }
  165.  
  166. // If we’re recording a new knock, save the info and get out of here.
  167. if (digitalRead(programSwitch)==HIGH){
  168. for (i=0;i< maximumKnocks ; i++){
  169. digitalWrite(greenLED, LOW);
  170. digitalWrite(redLED, LOW); // only turn it on if there’s a delay
  171. if (secretCode[i] > 0){
  172. delay( map(secretCode[i],0, 100, 0, maxKnockInterval));
  173. // Expand the time back out to what it was.  Roughly.
  174. digitalWrite(greenLED, HIGH);
  175. digitalWrite(redLED, HIGH);
  176.         }
  177. delay(50);
  178.       }
  179. return false;
  180. // We don’t unlock the door when we are recording a new knock.
  181.   }
  182.  
  183. if (currentKnockCount != secretKnockCount){
  184. return false;
  185.   }
  186.  
  187. /*  Now we compare the relative intervals of our knocks, not the absolute time between them.
  188. (ie: if you do the same pattern slow or fast it should still open the door.)
  189. This makes it less picky, which while making it less secure can also make it
  190. less of a pain to use if you’re tempo is a little slow or fast.
  191. */
  192. int totaltimeDifferences=0;
  193. int timeDiff=0;
  194. for (i=0;i rejectValue){ // Individual value too far out of whack
  195. return false;
  196.     }
  197. totaltimeDifferences += timeDiff;
  198.   }
  199. // It can also fail if the whole thing is too inaccurate.
  200. if (totaltimeDifferences/secretKnockCount>averageRejectValue){
  201. return false;
  202.   }
  203.  
  204. return true;
  205.  
  206. }
Share/Bookmark
Silly String Spider

Silly String Spider

Contest Entry by Todd Harrison

I had great fun this Halloween with a silly string shooting spider!  My plan was to use an Arduino micro-controller developer board to control my son’s “Teenage Mutant Ninja Turtle” RC car that already shoots silly string.  I didn’t get the spider to actually squirt the silly string but when you’re looking at a big black spider and something shoots silly string at you from the same direction it scares you just the same.

I was inspired to do this 4 hour marathon build by a blog posting by Eric on www.Instructables.com. Eric created a silly string shooting pumpkin which was so incredible I just had to build a spider for Halloween that did the same.

My major problem was that once I heard about Eric’s pumpkin I only had a day to get the supplies and about 4 hours of free time to wire-up something, code it and get it out in the front yard before the kids started coming for tricks or treats.

Here is a component breakdown of the final prop.

  • The red dot and arrow point to the RC car hiding under a bush.
  • 2) RC car remote control.
  • 3) Relay used by pin 2 on the Arduino to fire the remote control’s silly string button.
  • 4) Arduino board: Duemilanove with ATmega328 Purchased from adafruit.com
  • 5) Small blue servo to yank on the spiders leg: TowerPro SG-50.
  • 6) Two red LEDs for spider eyes. Not on the spider I know, I ran out of dev time
  • 7) Parallax Ping))) sonar sensor, held up with helping hands.
  • 8 ) Big black spider
Silly String Spider Parts

Silly String Spider Parts

I originally wanted the string to shoot from the spider’s behind but I really didn’t have time for that so I hid the RC car in the bushes behind the spider and loaded it with a fresh can of silly string.  All I really had to do was get the Arduino to sense somebody getting to close to the spider’s face and then “POW!” fire the silly string using the car’s remote control.

Just for extra effect I wanted the spider to move using a servo and have red LED eyes that blinked.  I also wanted the blinking and servo movement to ramp up faster and faster as a person got closer. To get this effect I used a Parallax Ping))) sonar sensor to track the approaching prey as well as to calculate an agitation delay.  The agitation delay was used to make the spider look more and more upset as the person got closer. If somebody was at a great distance the LED eyes flashed slow and the spider made slow jerking motions, but as the distance delay multiplier shortened the eyes flash furiously fast and the spider would jerk like mad!  If the trick-or-treater dared get closer the Arduino would fire a relay connected to the remote control and they would get a face full of silly string.

Silly String Spider Board Control

Silly String Spider Board Control

A lot of people did have the nerve to walk up on the spider but in the dark it took them a second to even realize they had just been doused in the face with silly string, but then they would laugh and do it again just for fun.  It only really scared a few that didn’t expect anything or were just standing behind the intended victim who was fortunately to short to get hit.

I didn’t get time to mount the eyes in the spider’s head but the red flashing LEDs on the control board seemed to have the same effect as they would have had if they were on the spider.  They were only needed to get the kids attention in the dark.

Arduino Sketch:

  1. #include
  2. Servo myservo;  // create servo object to control a servo
  3.  
  4. int pingPin = 7; // pin for ping sensor
  5. int stringPin = 2; // pin that will fire the silly string remote
  6. int LED_Eyes_Pin = 11; // pin for the two eyes
  7. int multiplier; // multiplier for delay
  8. int delay_time; // time to delay before next step
  9.  
  10. void setup() {
  11.   pinMode(LED_Eyes_Pin, OUTPUT);
  12.   pinMode(stringPin, OUTPUT);
  13.   myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  14.   Serial.begin(9600);
  15.   digitalWrite(stringPin, LOW);    //make sure this is off so we don’t shoot string
  16. }
  17.  
  18. void loop() {
  19.   ping();
  20.   eyes_and_servo(0,0);
  21.   delay(delay_time);
  22.  
  23.   ping();
  24.   eyes_and_servo(100,255);
  25.   delay(delay_time);
  26. }
  27.  
  28. void eyes_and_servo(int servo_pos, int eye_pulse)
  29. {
  30.   analogWrite(LED_Eyes_Pin, eye_pulse);
  31.   myservo.write(servo_pos);
  32. }
  33.  
  34. void ping()
  35. {  long duration, inches;
  36.  
  37.   // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  38.   // We give a short LOW pulse beforehand to ensure a clean HIGH pulse.
  39.   pinMode(pingPin, OUTPUT);
  40.   digitalWrite(pingPin, LOW);
  41.   delayMicroseconds(2);
  42.   digitalWrite(pingPin, HIGH);
  43.   delayMicroseconds(5);
  44.   digitalWrite(pingPin, LOW);
  45.  
  46.   // The same pin is used to read the signal from the PING))): a HIGH
  47.   // pulse whose duration is the time (in microseconds) from the sending
  48.   // of the ping to the reception of its echo off of an object.
  49.   pinMode(pingPin, INPUT);
  50.   duration = pulseIn(pingPin, HIGH);
  51.   // convert the time into a distance
  52.   inches = microsecondsToInches(duration);
  53.   multiplier = inches/10;
  54.  
  55.   delay_time = inches * multiplier;
  56.  
  57.   if (delay_time > 1000) {delay_time = 500;};
  58.  
  59.   if (delay_time < 300) {
  60.      digitalWrite(stringPin, HIGH);
  61.      delay(500);
  62.      digitalWrite(stringPin, LOW);
  63.      delay(2000);
  64.    };
  65.  
  66.   Serial.print(delay_time);
  67.   Serial.print(” delay time; inches are= “);
  68.   Serial.print(inches);
  69.   Serial.println();
  70. }
  71.  
  72. long microsecondsToInches(long microseconds)
  73. {
  74.   return microseconds / 74 / 2;
  75. }

Project Videos

Share/Bookmark

Halloween Dropping Spider

Halloween Dropping Spider

Contest Entry by Noel Portugal

My Halloween project consisted of a dropping spider triggered by a PIR motion sensor mounted on a Jackolantern. The motion sensor triggered a dropping spider, lights, sounds, low laying fog and finally a tweet with a picture attached.

Setup: It’s all pretty basic. The arduino controlled the PIR motion sensor, the servos for dropping spider reel, Jackolantern LED lights, toy with scary sound, and the X10 CM17A. Then the arduino sent a serial message to the ioBridge serial API telling to GET the URL of my site. Then on my site I had a bash script with a while loop looking for request coming from the ioBridge server, then the script played a sound, grab the picture from a wireless webcam and post it to twitter via twitpic’s API using cURL.

Arduino Halloween Dropping Spider

Arduino Halloween Dropping Spider

Arduino Sketch
Here is the arduino sketch. I used the X10Firecracker and the Servo libraries as well as the PIR sensor example from the arduino playground.

Spider Reel
I end up using an VHS tape as a reel. I had to modify one servo to have continuous rotation. I used this guide to do so. The second servo just did the lift part.

ioBridge Monitor
To establish the arduino-ioBridge serial communication I was planning to use an RF solution, but due to time constraints I had to use a long speaker cable to connect the arduino TX to ioBridge’s Serial Board RX with one wire and the second for GND.

This is the bash script I used to trigger a sound as well as send a twitpic.

  1. #!/bin/bash
  2. booCounter=$1
  3. while true;do
  4. status=`tail -n 1 /private/var/log/apache2/access_log | cut -f 1 -d "-"`
  5. if [ "$status" = "00.00.000.000 " ]
  6. then
  7. echo "Boo" >> /private/var/log/apache2/access_log
  8. afplay /full/path/Halloween/werewolf.mp3
  9. msg="Boo, victim $booCounter just got really scared"
  10. sleep 5
  11. curl -O http://www.mywebcam.com/IMAGE.JPG
  12. curl -F media=@/full/path/Halloween/IMAGE.JPG -F "username=username" -F "password=password" -F
  13. "message=$msg" http://twitpic.com/api/uploadAndPost
  14. let booCounter=booCounter+1
  15. fi
  16. done

I used my mac os x Apache 2 server. I had to give write permissions to the access_log so I could append a bogus line as a “break”.

These are the parts that I used for this project:

Arduino Duemilanove
o Adafruit Protoshield

ioBridge IO-204
o ioBridge Serial Smart Board

x10 Firecracker CM17A
o x10 Transeiver, Appliance and lamp modules

VHS tape
o 2 Futaba S3003 servos
o Nylon rope

Plastic Jackolantern
o Parallax PIR sensor
o 2 red LEDs
+ 2 1K resistors
o Checklane Yada Yada Yada (thanks Erick for the tip http://www.instructables.com/id/Arduino-controlled-Silly-String-shooter/)
+ 1 2N2222 tranisistor
+ 1 10k resistor

Fog Machine
o 125VAC/10A DPDT Plug-In Relay (as a switch combined with x10)
o Styrofoam cooler and dryer hose and Ice to create low laying fog.

Wireless webcam
Lights and accesories
o Incandescent black light, strobe light, black light bulbs.

Project Video:

Share/Bookmark


  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook