Making Things Interactive

May 9, 2008

Interactive Hovercraft

Filed under: Will Not Count Towards Your Grade — lingshui @ 9:33 pm

This hovercraft project is a hovercraft made of balsa wood and garbage bags, powered by a single computer fan. The hovercraft works by building up air pressure underneath the frame and then forcing the air out from the sides, thus creating a cushion of air for the hovercraft to sit on. This hovercraft is also interactive in that it activates the hover ability when it senses human presence (through the use of an ultrasonic rangefinder). Additionally, since the hovercraft is meant to be eventually developed into a hovering interactive pet of some kind, I have integrated the beginnings of a “personality” for the pet in that the hovercraft gets “mad” and lets out an annoying noise when it is bumped too hard against any surface laterally.

Pictures:

#1

#2

#3

Schematic:

Here

Code:

int RF = 5; //set rangefinder to analog 5
int bumpSwitch = 2; //switch for “bump” reaction to digital 2
int trans = 6; //transistor for fan activation to digital 6
int buzzer = 8; //buzzer for “bump” reaction to digital 8
const int sWait = 0; //setting state machine ints
const int sHover = 1;
int currentState = sWait;
int nextState = sHover;
int timeDelay = 0; //set amount for idle turnoff of fan
int led1 = 3; //set output status lights on hovercraft
int led2 = 4;
int ledCount = 0;

void setup()
{
pinMode (RF, INPUT); //setting inputs and outputs
pinMode (bumpSwitch, INPUT);
pinMode (trans, OUTPUT);
pinMode (buzzer, OUTPUT);
pinMode (led1, OUTPUT);
pinMode (led2, OUTPUT);
Serial.begin (9600);
currentState = sWait;
}

void loop()
{
switch (currentState) //state machine for hovercraft states
{
case sWait: //state “waiting for interaction”
digitalWrite (trans, LOW);
timeDelay = 0;
digitalWrite (led1, LOW);
digitalWrite (led2, LOW);
Serial.println (“Wait”);
if (analogRead(RF) <= 15) //if rangefinder detects human proximity... { currentState = sHover; //turn hover on } break; case sHover: //state "hovering" digitalWrite (trans, HIGH); //turn on fan digitalRead (bumpSwitch); if (ledCount < 25) //begin script for led flash pattern to cut out delay lag { digitalWrite (led1, HIGH); digitalWrite (led2, LOW); } if (ledCount == 25) { digitalWrite (led1, LOW); digitalWrite (led2, HIGH); } if (ledCount == 50) { ledCount = 0; } //end script for led flash pattern Serial.println ("Hover"); if (digitalRead(bumpSwitch) == HIGH) //if the hovercraft is bumped... { digitalWrite (buzzer, HIGH); //initiate buzzer and angry led pattern digitalWrite (led1, HIGH); digitalWrite (led2, HIGH); delay(100); digitalWrite (led1, LOW); digitalWrite (led2, LOW); delay(100); digitalWrite (led1, HIGH); digitalWrite (led2, HIGH); delay(100); digitalWrite (led1, LOW); digitalWrite (led2, LOW); delay(100); digitalWrite (led1, HIGH); digitalWrite (led2, HIGH); delay(100); digitalWrite (led1, LOW); digitalWrite (led2, LOW); delay(100); digitalWrite (led1, HIGH); digitalWrite (led2, HIGH); delay(100); digitalWrite (led1, LOW); digitalWrite (led2, LOW); delay(100); digitalWrite (led1, HIGH); digitalWrite (led2, HIGH); delay(100); digitalWrite (led1, LOW); digitalWrite (led2, LOW); delay(100); digitalWrite (led1, HIGH); digitalWrite (led2, HIGH); delay(100); digitalWrite (led1, LOW); digitalWrite (led2, LOW); delay(100); digitalWrite (led1, HIGH); digitalWrite (led2, HIGH); delay(100); digitalWrite (led1, LOW); digitalWrite (led2, LOW); delay(100); digitalWrite (led1, HIGH); digitalWrite (led2, HIGH); delay(100); digitalWrite (led1, LOW); digitalWrite (led2, LOW); delay(100); digitalWrite (led1, HIGH); digitalWrite (led2, HIGH); delay(100); digitalWrite (led1, LOW); digitalWrite (led2, LOW); delay(100); digitalWrite (led1, HIGH); digitalWrite (led2, HIGH); delay(100); digitalWrite (led1, LOW); digitalWrite (led2, LOW); delay(100); digitalWrite (buzzer, LOW); } timeDelay ++; //increment idle count ledCount ++; //increment led flash pattern count delay (10); if (timeDelay == 1700) //if idle count reaches 17 seconds... { currentState = sWait; //go back to waiting for interaction state } break; default: //default state, error, go back to waiting state Serial.println ("default state, ERROR"); currentState = sWait; break; } } [/sourcecode] The code for the hovercraft is a simple state machine with two states: waiting and hover. Hover state includes all script for flashing LEDs and "angry response" behavior. There was a problem with flashing the LEDs during the hover state while still reading the "bump switch" (because of delay command in led flash script it would stop reading bump switch during the delay). Thus I created a simple counting increment script for the bumpswitch which is outlined in the comments inside the "hover" state.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: