Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Emotion Robot with TFT LCD Display and Servo Motors

View and Edit Project In Cirkit DesignerImage of Arduino UNO Emotion Robot with TFT LCD Display and Servo Motors

Circuit Documentation

Summary

This circuit is designed to control an emotion robot using an Arduino UNO microcontroller. The robot can display different emotions on a TFT LCD screen, respond to touch and vibration sensors, and control three servo motors to perform various movements. The robot can also enter a sleep mode based on inactivity and has a dance mode activated by a toggle switch.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Servo (x3)

    • Description: Standard servo motor.
    • Pins: gnd, vcc, pulse
  3. SW-420 Vibration Sensor

    • Description: Vibration sensor module.
    • Pins: vcc, Ground, Digital output
  4. Toggle Switch

    • Description: Simple toggle switch.
    • Pins: Vcc, Sig, Gnd
  5. TFT LCD Display ST7735S

    • Description: TFT LCD display module.
    • Pins: Vcc, GND, CS, RESET, A0, SDA, SCK, LED
  6. Touch Sensor

    • Description: Capacitive touch sensor.
    • Pins: IO, VCC, GND

Wiring Details

Arduino UNO

Servo (x3)

SW-420 Vibration Sensor

Toggle Switch

TFT LCD Display ST7735S

Touch Sensor

Documented Code

#include <SPI.h>
#include <SD.h>
#include <TFT.h>  // Arduino LCD library
#include <Servo.h>

// Pin definitions
#define sd_cs 4
#define tft_cs 10
#define tft_AO 9
#define tft_rst 8
#define TOUCH_SENSOR_PIN 2        // Pin for touch sensor (digital)
#define VIBRATION_SENSOR_PIN 3    // Pin for vibration sensor (digital)
#define TOGGLE_PIN A0             // Pin for toggle switch (analog)

// Servo motor pins
#define handServo1Pin 6           // Left hand servo
#define handServo2Pin 7           // Right hand servo
#define bodyServoPin 5            // Body servo

TFT TFTscreen = TFT(tft_cs, tft_AO, tft_rst);

PImage happyImage;
PImage angryImage;
PImage dizzyImage;
PImage sadImage;
PImage sleepImage;

Servo handServo1, handServo2, bodyServo;

const int handMin = 0;
const int handMax = 180;
const int bodyMin = 90;
const int bodyMax = 180;

int hitCount = 0;
unsigned long lastActivityTime = 0;  // To track inactivity
bool isSleeping = false;  // Flag to check if the robot is in sleep mode
bool isDancing = false;   // Flag to check if the robot is in dance mode

void setup() {
  Serial.begin(9600);

  // Initialize TFT screen
  TFTscreen.begin();
  TFTscreen.background(255, 255, 255);
  TFTscreen.stroke(0, 0, 255);
  TFTscreen.println("Emotion Robot Ready!");

  // Initialize SD card
  if (!SD.begin(sd_cs)) {
    Serial.println("SD card initialization failed!");
    return;
  }

  // Load images
  happyImage = TFTscreen.loadImage("happy.bmp");
  angryImage = TFTscreen.loadImage("angry.bmp");
  dizzyImage = TFTscreen.loadImage("dizzy.bmp");
  sadImage = TFTscreen.loadImage("sad.bmp");
  sleepImage = TFTscreen.loadImage("sleep.bmp");

  if (!happyImage.isValid() || !angryImage.isValid() || !dizzyImage.isValid() || !sadImage.isValid() || !sleepImage.isValid()) {
    Serial.println("Error loading images!");
  }

  // Attach servos
  handServo1.attach(handServo1Pin);
  handServo2.attach(handServo2Pin);
  bodyServo.attach(bodyServoPin);

  // Initialize servo positions
  resetServos();

  // Initialize sensor pins
  pinMode(TOUCH_SENSOR_PIN, INPUT);
  pinMode(VIBRATION_SENSOR_PIN, INPUT);
  pinMode(TOGGLE_PIN, INPUT);

  Serial.println("Setup complete. Toggle switch to start/stop dancing.");
}

void loop() {
  // Sleep mode based on inactivity
  if (millis() - lastActivityTime > 16000 && !isSleeping) {
    showImage(sleepImage);
    isSleeping = true;
    resetServos();
  }

  // Check touch sensor for Happy behavior
  if (digitalRead(TOUCH_SENSOR_PIN) == HIGH) {
    performHappyBehavior();
    lastActivityTime = millis();
    isSleeping = false;
    delay(1000); // Debounce
    return;
  }

  // Check vibration sensor for hits
  if (digitalRead(VIBRATION_SENSOR_PIN) == HIGH) {
    countHits();
    lastActivityTime = millis();
    isSleeping = false;
  }

  // Check toggle switch for dance mode
  int toggleState = analogRead(TOGGLE_PIN) > 512 ? HIGH : LOW;

  if (toggleState == HIGH && !isDancing) {
    Serial.println("Dance mode activated!");
    isDancing = true;
    lastActivityTime = millis();
  }

  if (toggleState == LOW && isDancing) {
    Serial.println("Dance mode deactivated!");
    isDancing = false;
    resetServos();
  }

  if (isDancing) {
    performDance();
    return; // Skip other behaviors while dancing
  }
}

// -----------------------------------
// HANDLING HITS
// -----------------------------------
void countHits() {
  unsigned long startTime = millis();
  hitCount = 0;

  // Wait 2 seconds to count hits
  while (millis() - startTime < 2000) {
    if (digitalRead(VIBRATION_SENSOR_PIN) == HIGH) {
      hitCount++;
      delay(138); // Debounce
    }
  }

  Serial.print("Total hits: ");
  Serial.println(hitCount);

  // Determine behavior based on hit count
  if (hitCount >= 1 && hitCount <= 5) {
    performAngryBehavior();
  } else if (hitCount > 5 && hitCount <= 12) {
    performDizzyBehavior();
  }