Phase 0 of the IPON Project

by Natalia Fargasch Norman

in IPON

IPON circuit with diffused RGB LED

On my last post I introduced the IPON project, and today I’m sharing the implementation of Phase 0 of this project. (You may want to refer to the previous post if you haven’t yet read it, as this post will probably make much more sense if you know what the IPON project is about).

In Phase 0 I have the complete circuit and sketch that make up Phase 1, except the circuit is not yet implanted in the plush object. It’s just a rough prototype to make sure things work before I go about murdering cutting up a dear plush companion.

Want to skip straight to materials and code? Jump to bill of materials | Jump to Arduino sketch

Input and Output

The sensors and actuators used with the plush object so far are:

Input:

  • LDR (light dependent resistor/light sensor)
  • Tilt switch/sensor
  • Sound sensor (piezo element)
  • FSR (force sensitive resistor/force sensor)

Output:

Here’s a picture of the complete circuit setup:

IPON circuit wiring

Behavior

The behavior of the plush object at this point is as follows (I may change this in the future to make things more interesting).

  • If noise is detected, the plush object’s eyes will blink red. That is, if activity is detected on the piezo element, the LEDs will blink red.
  • If it turns dark, the eyes will blink alternating two colors, I chose aqua and pink. That is, if thelight sensor records a value that implies it is dark (it needs to be calibrated, see the sketch for the test code), the LEDs will blink alternating between aqua and pink.
  • If the plush object is turned upside down, the eyes will blink purple, and a sound scale is played (sort of a complaint from the plush object)… That is, if the tilt switch is engaged (mercury touching the contacts), the LEDs will blink purple and the speaker will play certain tones for a certain duration.
  • If its nose is squeezed, the plush object will shake, and then play some random sounds (a more enthusiastic complaint)… That is, if theforce sensor is pressed, thevibrating motor is activated, and then the speaker will play random tones for a certain duration.

Component wiring

The components are wired as the Fritzing diagram below shows:

Identified Plush Object Network Fritzing

Input components:

  • LDR: one lead to VCC other to Arduino pin using pull-down resistor (10K Ohm)
  • Tilt switch: one lead to VCC other to Arduino pin using pull-down resistor (10K Ohm)
  • Sound sensor: positive to VCC, negative to GND, signal to Arduino pin using pull-up resistor (10K Ohm)
  • FSR: one lead to VCC other to Arduino pin using pull-down resistor (10K Ohm)

Output components:

Lilypad vibeboard schematic

  • 2 RGB LEDs: common cathode lead to GND, R, G and B leads to Arduino pins, but check the datasheet to see if your LED is common cathode or common anode, if the latter, common anode lead to VCC (R resistor: 150 Ohm, G and B resistors: 100 Ohm)
  • Speaker: negative lead to GND, positive lead to Arduino pin
  • Vibrating motor: connected according to Lilypad vibeboard datasheet, see picture to the right (diode: 1N4001; resistor: 33 Ohm).

I soldered all the components to longer wires to make it easy for implantation later. When doing so I cover the connections withheat shring tubing for insulation. Here are close up pictures of such connections.

Note that I also soldered the resistors straight to the LED wires. (Make sure you have the correct lead for the correct resistor value, i.e. 150 Ohm to Red lead, and 100 Ohm to Green and Blue leads).

LED heatshrink

LED resistors heatshrink

LDR heatshrink

Sound sensor heatshrink

Vibrating motor heatshrink

Bill of materials

Video

Here’s a video of Phase 0 of the IPON project in action:

Sketch

/* www.TinkerHobby.com
 * Natalia Fargasch Norman
 * IPON project Phase 0 using Arduino
 */

// Arduino pins
#define RED 3
#define GRN 6
#define BLU 5
#define SPKR 2
#define LDR A0
#define MIC A1
#define TILT 9
#define FSR 10
#define VIBE 11

// pin setup
void setup() {
  Serial.begin(9600);
  pinMode(RED, OUTPUT);
  pinMode(GRN, OUTPUT);
  pinMode(BLU, OUTPUT);
  pinMode(SPKR, OUTPUT);
  pinMode(LDR, INPUT);
  pinMode(MIC, INPUT);
  pinMode(TILT, INPUT);
  pinMode(FSR, INPUT);
  pinMode(VIBE, OUTPUT);
}

void loop() {
//  ledTest();
//  ldrTest();
//  tiltTest();
//  micTest();
//  fsrTest();
//  vibeTest();
//  spkrTest();
  behavior();
}

/*
 * B E H A V I O R
 */
