Blog Home

Creep out guests with an Arduino-controlled teddy bear

Arduino TeamNovember 14th, 2018

Halloween has become something of a hacker holiday, giving creative people the world over a chance to show off their spooky animatronic inventions outside without neighborhood scrutiny. This year, Instructables user “gocivici” created a display inspired by the doll in a rocking chair featured in the movie Annabelle, but decided to use an Arduino-infused teddy bear instead. 

The setup is simple but effective, using an Arduino Nano and solenoid to rock the chair. The bear’s head rotates using another Arduino board—an Uno this time—along with a second solenoid and 3D-printed assembly stuffed inside. Control is accomplished via a small wireless remote, though a motion sensor could also be employed.

Boards:NanoUno
Categories:ArduinoFeatured

4 Responses to “Creep out guests with an Arduino-controlled teddy bear”

  1. majoodi_2015 Says:

    #include
    #include
    #include

    #define TRIG_PIN A4
    #define ECHO_PIN A5
    #define MAX_DISTANCE_POSSIBLE 1000
    #define MAX_SPEED 150 //
    #define MOTORS_CALIBRATION_OFFSET 3
    #define COLL_DIST 20
    #define TURN_DIST COLL_DIST+10
    NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE_POSSIBLE);

    AF_DCMotor leftMotor(4, MOTOR12_8KHZ);
    AF_DCMotor rightMotor(3, MOTOR12_8KHZ);
    Servo neckControllerServoMotor;

    int pos = 0;
    int maxDist = 0;
    int maxAngle = 0;
    int maxRight = 0;
    int maxLeft = 0;
    int maxFront = 0;
    int course = 0;
    int curDist = 0;
    String motorSet = “”;
    int speedSet = 0;

    void setup() {
    neckControllerServoMotor.attach(10);
    neckControllerServoMotor.write(90);
    delay(2000);
    checkPath();
    motorSet = “FORWARD”;
    neckControllerServoMotor.write(90);
    moveForward();
    }

    void loop() {
    checkForward();
    checkPath();
    }

    void checkPath() {
    int curLeft = 0;
    int curFront = 0;
    int curRight = 0;
    int curDist = 0;
    neckControllerServoMotor.write(144);
    delay(120);
    for(pos = 144; pos >= 36; pos-=18)
    {
    neckControllerServoMotor.write(pos);
    delay(90);
    checkForward();
    curDist = readPing();
    if (curDist < COLL_DIST) {
    checkCourse();
    break;
    }
    if (curDist curDist) {maxAngle = pos;}
    if (pos > 90 && curDist > curLeft) { curLeft = curDist;}
    if (pos == 90 && curDist > curFront) {curFront = curDist;}
    if (pos curRight) {curRight = curDist;}
    }
    maxLeft = curLeft;
    maxRight = curRight;
    maxFront = curFront;
    }

    void setCourse() {
    if (maxAngle 90) {turnLeft();}
    maxLeft = 0;
    maxRight = 0;
    maxFront = 0;
    }

    void checkCourse() {
    moveBackward();
    delay(500);
    moveStop();
    setCourse();
    }

    void changePath() {
    if (pos 90) {lookRight();}
    }

    int readPing() {
    delay(70);
    unsigned int uS = sonar.ping();
    int cm = uS/US_ROUNDTRIP_CM;
    return cm;
    }

    void checkForward() { if (motorSet==”FORWARD”) {leftMotor.run(FORWARD); rightMotor.run(FORWARD); } }

    void checkBackward() { if (motorSet==”BACKWARD”) {leftMotor.run(BACKWARD); rightMotor.run(BACKWARD); } }

    void moveStop() {leftMotor.run(RELEASE); rightMotor.run(RELEASE);}

    void moveForward() {
    motorSet = “FORWARD”;
    leftMotor.run(FORWARD);
    rightMotor.run(FORWARD);
    for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2)
    {
    leftMotor.setSpeed(speedSet+MOTORS_CALIBRATION_OFFSET);
    rightMotor.setSpeed(speedSet);
    delay(5);
    }
    }

    void moveBackward() {
    motorSet = "BACKWARD";
    leftMotor.run(BACKWARD);
    rightMotor.run(BACKWARD);
    for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2)
    {
    leftMotor.setSpeed(speedSet+MOTORS_CALIBRATION_OFFSET);
    rightMotor.setSpeed(speedSet);
    delay(5);
    }
    }

    void turnRight() {
    motorSet = "RIGHT";
    leftMotor.run(FORWARD);
    rightMotor.run(BACKWARD);
    delay(400);
    motorSet = "FORWARD";
    leftMotor.run(FORWARD);
    rightMotor.run(FORWARD);
    }

    void turnLeft() {
    motorSet = "LEFT";
    leftMotor.run(BACKWARD);
    rightMotor.run(FORWARD);
    delay(400);
    motorSet = "FORWARD";
    leftMotor.run(FORWARD);
    rightMotor.run(FORWARD);
    }

    void lookRight() {rightMotor.run(BACKWARD); delay(400); rightMotor.run(FORWARD);}
    void lookLeft() {leftMotor.run(BACKWARD); delay(400); leftMotor.run(FORWARD);}

  2. majoodi_2015 Says:

    sketch_nov19a.ino:1:9: error: #include expects “FILENAME” or
    sketch_nov19a.ino:2:10: error: #include expects “FILENAME” or
    sketch_nov19a.ino:3:11: error: #include expects “FILENAME” or
    sketch_nov19a:26: error: stray ‘\’ in program
    sketch_nov19a:26: error: stray ‘\’ in program
    sketch_nov19a:34: error: stray ‘\’ in program
    sketch_nov19a:34: error: stray ‘\’ in program
    sketch_nov19a:96: error: stray ‘\’ in program
    sketch_nov19a:96: error: stray ‘\’ in program
    sketch_nov19a:98: error: stray ‘\’ in program
    sketch_nov19a:98: error: stray ‘\’ in program
    sketch_nov19a:103: error: stray ‘\’ in program
    sketch_nov19a:103: error: stray ‘\’ in program
    sketch_nov19a:12: error: ‘NewPing’ does not name a type
    sketch_nov19a:14: error: ‘AF_DCMotor’ does not name a type
    sketch_nov19a:15: error: ‘AF_DCMotor’ does not name a type
    sketch_nov19a:16: error: ‘Servo’ does not name a type
    sketch_nov19a:26: error: ‘u201c’ was not declared in this scope
    sketch_nov19a:26: error: expected ‘,’ or ‘;’ before ‘u201d’
    sketch_nov19a.ino: In function ‘void setup()’:
    sketch_nov19a:30: error: ‘neckControllerServoMotor’ was not declared in this scope
    sketch_nov19a:34: error: ‘u201cFORWARD’ was not declared in this scope
    sketch_nov19a:34: error: expected `;’ before ‘u201d’
    sketch_nov19a.ino: In function ‘void checkPath()’:
    sketch_nov19a:49: error: ‘neckControllerServoMotor’ was not declared in this scope
    sketch_nov19a:61: error: expected `)’ before ‘curDist’
    sketch_nov19a:64: error: expected `)’ before ‘curRight’
    sketch_nov19a.ino: In function ‘void setCourse()’:
    sketch_nov19a:72: error: expected `)’ before numeric constant
    sketch_nov19a.ino: In function ‘void changePath()’:
    sketch_nov19a:86: error: expected `)’ before numeric constant
    sketch_nov19a.ino: In function ‘int readPing()’:
    sketch_nov19a:91: error: ‘sonar’ was not declared in this scope
    sketch_nov19a:92: error: ‘US_ROUNDTRIP_CM’ was not declared in this scope
    sketch_nov19a.ino: In function ‘void checkForward()’:
    sketch_nov19a:96: error: ‘u201dFORWARD’ was not declared in this scope
    sketch_nov19a:96: error: expected `)’ before ‘u201d’
    sketch_nov19a:96: error: ‘leftMotor’ was not declared in this scope
    sketch_nov19a:96: error: ‘FORWARD’ was not declared in this scope
    sketch_nov19a:96: error: ‘rightMotor’ was not declared in this scope
    sketch_nov19a.ino: In function ‘void checkBackward()’:
    sketch_nov19a:98: error: ‘u201dBACKWARD’ was not declared in this scope
    sketch_nov19a:98: error: expected `)’ before ‘u201d’
    sketch_nov19a:98: error: ‘leftMotor’ was not declared in this scope
    sketch_nov19a:98: error: ‘BACKWARD’ was not declared in this scope
    sketch_nov19a:98: error: ‘rightMotor’ was not declared in this scope
    sketch_nov19a.ino: In function ‘void moveStop()’:
    sketch_nov19a:100: error: ‘leftMotor’ was not declared in this scope
    sketch_nov19a:100: error: ‘RELEASE’ was not declared in this scope
    sketch_nov19a:100: error: ‘rightMotor’ was not declared in this scope
    sketch_nov19a.ino: In function ‘void moveForward()’:
    sketch_nov19a:103: error: ‘u201cFORWARD’ was not declared in this scope
    sketch_nov19a:103: error: expected `;’ before ‘u201d’
    sketch_nov19a:104: error: ‘leftMotor’ was not declared in this scope
    sketch_nov19a:104: error: ‘FORWARD’ was not declared in this scope
    sketch_nov19a:105: error: ‘rightMotor’ was not declared in this scope
    sketch_nov19a.ino: In function ‘void moveBackward()’:
    sketch_nov19a:116: error: ‘leftMotor’ was not declared in this scope
    sketch_nov19a:116: error: ‘BACKWARD’ was not declared in this scope
    sketch_nov19a:117: error: ‘rightMotor’ was not declared in this scope
    sketch_nov19a.ino: In function ‘void turnRight()’:
    sketch_nov19a:128: error: ‘leftMotor’ was not declared in this scope
    sketch_nov19a:128: error: ‘FORWARD’ was not declared in this scope
    sketch_nov19a:129: error: ‘rightMotor’ was not declared in this scope
    sketch_nov19a:129: error: ‘BACKWARD’ was not declared in this scope
    sketch_nov19a.ino: In function ‘void turnLeft()’:
    sketch_nov19a:138: error: ‘leftMotor’ was not declared in this scope
    sketch_nov19a:138: error: ‘BACKWARD’ was not declared in this scope
    sketch_nov19a:139: error: ‘rightMotor’ was not declared in this scope
    sketch_nov19a:139: error: ‘FORWARD’ was not declared in this scope
    sketch_nov19a.ino: In function ‘void lookRight()’:
    sketch_nov19a:146: error: ‘rightMotor’ was not declared in this scope
    sketch_nov19a:146: error: ‘BACKWARD’ was not declared in this scope
    sketch_nov19a:146: error: ‘FORWARD’ was not declared in this scope
    sketch_nov19a.ino: In function ‘void lookLeft()’:
    sketch_nov19a:147: error: ‘leftMotor’ was not declared in this scope
    sketch_nov19a:147: error: ‘BACKWARD’ was not declared in this scope
    sketch_nov19a:147: error: ‘FORWARD’ was not declared in this scope

  3. prolifichr Says:

    Awesome simply

  4. hackboi Says:

    man that is amazing thanks for the code
    Ill try it my self!!

Leave a Reply

You must be logged in with your Arduino account to post a comment.