Stupid Pet Trick–Swing Winnie the Pooh

Sunny Song
Professor: Marcela Godoy
Project: Swing Winnie the Pooh

 

Description:

When you are passing and do not notice Winnie, it will swing happily, the LEDs will blink and the buzzer will play Ode To Joy. But when you stop your pace and come near Winnie, it will stop as if it is willing to listen and communicate with you.

 

Components:

  • 1 * Breadboard
  • 1 * Arduino Uno
  • 1 * Distance Sensor (100~550cm)
  • 3 * LEDs
  • 1 * RGB LED
  • 4 * 220 ohm Resistors
  • 1 * Buzzer
  • 1 * Micro Servo
  • Jumper Cables (M/M)
  • Jumper Cables (F/M)
  • Components from LEGO and x-RCV Robot
  • A Winnie the Pooh
  • A box

 

Process:

Fist of all, I made five small tests to make sure that every small function could work well.

Test 1: How to free the LEDs from the breadboard?

The first problem I have thought about was how to free the LEDs from the breadboard because I would like to set them around Winnie. My first solution was to using tape to connect LEDs with cables. But soon I found F/M cables in the kit, which met my demand perfectly. I used the example blink code to test whether F/M cables could work and I succeeded.

Test 2: How to use RGB LED?

When I found the F/M cables, I also noticed RGB LED. There was an instruction card of RGB LED in the kit so I learned how to build its circuit. Then I modified the basic blink code (add more outputs) and uploaded it. The RGB LED worked successfully and I decided to use it in this project.

Test 3: How to make Winnie swing?

Since the toy contained a swing, what I needed to do was just to make it act. At first, I wanted to use motor and fan because I have done an interactive fan in recitation 3. However, the fan was so small to create enough wind. I used paper and paperboard to enlarge the flabellum. But it still failed to blow Winnie to swing. Then I changed my idea and used micro servo instead of motor and fan. At this time, my task was to create a mechanical arm. There was no component in the kit to make a mechanical arm so I searched suitable components at home. In the end, I found components from a set of LEGO and the kit of x-RCV Robot (I learned to play it when I was in junior middle school). I built up the mechanical arm and uploaded the example code of servo to it. The mechanical arm worked well.

Test 4: How to change the sounds of the buzzer?

I wanted to use buzzer but I thought its sound was too simple and boring. So I searched online about how to change its sounds. I found an instruction in an arduino forum and I followed it to change the buzzer’s sound into Ode To Joy. (http://www.cnblogs.com/xiaowuyi)

 

Test 5: How to use the Distance Sensor that I have borrowed from IMA studio?

I wanted to use the distance sensor to detect whether people came near the Winnie. Although I have not used this sensor in the recitation before, I considered it was similar to the one I have used. So I clicked the link that the page of recitation 3 contained. I found the instruction of this 100~550cm distance sensor and read it. The circuit was easy to connect but coding needed more time. I used the code that the instruction provided at first. What was new to me in this process was how to add a new file to the library. I downloaded a ZIP file and found the way to add it to the arduino library. Although the code worked successfully, I thought it was too complicated. So I decided to use the sensor code that I have used in recitation 3 at last. Also, since the distance sensor that I used initially could not work well, I changed another distance sensor when I was back to school.

 

Circuit and code:

After five tests, I could build up the whole circuit and write a complete code now. For the circuit part, I simply designed a parallel circuit, in which all LEDs were connected in series in a small circuit. There was no mistake in circuit part. For the code part, I initially just used “if-else” structure and put all codes that I have tested before into a whole. However, due to the “if-else” structure, all small components worked one by one but not at the same time. So I searched online to find solutions. I learned that to make different components worked simultaneously, I should use “scoop” and deliver each component’s code into a separate function. So I added “scoop” to the library and wrote a new code. The circuit worked successfully at this time.

Scene:

Afterwards, it was time to make the scene. I used a box as material. Firstly, I curved one side of the box and created a hole for Winnie to swing. Then I printed several pictures to decorate the white paperboard. Then I fixed Winnie to a fit position. Lastly, I chose the best positions for each component (mechanical arm and LEDs) and fixed them. This step was not very easy because the length of wires set limits to how far could the components be away from the breadboard.

Testing:

After fixed all components, I started testing. The biggest problem was that the sensor was not sensitive so the whole project could not work as ideally as I imagined. Another problem was that the mechanical arm could not make Winnie swing with wide-angles. I modified the code but the effect was not obvious. However, besides these two problems, the pet trick was successful and realized my initial design.

Conclusion:

The mechanical arm, the buzzer and the LEDs could all work well when the distance sensor also worked. So the Winnie would swing when people pass by but stop when people come near. In this project, I have autonomously learned many new knowledge as mentioned above, like adding a new library, using RGB LED, changing the sound of buzzer, using “scoop” and so on. Meanwhile, I also learned how to solve the problems. I met many big and small problems in this process. I solved them because I tried hard to find solutions every time. Internet is a great tool to find out solutions. And I believe that the attitude of working hard to solve the problems is most important.

 

Future Development:

If I can optimize this project in the future, I would like to change a better distance sensor even though I have used two different sensors.  Besides, I also want to redesign the mechanical arm since it is not working very well now. When I showed this project to the professor and fellows, they gave me some advice for the second problem. They suggested me putting a bigger servo above the Winnie and connecting the swing to the servo directly. Another suggestion was that I could combine Winnie with the mechanical arm so they could move together. I think these suggestions are all very practical and I will do better next time.

#include "SCoop.h"
defineTask(Task1);
int sensorValue = 0;
int threshold = 350;
void Task1::setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}
void Task1::loop() {
  sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  if (sensorValue > threshold) {
    digitalWrite(13, HIGH);
  } else {
    digitalWrite(13, LOW);
  }
}

