Group 11-Project 6

Your Own Talking and Loving Teddy Bear

Do you remember what you had as a toy in your childhood? Everyone may have a toy when he was young, and regard them as friends and the most precious memories.Teddy bear should be the most popular plush toy. Children think it’s very cute and fluffy. But normal plush toys do not have the function of interacting with people. Now please imagine what an interesting interactive experience it would be if your teddy bear could achieve more interesting interactions with you? For example, if we greet you through the induction system and have the function of making sounds, will your life be richer? Our project is committed to trying to use the tools and knowledge of Arduino to achieve this idea.

Group Members

NameWork
Jialu GaoDocument blog design
Physical Arduino board test
Humayrah SiddiquePhysical Arduino board test
Coding
Adrian Donald Oluyemi AllenPhysical Arduino board test
Coding

Maker Manual

Components used

  • Arduino Uno
  • RFID-RC522
  • 2xServo
  • 2xRGB LED
  • 6×220 Ohm Resistors
  • Wires
  • 5W Speaker
  • 1x1k Ohm Resistor
  • DFPlayer Mini
  • Micro SD Card

Build section (how you made the physical aspects of your project).

  1. LEDs
    • You will need to use the RGB LEDs, 220 Ohm Resistors and wires
    • Connect the longest wire to either 5V or GND. You will know which one to use by testing the light with generic analogWrite code.
    • Connect the R, G and B wires to analog pins via the 220 Ohm resistors. We have used A0, A1 and A2.
    • Repeat this with the second RGB LED.
  2. Servo
    • You will need to use Servos and wires
    • Connect the yellow, red, and brown wires to the analog pin, 5v, and ground respectively.
  3. RFID
    • You will need the RFID tag reader and wires
    • Connect each wire to the correct pins as shown below:
  4. Speaker
    • You will need the SD Card reader, Speaker, SD Card and wires
    • Make sure you have a formatted SD with two mp3 files on it that are shorter than 5 seconds
    • Insert the SD card into DFPLayer and then connect the speaker to pins ‘spk1’ and ‘spk2’ of the DFPlayer.
    • Connect the resistor to the RX pin of the DFPlayer
    • Connect a wire to the VCC pin of the DFPlayer
    • Connect a wire to GND and another to 5v
  5. Putting it all together
    • We are going to connect everything via the ground and 5v columns on the breadboard. Everything else can go straight to the Arduino Uno controller.
    • Run the code below in your Arduino IDE
//Libraries
#include <Servo.h>
//for RFID 
#include <SPI.h>      
#include <MFRC522.h>
//Speaker
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

//Global Variables
Servo leftFoot;
Servo rightFoot;

String currentUserID= "";
String GOOD_USER = "43 60 A2 19";
String BAD_USER = "53 BD E5 12";
int loggedIn = 0; //neutral 0 friend +1 enem -1

int pause = 500;  //pausing before switching modes

//for RFID
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

//speaker
static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX
static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);

DFRobotDFPlayerMini player;

void setup() {
  setupRFID();
  setupLED();
  setupServo();
  setupSpeaker();
}

void loop() {
  String cardScanned = lookForCards();

  if (cardScanned != "") {
    Serial.println("Card scanned.");

    if(currentUserID==""){
      Serial.println("User not logged in yet.");
      currentUserID=cardScanned; //attempt login
      if(loggedIn == 0){
        Serial.println("Logging in...");
        login();
      }
    }else if(currentUserID==cardScanned){
      logout(); //clears
    }else{
      Serial.println("You cannot switch users until you have logged out.");
    }
  }

  delay(pause);

  if(loggedIn==-1){
    unfriendlyMode();
  }
  else if(loggedIn==1){
    friendlyMode();
  }
  else{
    neutralMode();
  }
} 

void setupRFID(){
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  Serial.println("Approximate your card to the reader...");
  Serial.println();
}

void setupLED(){
  //left eye r,g,b
  pinMode(A0,OUTPUT);
  pinMode(A1,OUTPUT);
  pinMode(A2,OUTPUT);
  //right eye r,g,b
  pinMode(A3,OUTPUT);
  pinMode(A4,OUTPUT);
  pinMode(A5,OUTPUT);
}

void setupServo(){
  //left foot
  leftFoot.attach(6);
  //right foot
  rightFoot.attach(5);
}

void setupSpeaker(){
  Serial.begin(9600);
  softwareSerial.begin(9600);

  if (player.begin(softwareSerial)) {
    player.volume(15);  //0-30
       Serial.println("OK");

   // player.play(1); //play 1 is good, play 2 is bad
  } else {
   // Serial.println("Connecting to DFPlayer Mini failed!");
  }
}

String lookForCards(){
  //Checks if a card is physically present and is a valid RFID tag
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return "";
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return "";
  }

  String temp=""; //active card scanned
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     temp.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     temp.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  temp.toUpperCase();
  return temp;
}

void login(){
  if (currentUserID.substring(1) == GOOD_USER){ //change here the UID of the card/cards that you want to give access
    loggedIn = 1;
    printLogin(currentUserID.substring(1));
  }
  else if(currentUserID.substring(1) == BAD_USER){
    loggedIn = -1;
    printLogin(currentUserID.substring(1));
  }
}

