This is an old revision of the document!


Very Shy Robot

Author : Ghibea Ovidiu-Catalin

Group : 1221A

Faculty : FILS

Introducere

This robot has an anxiety problem and does not want to meet with anyoane or anything.

Descriere generală

Small robot that is capable of sensing incoming obstacles and avoid them. Once the switch is turned on, the robot will start moving in a straight line. The ultrasonic sensor placed on the front of the robot will pick up any incoming waves and will translate this into distance in the code. If the received distance will be lower than a certain threshold He will stop and signal to the motor driver module to turn left until there is nothing in front of him anymore, after which he will continue moving.

Hardware Design

Components

Name Quantity
Arduino Uno 1
HC-SR04 Ultrasonic Sensor 1
Speaker 1
LM298N Motor Driver Module 1
5V DC Motors 2
Switch 1
9V Battery 1
Wheels 2
Chassis 1
Jumper Wires 1

Electric diagram:

Software Design

  • Development environments used: ArduinoIDE
  • Used libraries:

https://www.arduino.cc/reference/en/libraries/pcm/

How It Works

First define trig and echo pin of HC-SR04 in the program. In this project the trig pin is connected to GPIO9 and echo pin is connected to GPIO10 of Arduino NANO.

int trigPin = 9;      // trig pin of HC-SR04
 
int echoPin = 10;     // Echo pin of HC-SR04

Define pins for input of LM298N Motor Driver Module. The LM298N has 4 data input pins used to control the direction of motor connected to it.

int revleft4 = 4;       //REVerse motion of Left motor
int fwdleft5 = 5;       //ForWarD motion of Left motor
int revright6 = 6;      //REVerse motion of Right motor
int fwdright7 = 7;      //ForWarD motion of Right motor

In setup() function, define the data direction of utilised GPIO pins. The four Motor pins and Trig pin is set as OUTPUT and Echo Pin is set as Input.

pinMode(revleft4, OUTPUT);      // set Motor pins as output
pinMode(fwdleft5, OUTPUT);
pinMode(revright6, OUTPUT);
pinMode(fwdright7, OUTPUT); 
pinMode(trigPin, OUTPUT);         // set trig pin as output
pinMode(echoPin, INPUT);          //set echo pin as input to capture reflected waves

The loop() part of the program is made out of two scenarios.

In the first scenario, the switch is off (The convention for this project is that if the microswitch is off, the circuit is active. If the switch is on, then the circuit is off. The reason for this being the outer design of the toy as well as the desire to make it movie accurate) and the program begins the arming sequence. It receives the measurement from the movement sensor and if the measurement is smaller than the chosen value, it keeps on with the arming sequence. If the measurement is greater than the chosen value, it stops the previous sequence by stopping track 1 and starts the detonation sequence by playing track 2 and turning all LED’s on HIGH.

// Start communication with DFPlayer Mini
 
    // Set volume to a value between (0 to 30)
    player.volume(30);
 
  if (digitalRead(BUTTON) == LOW ){
      player.play(1); // play the arming sequence
      digitalWrite(LEDRED, HIGH);//switch armed LED (red) on
  }
 
  if (digitalRead(BUTTON) == LOW && sequenceNumber == 0)
  {
    long measurement =pulseIn (SENSOR, HIGH); //get measurement from teh sensor
    Serial.println(measurement);
    if (measurement > 1000)
    { // measurement checks
      player.stop();
	    player.play(2); //playing detonating sequence
	    sequenceNumber = 0;
	    digitalWrite(LEDRED, HIGH);
      digitalWrite(LEDRIGHT, HIGH);
      digitalWrite(LEDMIDDLE, HIGH);
      digitalWrite(LEDLEFT, HIGH);
	    while(digitalRead(BUTTON)==LOW){ // give a chance to turn off the toy
		    delay(10000);
		    player.stop();
		    digitalWrite(LEDRED, LOW);
        digitalWrite(LEDRIGHT, LOW);
        digitalWrite(LEDMIDDLE, LOW);
        digitalWrite(LEDLEFT, LOW);
	    }
    }
    else
    { // measuremnt does not check
      delay(time);
      Sequence(false, true, true); // continu with arming sequence
      sequenceNumber++;
    }
  }

The second scenario is when the switch is on, so the circuit is not active.

if (digitalRead(BUTTON) == HIGH) // toy is turned off
  {
    sequenceNumber = 0;
    player.stop();
		digitalWrite(LEDRED, LOW);
    digitalWrite(LEDRIGHT, LOW);
    digitalWrite(LEDMIDDLE, LOW);
    digitalWrite(LEDLEFT, LOW);
  }  

Additionally, depending on the length of track 1 used in the arming sequence, we will choose a number of times the respective if{} statement will be repeated. In this case it, is repeated 12 times.

Rezultate Obţinute

Care au fost rezultatele obţinute în urma realizării proiectului vostru.

Concluzii

Download

O arhivă (sau mai multe dacă este cazul) cu fişierele obţinute în urma realizării proiectului: surse, scheme, etc. Un fişier README, un ChangeLog, un script de compilare şi copiere automată pe uC crează întotdeauna o impresie bună ;-).

Fişierele se încarcă pe wiki folosind facilitatea Add Images or other files. Namespace-ul în care se încarcă fişierele este de tipul :pm:prj20??:c? sau :pm:prj20??:c?:nume_student (dacă este cazul). Exemplu: Dumitru Alin, 331CC → :pm:prj2009:cc:dumitru_alin.

Jurnal

Puteți avea și o secțiune de jurnal în care să poată urmări asistentul de proiect progresul proiectului.

Bibliografie/Resurse

Listă cu documente, datasheet-uri, resurse Internet folosite, eventual grupate pe Resurse Software şi Resurse Hardware.

Export to PDF

pm/prj2022/robert/mini_wall-e.1653667165.txt.gz · Last modified: 2022/05/27 18:59 by ovidiu.ghibea
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0