Professional Documents
Culture Documents
Activity 3 Campus Robot Roving Sanitizer
Activity 3 Campus Robot Roving Sanitizer
INTRODUCTION
Arduino Uno
Lion battery (4pcs)
Jumper wire
Ultrasonic sensor
Pump bottle
4x Wheels
4x DC motor
2x IR sensor
Wooden board
Motor pump
Hose
Alcohol
Switch button
PROCEDURE
Led light has two pin the short and long pin, the short
digital pin2.
Determine the four the trig, echo, volts and GND. The
trig pin is connected to motor shield pin3 and the echo pin is
terminal. In this case, Arduino pin4 for M1, pin5 for M2, pin6
Put the water pump motor with hose inside the bottle of
full alcohol.
CIRCUIT DIAGRAM
SOURCE
#include <AFMotor.h>
#include <NewPing.h>
//defining motors
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
long inch;
void setup() {
//setting the speed of motors
motor1.setSpeed(90);
motor2.setSpeed(90);
motor3.setSpeed(90);
motor4.setSpeed(90);
//declaring pin types
pinMode(lefts,INPUT);
pinMode(rights,INPUT);
void loop(){
// pump condition
digitalWrite(trigPin, LOW);
delayMicroseconds(2);// Sets the trigPin HIGH (ACTIVE) for 10
microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);// Reads the echoPin, returns the
sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}
else
{
digitalWrite(relayPin, HIGH);
digitalWrite(ledPin, HIGH);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
//line detected by right sensor
else if(!analogRead(lefts)<=350 && analogRead(rights)<=350){
//turn right
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
//line detected by none
else if(!analogRead(lefts)<=350 && !analogRead(rights)<=350)
{
//stop
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);