void friendlyMode(){
  colourEyes(0,255,0);
  moveFeet(90,1);
    player.volume(15);

  player.play(2);
}

void unfriendlyMode(){
  colourEyes(255,0,0);
  moveFeet(90,2);
    player.volume(15);
  player.play(1); //lay sad sng
}

void neutralMode(){
  colourEyes(200,0,200);
  moveFeet(0,0);
    player.volume(0);
  //player.play(1); //lay sad sng
}

void logout(){
  Serial.println("You have logged out.");
  loggedIn = 0;
  currentUserID = "";
}

void printLogin(String id){
  Serial.println("You are logged in as "+id+" .");
}
void colourEyes(int r, int g, int b){
  //cathode ver.
  r = 255-r;
  g = 255-g;
  b = 255-b;

  //left eye
  analogWrite(A0,r);
  analogWrite(A1,g);
  analogWrite(A2,b);

  //right eye
  analogWrite(A3,r);
  analogWrite(A4,g);
  analogWrite(A5,b);
}

void moveFeet(int angle, int speed){
  if(angle==0 && speed==0){
    delay(1000);
    return;
  }

  int pos = 0;
  int delayTime = 25;

  for(pos=0; pos<=angle; pos+=speed){
    leftFoot.write(pos);
    rightFoot.write(pos);
    delay(delayTime);
  }

  for(pos=angle;pos>=0;pos-=speed){
    leftFoot.write(pos);
    rightFoot.write(pos);
    delay(delayTime);
  }
}

//int arrayLength(int arr[]){
//  int arrayLength = sizeof(arr)/sizeof(arr[0]);
//  return arrayLength;
//}


How to play:

Wait for the eyes of the bear to turn purple. That is you are ready to log in. Use your card and bring it to the bear’s tummy. After a few seconds, the bear should know that it is you and be happy. Happy music will play, the LEDs will be green, and the feet will dance. If it is not you, they will be angry. An alert sound will be played, the eyes will be red, and the feet will move very fast. Bring your card to the bear’s tummy again to log out. They eyes should go back to purple if it is successful.

Process Going

Project Task List

November 16,2022Meet up and begin discussion about topicAll members
November 18,2022Allocate roles of each peopleAll members
November 21,2022Create group on Teams and GithubHumayrah
November 25,2022Brainstorming and reference togetherAll members
December 5,2022Basic circuitHumayrah
Adrian
December 8,2022Combine breadboard, get 2 RGB led and readerHumayrah
Jialu
December 9,2022Get the sound workingAdrian
December 10,2022LEDS and shift register workingHumayrah
Adrian
December 11,2022Servo workingHumayrah
Jialu
December 12,2022Combining all features All members
December 13,2022Implement on documentJialu for main structure, design and writing
other members also put some info

November 16, 2022. Members meet up and discuss and determine the topic.

project selection

November 18,2022. Allocate roles inside the group and began doing searching.

Research

  • https://www.smythstoys.com/uk/en-gb/toys/fashion-and-dolls/cosmetics/funlockets-secret-diary-journal-glitter-edition/p/208696
  • https://www.argos.co.uk/browse/toys/teddy-bears-and-soft-toys/c:30308/type:interactive-soft-toys/
  • https://www.amazon.co.uk/glow-bear/s?k=glow+bear

November 21,2022. Create groups on Teams and Github. Set all requirements on for all members to check any time.

Example of content discussed on 21/11/2022

November 25, 2022. Brainstorming and posting reference together.

December 5, 2022. Building basic circuits and try to make it work.

December 8, 2022. Combine breadboards.

December 8,2022. Get 2 cathode RGB Led responding to the RFID sensor.

Colour of RGB LED responds to correct and incorrect RFID tags.

December 9,2022. Get the sound working.

Extending the first speaker length to fit the teddy bear.

As two led are the eyes of teddy bear, we need to get tested both of them are working and the system could receive different sign and give different feedback.(Red light for wrong, Green light for correct).

December 10, 2022. Get 2xRGB LEDs to respond to the RFID Tag with the same behaviour.

December 10,2022. Tested for both led represent eyes of the teddy bear working. Try to incorporate shift register.

December 11,2022. Get the servo working and combine them together. Buy the teddy bear.

RFID+Servos+RGB LEDs
Final Prototype

Code Explanation

Explanation of Setup Functions
Explaining the choice of good user / bad user
Explaining the RFID scanner behaviour
The core loop of our program
The behaviours of our teddy bear

Design choices

  • We chose a log in / log out system because we wanted to add non timed functionalities
    • As of now, the teddy bear only wiggles, colours and makes noise. We wanted to add interactable features like pressing one paw to record a message and one paw to play back a message. This would have needed a login/logout system as the teddy bear will need to know when the user is done using it.
    • Arduino also caches lots of information that is hard to wipe. The login/logout system allows a neutral/reset point to clear all the data so no data is overwritten
  • We chose to put the servos in the feet as we thought a foot wiggling motion would be cute and display its emotion (anxious- fast, calm- slow).

Shortcomings

  • Speaker may bug – loudness can reset and .mp3 can be cut short.
  • Teddy bear cannot move very far – it depends on the length of the soldered wires
  • LEDs can be hard to work with – very often the eyes are wonky
  • Reactions are simple right now – we can add more complex behaviours
  • There is only 1 good user and 1 bad user, we can change this in the future