ayanfeoluwaadekanye1
Published © GPL3+

Cleaner Bot

Make an autonomous voice controlled cleaner bot that can dust around your room.

IntermediateShowcase (no instructions)524
Cleaner Bot

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Resistor 1k ohm
Resistor 1k ohm
×3
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
Relay Module (Generic)
×1

Software apps and online services

MIT App Inventor 2
MIT App Inventor 2

Story

Read more

Schematics

The Circuit

I used 3 18650 Li ion batteries not 2.

The apk

Code

The Code

C/C++
#define enA 9
#define enB 10
#define in1 8
#define in2 7
#define in3 6
#define in4 5
#define rly 2

//infared pins
#define lftIr 12
#define ctrIr 4
#define rghIr 3

String msg="";
int spd=150;
bool swtch=0;

void setup() {
  // put your setup code here, to run once:
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(rly, OUTPUT);
  
  Serial.begin(38400);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()){
    msg=Serial.readString();
  }

  if (msg=="start cleaning"){
    swtch=1;
  }
  else if(msg=="stop cleaning"){
    swtch=0;
  }
  if (swtch==1) {
    moveBot();
    digitalWrite(rly,HIGH);
  }
  else{
    digitalWrite(rly,LOW);
    stopAll();
    }
}

void moveBot(){
  //delay(500);
 // stopAll();
  //delay(2000);
  analogWrite(enA, 100);
  analogWrite(enB, 100);
  int leftIr=digitalRead(lftIr);
   int centerIr=digitalRead(ctrIr);
   int rightIr=digitalRead(rghIr);
  

   if (leftIr==LOW && rightIr==HIGH){
        while(leftIr==LOW){
          rightMov();
          leftIr=digitalRead(lftIr);
        }
        stopAll();
       }
       else if (leftIr==HIGH && rightIr==LOW){
        stopAll();
          while(rightIr==LOW){
            leftMov();
            rightIr=digitalRead(rghIr);
          }
        stopAll(); 
      }
      else if (leftIr==LOW && centerIr==LOW && rightIr==LOW){
          stopAll();
              while(leftIr==LOW || centerIr==LOW || rightIr==LOW){
                backMov();
                leftIr=digitalRead(lftIr);
                centerIr=digitalRead(ctrIr);
                rightIr=digitalRead(rghIr);
                }
                stopAll();
          }
          
      else if (leftIr==HIGH && centerIr==LOW && rightIr==HIGH){
          stopAll();
          while(centerIr==LOW){
            backMov();
            centerIr=digitalRead(ctrIr);
          }
          stopAll();
          delay(10);
          leftMov();
          delay(500);
          stopAll();
        }
      else{
        fowardMov();
        
      }
  }
void fowardMov(){
  digitalWrite(in2,HIGH);
  digitalWrite(in4,HIGH);
  digitalWrite(in1, LOW);
  digitalWrite(in3, LOW);
}

void backMov(){
  digitalWrite(in1,HIGH);
  digitalWrite(in3,HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in4, LOW);
}

void rightMov(){
  digitalWrite(in1, HIGH);
  digitalWrite(in4, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
}

void leftMov(){
  digitalWrite(in2, HIGH);
  digitalWrite(in3, HIGH);
  digitalWrite(in1, LOW);
  digitalWrite(in4, LOW);
}

void stopAll(){
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}

Credits

ayanfeoluwaadekanye1

ayanfeoluwaadekanye1

0 projects β€’ 8 followers

Comments