Posts | Comments

Planet Arduino

Archive for the ‘Contest Entries’ Category

Lil Herbert - Beginner Robot

Lil Herbert - Beginner Robot

Contest entry by Annie (note: was submitted within the deadline, I wasn’t able to add to the blog until today)

In September of 2009 I found myself in a learning mood.  Throughout my life I have been fascinated by everything: science, math, history…you name it, I love to know about it.  In September I decided I was going to brush up on my electronics knowledge and see where it would take me.  I had studied electronics at a tech school during the 90s and I’d grown up in Silicon Valley so I wasn’t completely new to the endeavor.  But upon graduation from the tech program I immediately began working on computer network support and Key System/PBX telephone system programming rather than the nitty gritty world of capacitors, resistors and ICs and found my understanding of it all both fading and lacking.

As I practiced building little 555 timer and 386 audio amplifier circuits, I soaked in as much information as I could from forums and online electronics articles.  It was then that I began hearing   about something called Arduino.  Arduino?  What, pray tell, is an Arduino?

A pizza, perhaps?  As in “I’ll have a large pepperoni and Arduino with extra cheese!”  No, that wasn’t it.  Arduino…hmmmm.

A new Italian sports car?  “The new 2010 Arduino Coupe, 0 to 60 in 200 microseconds” (Of course with a little disclaimer at the bottom explaining that the Arduino driver is a pro, so kiddies, don’t try this at home!).  Well, that wasn’t it either.

A quick search of Wikipedia and then Amazon was my road to Damascus. I had found a microcontroller that was cheap, extremely easy to learn, a massive open-source community to hold my hand as I dipped my pinky toe into the microcontroller waters, and a seemingly unending variety of applications and add-ons.  By October 9th I had my first Arduino.  A Duemilanove.  It was (and still is) a thing of beauty in my eyes.

After a week of the usual “Hello World” blinking LED type projects, I decided I needed a long term project to build upon and to hone my skills.  Thus, Herbert was born.

Herbert started out with a discussion I had with my mom.  I was thinking of  some goals to set to help me learn all of the different aspects of micro-controller use.  I wanted to learn to write code.  I wanted to continue my work designing and building circuits.  I wanted to practice my soldering skills.  A robot project was the answer!

The goals for Herbert were these:

  • Start from scratch.  To really understand the workings of Herbert I needed to build him from the ground up, no ready-made kits.
  • Have the Arduino control his movement; he must start out with simple forward, backward and turning motions autonomously.
  • Add sensors to let Herbert see the world.  His first sensor is a Parallax Ping ultrasonic sensor, but eventually he will have many different types.
  • Through code of my own creation, have Herbert avoid collisions by turning, stopping or reversing.  I felt it was important for my educational development to create my own code rather than borrow someone else’s.  I have seen some fancy avoidance programming out there that I admire greatly.  But I knew if I didn’t start from scratch I would miss out on the joys of failure.

Have Herbert be a long range project.  I decided that he could be open ended.  As I solve one set of obstacles, I can move on and add new features.  Someday Herbert will talk, tell me the weather, read me my email and play songs off my computer for me.  It’s all just one step at a time.

The Basics

Robot Chassis

Robot Chassis

I started building in late October.  I received an early Christmas present in the form of 4 motors, 4 wheels and a chassis.  I decided to focus on a pulse width modulation circuit design to control the  independent speed of each motor.  After much studying on the web,   I built a circuit with 4 Darlington transistors to control the current   through the motors with the Arduino pins controlling the current  through each motor.  In addition, I added 4 reversed biased diodes to      protect the Arduino pins from kick-back voltage.

Schematic

Schematic

This circuit worked great for my first foray across the living room floor.  I could change the motor speed by changing the PWM in the Arduino sketch and soon I had Herbert zipping around scaring the dogs.  I decided it was time to give him some ‘eyes’.  While shopping for parts at Radio Shack one day I stumbled upon the Parallax Ping))) Sensor.  It is an ultrasonic sensor that was perfect for what I was doing.  With only a 5v, Gnd and Signal pin, I knew I could get it up and running with the Arduino!

I modified my code and put the signal for the Ping sensor on pin 9 of the Arduino.  I attached the 5v and Gnd of the sensor to the respective spots on the Duemilanove.  At this point I broke from my stated goal of always writing my own code.  The truth is, I had not the slightest idea how to write my own functions at this point, let alone libraries.  Luckily, the Arduino IDE saved the day!  In Files-Examples-Sensors there is a sketch for the Parallax Ping))) sensor.

After testing the sensor on a breadboard, I wired it up on Herbert.  I then took the important parts of the Ping))) sketch and added them to my current working sketch.  Herbert saw the light and was on the move!  I had him driving forward, detecting objects in front of him and turning to avoid them.  Granted, my code needed polishing but it was a start!

