Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Walley Erfan Khan
Published © Apache-2.0

UV RoboS (Covid Warrior)

My 1st Robot.

BeginnerFull instructions provided5 hours3,945
UV RoboS (Covid Warrior)

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
DC Motor, 12 V
DC Motor, 12 V
×4
Maker Essentials - Micro-motors & Grippy Wheels
Pimoroni Maker Essentials - Micro-motors & Grippy Wheels
×4
LED (generic)
LED (generic)
×12
Soldering iron (generic)
×1
Multitool, Screwdriver
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Bluetooth RC Car

Story

Read more

Schematics

COVID-19 warrior Robot Schismatic

COVID-19 warrior Robot schismatic

Code

UVRoboS Code

Arduino
COVID-19 warrior Robot
#include <AFMotor.h>
#include <SoftwareSerial.h>
SoftwareSerial bluetoothSerial(9, 10); // RX, TX

AF_DCMotor front_right(1);
AF_DCMotor front_left(2);
AF_DCMotor back_right(3);
AF_DCMotor back_left(4);

int pir1 = 14;
int pir2 = 15;
int pir3 = 16;
int pir4 = 17;

boolean pirStat1 = false;
boolean pirStat2 = false; 
boolean pirStat3 = false; 
boolean pirStat4 = false;  

int vuc_lamp = 13;

int manualSpeed = 160;

boolean living_object = false; 

char btCommand = 'S';
char prevCommand = 'A';
int velocity = 0;   
unsigned long timer0 = 2000;  //Stores the time (in millis since execution started) 
unsigned long timer1 = 0;  //Stores the time when the last command was received from the phone

String inputString = "";
String command = "";
String value = "";
boolean stringComplete = false; 

void setup() {
  
  bluetoothSerial.begin(9600); //set the baud rate for your bluetooth mode
  
  pinMode(pir1, INPUT);
  pinMode(pir2, INPUT);
  pinMode(pir3, INPUT);
  pinMode(pir4, INPUT);
  pinMode(uvc_lamp, OUTPUT);
  
  // turn on motor
  front_right.setSpeed(150);
  front_left.setSpeed(150);
  back_right.setSpeed(150);
  back_left.setSpeed(150);
 
  front_right.run(RELEASE);
  front_left.run(RELEASE);
  back_right.run(RELEASE);
  back_left.run(RELEASE);

  inputString.reserve(50);  // reserve 50 bytes in memory to save for string manipulation 
  command.reserve(50);
  value.reserve(50);
}

void loop() {

//  front_right.setSpeed(manualSpeed);
//  front_left.setSpeed(manualSpeed);
//  back_right.setSpeed(manualSpeed);
//  back_left.setSpeed(manualSpeed);

  pirStat1 = digitalRead(pir1);
  pirStat2 = digitalRead(pir2);
  pirStat3 = digitalRead(pir3);
  pirStat4 = digitalRead(pir4); //if any sensor detect motor state goes to high
   
  if (pirStat1 == HIGH || pirStat2 == HIGH || pirStat3 == HIGH || pirStat4 == HIGH) {            // if motion detected
   living_object = true; 
  }  
  bluetoothControl();
  
}

motor.run(FORWARD);
motor.run(BACKWARD);
motor.run(RELEASE);

void run_forward(){
   front_right.run(FORWARD);
   front_left.run(FORWARD);
   back_right.run(FORWARD);
   back_left.run(FORWARD);
 }

void run_backward(){
   front_right.run(BACKWARD);
   front_left.run(BACKWARD);
   back_right.run(BACKWARD);
   back_left.run(BACKWARD);
 }

void stop_position(){
   front_right.run(RELEASE);
   front_left.run(RELEASE);
   back_right.run(RELEASE);
   back_left.run(RELEASE);
 }

void rotate_write(){
   front_right.run(BACKWARD);
   front_left.run(FORWARD);
   back_right.run(BACKWARD);
   back_left.run(FORWARD);
 }

void rotate_left(){
   front_right.run(FORWARD);
   front_left.run(BACKWARD);
   back_right.run(FORWARD);
   back_left.run(BACKWARD);
 }


 void serialEvent() {
  while (bluetoothSerial.available()) {
    // get the new byte:
    char inChar = (char)bluetoothSerial.read(); 
    //Serial.write(inChar);
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline or a carriage return, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n' || inChar == '\r') {
      stringComplete = true;
    } 
  }
}


void bluetoothControl(){
  if(bluetoothSerial.available() > 0){ 
    timer1 = millis();   
    prevCommand = btCommand;
    btCommand = bluetoothSerial.read(); 
    //Change pin mode only if new command is different from previous.   
    if(btCommand!=prevCommand){
      //Serial.println(command);
      switch(btCommand){
      case 'F':  
        run_forward();
        break;
      case 'B':  
        run_backward();
        break;
      case 'L':  
        rotate_left();
        break;
      case 'R':
        rotate_right();
        break;
      case 'S':  
        stop_position();
        break; 
      case 'U':  //uvc 
        if(!living_object)
          digitalWrite(uvc_lamp, HIGH);
        break;
      case 'V':  //uvc 
        digitalWrite(uvc_lamp, LOW);
        break;       
      default:  //Get velocity
        if(btCommand=='q'){
          velocity = 255;  //Full velocity
          manualSpeed = velocity;
        }
        else{ 
          //Chars '0' - '9' have an integer equivalence of 48 - 57, accordingly.
          if((btCommand >= 48) && (btCommand <= 57)){ 
            //Subtracting 48 changes the range from 48-57 to 0-9.
            //Multiplying by 25 changes the range from 0-9 to 0-225.
            velocity = (btCommand - 48)*25;       
            manualSpeed = velocity;
          }
        }
      }
    }
  } 
}

Credits

Walley Erfan Khan

Walley Erfan Khan

2 projects • 8 followers
Engineer, developer, Inventor, Maker & Hacker.

Comments