EMO Robot Using Arduino Nano

 EMO ROBOT PROJECT 





● Electronics Components Required:-

1. Arduino Nano 

2. Oled Display 


3. Servo Motor 

4. Touch Sensor 


5. Switch 


6. Lithium Ion Battery 


7. Battery Holder 


8. Breadboard 





Connections:-


● Library Used:-

Adafruit_GFX.h
Adafruit_SSD1306.h

● Code:-

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Servo.h>

// ---------- OLED ----------
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// ---------- SERVO ----------
Servo neck;
#define SERVO_PIN 9

int centerPos = 90;
int leftPos = 45;
int rightPos = 135;
int servoPos = centerPos;
int stepSize = 2;
bool moveRight = true;

// ---------- TOUCH SENSOR ----------
#define TOUCH_PIN 2
bool touched = false;

// ---------- EYES ----------
int eyeY = 32;
int eyeOffset = 0;
unsigned long lastBlink = 0;
bool blink = false;

// ---------- SETUP ----------
void setup() {
  pinMode(TOUCH_PIN, INPUT);

  neck.attach(SERVO_PIN);
  neck.write(centerPos);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();

  // Startup Name (2 sec)
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(5, 24);
  display.println("Mr Ayush");
  display.setCursor(25, 44);
  display.println("Xaxa");
  display.display();
  delay(2000);
}

// ---------- LOOP ----------
void loop() {
  touched = digitalRead(TOUCH_PIN);

  if (touched) {
    touchMode();
  } else {
    radarServo();
    eyeAnimation(false);
  }
}

// ---------- TOUCH MODE ----------
void touchMode() {
  // Servo to center & stop
  servoPos = centerPos;
  neck.write(centerPos);

  // Big eyes + fast blink
  eyeAnimation(true);
}

// ---------- RADAR SERVO ----------
void radarServo() {
  if (moveRight) {
    servoPos += stepSize;
    if (servoPos >= rightPos) moveRight = false;
  } else {
    servoPos -= stepSize;
    if (servoPos <= leftPos) moveRight = true;
  }

  neck.write(servoPos);

  // Pause at center
  if (servoPos == centerPos) {
    delay(1000);
  }

  delay(15);
}

// ---------- EYE ANIMATION ----------
void eyeAnimation(bool bigEyeMode) {
  display.clearDisplay();

  eyeOffset = map(servoPos, leftPos, rightPos, -6, 6);

  unsigned long blinkInterval = bigEyeMode ? 400 : 3000;

  if (millis() - lastBlink > blinkInterval) {
    blink = true;
    lastBlink = millis();
  }

  if (bigEyeMode) {
    drawBigEye(44, eyeY);
    drawBigEye(84, eyeY);
  } else {
    drawEye(44 + eyeOffset, eyeY);
    drawEye(84 + eyeOffset, eyeY);
  }

  display.display();

  if (blink) {
    delay(bigEyeMode ? 60 : 120);
    blink = false;
  }
}

// ---------- NORMAL EYE ----------
void drawEye(int x, int y) {
  if (blink) {
    display.fillRect(x - 12, y, 24, 3, SSD1306_WHITE);
  } else {
    display.fillRoundRect(x - 12, y - 12, 24, 24, 7, SSD1306_WHITE);
    display.fillCircle(x, y, 4, SSD1306_BLACK);
  }
}

// ---------- BIG EYE (TOUCH MODE) ----------
void drawBigEye(int x, int y) {
  if (blink) {
    display.fillRect(x - 16, y, 32, 4, SSD1306_WHITE);
  } else {
    display.fillRoundRect(x - 18, y - 18, 36, 36, 9, SSD1306_WHITE);
    display.fillCircle(x, y, 6, SSD1306_BLACK);
  }
}



Thankyou...


Comments

Popular posts from this blog

Obstacle Avoiding Robot Car Arduino Project

4 Best Science Projects For School Without Using Arduino

SENSOR TUTORIAL

AUTOMATIC TOLL GATE PROJECT

ARDUINO TUTORIAL

Drone Tech | How To Make Mini Drone For Science Exhibition It Can Fly || Remote Control Drone

RAIN ALARM PROJECT

BASIC SERVO MOTOR TEST

SMART IRRIGATION FOR FLYOVER

KIKIBOT Robo Car ESP32 Project