At this point my goal was to have Herbert move forward.  If he detected an obstacle he would stop and sweep his ping sensor to the left and take a measurement.  Then he would swing the sensor to the right and take another measurement.  He would then compare the two to decide which was a clearer path.  I wrote the sketch and it worked….once.  Somehow I had run into my first major bug and I was at a loss to figure it out.  Herbert was acting strange, not responding correctly and dancing around like a madman.

With little time before the contest deadline and wanting Herbert to make an appearance, I decided the strange problem must’ve been something to do with the cheap wheel motors I had (they had been giving me problems now and again already) and so I quickly ordered  4 Solarbotics GM13a 150:1 mini metal gear motors and tires to match.  They are much smaller than the no-name motors I had been using, but they are quiet and nice!  Herbert became Lil’ Herbert.

I rebuilt Herbert with the new motors and wheels and ran into the same strange behavior.  Obviously the motors weren’t the problem.  I’m sure I now know what it is, and I will experiment after the contest deadline to see if I am right.  I’ve been using an Adafruit Minty Boost to power the Arduino.  It’s a little circuit that converts the 3 volts from 2 AA batteries to 5 volts and sits in an Altoids tin on Herbert’s chassis.  I now believe that having the Arduino power the ping sensor, a sweeping servo and itself is just too much for the Minty Boost, causing strange things to happen.  But, as I was running out of time, I chose to forego the sweeping of the servo until after the deadline.

So, this is where we stand.  Or where Herbert rolls as it were.  I was still using my transistor circuit to power the motors and pinging to avoid collisions.  The main problem with this setup is that the motors’ current could only go one way.  I was able to drive Herbert forward and turn him, but he couldn’t reverse or turn on a dime.  At this time I decided that I knew enough about my transistor circuit/motor setup that I could investigate motor controller boards.  I knew I could build H-Bridge circuits to allow the motors to drive either direction, but I felt the compact nature of some of the control boards I had been looking at would help me keep Herbert compact.

So into the picture came 2 Pololu Qik 2s9v1 Dual Serial Motor Controllers.  They are little, efficient and allowed me to have Herbert go forward or backwards.  I once again sacrificed my vow to write my own code and used a library specifically for these boards.  My only trouble was the code was written for one board only, and I had two.  I fumbled my way through making 2 instances of the library and all was well.

As I write this it is 3:30 PM on December 31, 2009.  I have reached the contest deadline and can do no more.  Herbert can currently sense obstacles in front of him and turn to avoid them.  He can move forward and backward.  Sadly, there was no time to resolve his neck sweep issues in time.  But as Herbert travels around the house in the coming months he will be doing more and doing it more efficiently.  I will keep adding new videos to my You Tube page and Herbert will continue to annoy my dogs.

I have included two versions of Herbert’s sketches in the zipped folder.  One is from the early days of the transistor circuit, and the other is from this very day with the motor controllers.

Herbert’s videos can be seen on my You Tube channel.  The first one, Herbert is Born, was from November.  The most recent is Lil Herbert.

Videos: http://www.youtube.com/profile?user=AnnieNakki#g/u

Share/Bookmark

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
22

Arduino/ioBridge internet controlled Christmas lights and music show (Build It!)

arduino, Christmas Lights, Contest Entries, Internet Controlled Lights, iobridge, LED Commenti disabilitati su Arduino/ioBridge internet controlled Christmas lights and music show (Build It!) 

Internet controlled Christmas lightsArduino Build It! contest entry by: Noel Portugal My xmas-box project consists of an internet controlled Christmas lights and music show. A Christmas song can be requested on-line which is then put in a queue and played in the order it was requested. The music is transmitted on an FM station within a 300 ft radius from my house.

The xmas-box has 8 Channels (power outlets) where different light modes can be played: vu meter style, ascending, descending, split, merge, sequence and random. During each song one of these modes is used randomly every 10 seconds (to make the show less monotonous).I started my research right after Halloween and I came across a couple different options, but I settled with the following combination of hardware : arduino + adafruit wave shield + ioBridge + wifi bridge + solid state relays (SSRs).

The xmas-box is enclosed in a small plastic tool box. I have place it on my deck under a roof ( it is not completely weather proof). The tool box has “3 levels.” The bottom is where all the SSRs and AC wiring are located. The middle (the inside tray) contains the wall warts for the arduino (9v), ioBridge (5v) and Wifi Bridge with power. The top level contains the Arduino board, the ioBridge module and the FM transmitter.

Noel has put together a really great Instructable. Rather than attempt to post all the steps here, the remainder of the project can be found on his Instructable.

Great Job Noel!

As as side note I will like to share how much Arduino has changed my life. I am software guy by trade but I have always wanted to bridge the internet with the real world. When I found out about Arduino I rushed to order one of these amazing boards, and I haven’t been disappointed. The ability to program it using C (with wiring) and the immense documentation and free libraries make it really easy for anyone with little to no experience to get started with physical computing. My head  has been constantly spinning  by all the possibilities that I could prototype with this platform.

I hope that any of my experiences shared by my blog could ever help someone else trying to do similar things.

-Noel

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
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