void behavior() {

  // if noise or vibration detected, eyes blink red 5 times
  if ((analogRead(MIC) < 1020)) {
    for (int i=0; i<5; i++) {
      digitalWrite(RED, HIGH);
      digitalWrite(GRN, LOW);
      digitalWrite(BLU, LOW);

      delay(300);

      digitalWrite(RED, LOW);

      delay(200);
    }
  }

  // if turned upside-down, eyes blink purple 5 times and play scale
  if (digitalRead(TILT)) {
    for (int i=0; i<5; i++) {
      analogWrite(RED, 185);
      analogWrite(GRN, 26);
      analogWrite(BLU, 139);
      delay(300);

      digitalWrite(RED, LOW);
      digitalWrite(GRN, LOW);
      digitalWrite(BLU, LOW);
      delay(200);
    }

    for (int i=100; i>=5; i--) {
      playTone(i*i, 50);
    }
    delay(50);
  }

  // if nose pressed, shake and play random sounds
  if (digitalRead(FSR)) {
    digitalWrite(VIBE, HIGH);
    delay(2000);
    digitalWrite(VIBE, LOW);

    spkrTest();
  }

  // if dark, eyes blink from aqua to magenta 5 times
  if (analogRead(LDR) < 300) {
    for (int i=0; i<5; i++) {

      analogWrite(RED, 0);
      analogWrite(GRN, 255);
      analogWrite(BLU, 255);
      delay(300);

      analogWrite(RED, 255);
      analogWrite(GRN, 0);
      analogWrite(BLU, 255);
      delay(300);
    }
    digitalWrite(RED, LOW);
    digitalWrite(GRN, LOW);
    digitalWrite(BLU, LOW);
    delay(50);
  }

}

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(SPKR, HIGH);
    delayMicroseconds(tone);
    digitalWrite(SPKR, LOW);
    delayMicroseconds(tone);
  }
}

void ledTest() { // common anode x common cathode, lead colors
  Serial.println("Red");
  digitalWrite(RED, HIGH);
  digitalWrite(GRN, LOW);
  digitalWrite(BLU, LOW);
  delay(2500);
  digitalWrite(RED, LOW);

  Serial.println("Green");
  digitalWrite(RED, LOW);
  digitalWrite(GRN, HIGH);
  digitalWrite(BLU, LOW);
  delay(2500);
  digitalWrite(GRN, LOW);

  Serial.println("Blue");
  digitalWrite(RED, LOW);
  digitalWrite(GRN, LOW);
  digitalWrite(BLU, HIGH);
  delay(2500);
  digitalWrite(BLU, LOW);
}

void ldrTest() { // dark when reading < 300'ish
  Serial.print("Photocell reading = ");
  Serial.println(analogRead(LDR));
  delay(500);
}

void tiltTest() { // 1 when mercury touching/upside down
  Serial.print("Tilt status: ");
  Serial.println(digitalRead(TILT));
  delay(1000);
}

void micTest() { // < 1023 when noise/vibration detected (1023 = silence)
  Serial.print("Mic reading = ");
  Serial.println(analogRead(MIC));
  delay(100);
}

void fsrTest() {
  Serial.print("Force status: ");
  Serial.println(digitalRead(FSR));
  delay(500);
}

void vibeTest() {
  Serial.println("Vibrate!");
  digitalWrite(VIBE, HIGH);
  delay(1000);
  digitalWrite(VIBE, LOW);
  delay(2000);
}

void spkrTest() {
  Serial.println("Random sounds...");
  long k = 0;
  for (int i=5; i<100; i++) {
    k = random(5, 100);
    playTone(k*k, 75);
  }
}
Digiprove sealCopyright secured by Digiprove © 2014 Natalia Fargasch Norman

{ 8 comments… read them below or add one }

annie andre

Natalia,

Loved that you listed out the bill of materials. I was wondering what the level of difficulty was and how long it might take someone and total cost for this project was.. Just curious but maybe some others might be interested too?

Reply

Natalia

Thanks Annie, I always list the materials on every project post, but usually do not include the information you inquired about. Difficulty is always easy here on my blog, and the cost can vary, depending on what you already have on hand. For me the cost was $0, but for this project it can be up to $50 if you don’t have any of the items (Which I think would be a rare case). For most hobbyist probably between $15 and $20, depending on the items they need to buy to complete the project. That’s why I always include the complete list, as these items may vary for each person.

Reply

annie andre

Thanks Natalia. that makes sense that the cost might vary. DUH!!! what was i thinking?
ps loved the added video. Makes the whole project come to life. I had an idea for a future video. video tape a prject from start to finish and speed it up really fast. I saw it once on some other hobbyist site i can’t remember where but i liked it..

Reply

Natalia

That’s a great video idea! I don’t do my projects in one sitting, but that’s what video editing is for, right? :-)

Reply

Brian J Hoskins

Love the project! Keep the updates coming!

By the way, I like your code box. I’ve been looking into ways of inserting code snippets into posts on my website (I’ve only just set my site up so there’s no electronic stuff there yet) but I haven’t found anything that I’m satisfied with yet. What are you using to do yours?

Reply

Natalia

Thanks Brian!

As for the code, I generate the pre-formatted code with the Arduino IDE (it inserts the color hightlighting) then I wrap it inside a “div” tag:
div style=”width: 550px; height: 500px; overflow: auto; padding: 5px; border: 1px solid #CCCCCC;”

Reply

Ryan Coupe

Hi, this looks fantastic. I’m looking to do something a little less complex but I am hoping that you will be able to help.

I’m looking to create a stress ball lamp with RGB LEDs with the FSR. So the harder you squeeze the ball the colour of the LED will change. How would I change around the code you have above to do this, im a newbie at coding so any tips would be great.

Many thanks

Reply

Natalia

Hi Ryan,

you will map the analog input to your PWM pins output, remember that the input will be 0-1023 and the PWM output 0-254. I love your idea, I just am not sure how the FSR would work with squeezing, at it responds to force applied directly to it. Let me know how it works!

Reply

Leave a Comment

{ 1 trackback }

Previous post:

Next post: