Projects / Talking robot toy

Talking robot toy

Beginner2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANOKY038

    Test the sound sensor

    Print readings and clap.

  2. NANO

    Test the IR sensor

    Wave a hand in front.

  3. NANO

    Test the player

    Play each phrase.

  4. NANO59°

    Move the head

    Sweep the servo.

  5. NANO

    Join them

    Clap or wave to speak.

  6. NANO

    Add sleep

    Rest after a minute.

  7. NANOSANDIS

    Decorate

    Build a cardboard robot around it.

In short

How do you build a talking robot toy?

A cardboard robot that turns its head with a servo and says things when you clap or wave. You need Arduino Nano, SG90 Micro Servo, Sound sensor module (KY-038), IR obstacle avoidance sensor module, DFPlayer Mini MP3 module, Speaker 8 Ω 0.5 W, SanDisk microSD card 32 GB (A1, Class 10), Battery holder 4 × AA with switch, AA alkaline battery × 4 and Resistor 1 kΩ. It takes 7 steps and about 120 minutes.

Level
Beginner
Time
About 120 min
Parts
10

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Sound module VCC and GNDNano 5V and GNDPower
Sound module AONano A0Loudness reading
IR module VCC and GNDNano 5V and GNDPower
IR module OUTNano D2Wave detect (LOW when something is near)
Servo signalNano D9Head turn
Servo plus and minus4 AA pack plus and minusServo power
DFPlayer TXNano D10Replies
DFPlayer RXNano D11 through a 1 kΩ resistorCommands
DFPlayer SPK1 and SPK2SpeakerVoice
4 AA packNano VIN and GND; DFPlayer VCC to Nano 5VPower

Code

The robot listens for a clap with the sound sensor, which is compared with the room's normal level taken at start-up, and for a wave with the infrared sensor. Either one makes it turn its head to a random angle and play a random phrase from the SD card. It stays quiet for 2.5 seconds between phrases and goes to sleep after a minute. Record the phrases yourself, or use simple sounds, as short MP3 files. For a young child, enclose the batteries behind a cover that needs a screwdriver, keep the cardboard away from heat, and make sure small parts such as the servo horn cannot come off. Keep the volume moderate. Use only the AA pack, not a mains adapter, on a toy. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// Talking robot. Libraries: Servo (built in), DFRobotDFPlayerMini. Board: Arduino Nano.
// SD card: phrase files 0001.mp3 to 0010.mp3 in the root folder.
#include <Servo.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

SoftwareSerial mp3(10, 11);
DFRobotDFPlayerMini player;
Servo head;
const int SND = A0, IR = 2;
unsigned long lastActive = 0, lastSpeak = 0;
int baseline = 0;
bool asleep = false;

void setup() {
  pinMode(IR, INPUT);
  head.attach(9); head.write(90);
  mp3.begin(9600); player.begin(mp3); player.volume(20);
  randomSeed(analogRead(A5));
  long s = 0; for (int i = 0; i < 100; i++) { s += analogRead(SND); delay(5); }
  baseline = s / 100;                                   // the room's normal sound level
  lastActive = millis();
}

void speak() {
  if (millis() - lastSpeak < 2500) return;              // do not talk over itself
  head.write(random(60, 121));                          // turn the head
  player.play(random(1, 11));
  lastSpeak = lastActive = millis(); asleep = false;
}

void loop() {
  bool clap = abs(analogRead(SND) - baseline) > 200;    // a loud, sudden sound
  bool wave = digitalRead(IR) == LOW;                   // a hand in front
  if (clap || wave) { speak(); }
  if (!asleep && millis() - lastActive > 60000) {       // sleep after a minute with no one around
    head.write(90); asleep = true;
  }
  delay(20);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
ClapHead turns and a phrase plays
WaveThe same
Quiet minuteRobot sleeps
Wave againWakes up

If it does not work

Triggers by itself

Turn the sound module's screw down or raise the clap threshold.

No sound

Check the SD card and the 1 kΩ resistor.

Servo twitches

Power it from the AA pack with a common ground.

Resets

Use fresh batteries.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the talking robot toy?

Arduino Nano, SG90 Micro Servo, Sound sensor module (KY-038), IR obstacle avoidance sensor module, DFPlayer Mini MP3 module, Speaker 8 Ω 0.5 W, SanDisk microSD card 32 GB (A1, Class 10), Battery holder 4 × AA with switch, AA alkaline battery × 4 and Resistor 1 kΩ.

How long does the talking robot toy take to build?

About 120 minutes for a beginner maker, in 7 steps.

How do I know the talking robot toy works?

Clap: Head turns and a phrase plays. Wave: The same. Quiet minute: Robot sleeps.

Triggers by itself: what should I check?

Turn the sound module's screw down or raise the clap threshold.

No sound: what should I check?

Check the SD card and the 1 kΩ resistor.

Servo twitches: what should I check?

Power it from the AA pack with a common ground.

Resets: what should I check?

Use fresh batteries.