defineTask(Task2);
void Task2::setup() {
  Serial.begin(9600);
  pinMode(12, OUTPUT);
}
void Task2::loop() {
  sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  if (sensorValue > threshold) {
    digitalWrite(12, HIGH);
  } else {
    digitalWrite(12, LOW);
  }
}

defineTask(Task3);
void Task3::setup() {
  Serial.begin(9600);
  pinMode(8, OUTPUT);
}
void Task3::loop() {
  sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  if (sensorValue > threshold) {
    digitalWrite(8, HIGH);
  } else {
    digitalWrite(8, LOW);
  }
}

defineTask(Task4);
void Task4::setup() {
  Serial.begin(9600);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
}
void Task4::loop() {
  sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  if (sensorValue > threshold) {
    digitalWrite(11, HIGH);
    sleep(100);
    digitalWrite(11, LOW);
    sleep(100);
    digitalWrite(10, HIGH);
    sleep(100);
    digitalWrite(10, LOW);
    sleep(100);
    digitalWrite(9, HIGH);
    sleep(100);
    digitalWrite(9, LOW);
    sleep(100);
  } else {
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
  }
}

defineTask(Task5); // credit to http://www.cnblogs.com/xiaowuyi
#define NTD0 -1
#define NTD1 294
#define NTD2 330
#define NTD3 350
#define NTD4 393
#define NTD5 441
#define NTD6 495
#define NTD7 556

#define NTDL1 147
#define NTDL2 165
#define NTDL3 175
#define NTDL4 196
#define NTDL5 221
#define NTDL6 248
#define NTDL7 278

#define NTDH1 589
#define NTDH2 661
#define NTDH3 700
#define NTDH4 786
#define NTDH5 882
#define NTDH6 990
#define NTDH7 112

#define WHOLE 1
#define HALF 0.5
#define QUARTER 0.25
#define EIGHTH 0.25
#define SIXTEENTH 0.625

int tune[] =
{
  NTD3, NTD3, NTD4, NTD5,
  NTD5, NTD4, NTD3, NTD2,
  NTD1, NTD1, NTD2, NTD3,
  NTD3, NTD2, NTD2,
  NTD3, NTD3, NTD4, NTD5,
  NTD5, NTD4, NTD3, NTD2,
  NTD1, NTD1, NTD2, NTD3,
  NTD2, NTD1, NTD1,
  NTD2, NTD2, NTD3, NTD1,
  NTD2, NTD3, NTD4, NTD3, NTD1,
  NTD2, NTD3, NTD4, NTD3, NTD2,
  NTD1, NTD2, NTDL5, NTD0,
  NTD3, NTD3, NTD4, NTD5,
  NTD5, NTD4, NTD3, NTD4, NTD2,
  NTD1, NTD1, NTD2, NTD3,
  NTD2, NTD1, NTD1
};
float durt[] =                 
{
  1, 1, 1, 1,
  1, 1, 1, 1,
  1, 1, 1, 1,
  1 + 0.5, 0.5, 1 + 1,
  1, 1, 1, 1,
  1, 1, 1, 1,
  1, 1, 1, 1,
  1 + 0.5, 0.5, 1 + 1,
  1, 1, 1, 1,
  1, 0.5, 0.5, 1, 1,
  1, 0.5, 0.5, 1, 1,
  1, 1, 1, 1,
  1, 1, 1, 1,
  1, 1, 1, 0.5, 0.5,
  1, 1, 1, 1,
  1 + 0.5, 0.5, 1 + 1,
};
int length;
int tonepin = 6;
void Task5::setup() {
  Serial.begin(9600);
  pinMode(6, OUTPUT);
  length = sizeof(tune) / sizeof(tune[0]);
}
void Task5::loop() {
  sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  if (sensorValue > threshold) {
    for (int x = 0; x < length; x++) {
      tone(tonepin, tune[x]);
      delay(500 * durt[x]);
      noTone(tonepin);
    }
    delay(2000);
  } else {
    noTone(tonepin);
  }
}

defineTask(Task6);
#include <Servo.h>
Servo servo;
int d = 800;
void Task6::setup() {
  Serial.begin(9600);
  pinMode(3, OUTPUT);
  servo.attach(3);
}
void Task6::loop() {
  sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  if (sensorValue > threshold) {
    servo.write(400);
    delay(d);
    servo.write(60);
    delay(d);
  } else {
    servo.write(60);
  }
}


void setup() {
  mySCoop.start();
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(3, OUTPUT);
}

void loop() {
  yield();
}

2 thoughts on “Stupid Pet Trick–Swing Winnie the Pooh

  1. I really like the idea of the mechanism using legos. I made a project in that way one time, you can check it out here:
    https://vimeo.com/31639771

    I think the sensor was not working as you wanted because to get the distance you need to apply a formula: https://www.dfrobot.com/wiki/index.php/SHARP_GP2Y0A41SK0F_IR_ranger_sensor_(4-30cm)_SKU:SEN0143

    or you can also try to find out manually like they do it here:
    https://create.arduino.cc/projecthub/jenniferchen/distance-measuring-sensor-900520

    anyways, I think you did a great job with your whole project, it was not only a circuit and code, the idea of the bear and swing was pretty funny 🙂

Leave a Reply