DAISY : THE SERVING ROBOT
CIRCUIT :
SOURCE CODE :
//MKINVENTIONS : PLACE OF INNOVATIVE INVENTIONS.
//YOUTUBE/MKINVENTIONS MADHAN CHIRUGURI.
//FACEBOOK/MADHAN KUMAR CHIRUGURI
//************************************************************
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD
// Wiring: SDA pin is connected to A4 and SCL pin to A5.
// Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered)
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x3F, 16, 2); // Change to (0x27,16,2) for 16x2 LCD.my address is (0x3F)
#include <Stepper.h>
const int STEPS = 250;
Stepper myStepper(STEPS, 13, 10, 12, 11);
int x = 0;
// the 8 arrays that form each segment of the custom numbers
byte LT[8] =
{
B00111,
B01111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
byte UB[8] =
{
B11111,
B11111,
B11111,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte RT[8] =
{
B11100,
B11110,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
byte LL[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B01111,
B00111
};
byte LB[8] =
{
B00000,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111,
B11111
};
byte LR[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11110,
B11100
};
byte UMB[8] =
{
B11111,
B11111,
B11111,
B00000,
B00000,
B00000,
B11111,
B11111
};
byte LMB[8] =
{
B11111,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111,
B11111
};
//***************************************************
char command;
int LMT1 = 5;//left motor 1
int LMT2 = 6;//left motor 2
int RMT1 = 7;//right motor 1
int RMT2 = 8;//right motor 2
int LED1 = A0;//HEAD LEDS
int LED2 = A1;//BACK LED
int LED3 = A2;//BOTTOM LED
int trigPin = 2;
int echoPin = 3;
int BUZZER = 1;
long distance;
long duration;
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.createChar(8,LT);
lcd.createChar(1,UB);
lcd.createChar(2,RT);
lcd.createChar(3,LL);
lcd.createChar(4,LB);
lcd.createChar(5,LR);
pinMode(LMT1, OUTPUT);
pinMode(LMT2, OUTPUT);
pinMode(RMT1, OUTPUT);
pinMode(RMT2, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(BUZZER, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
}
void loop(){
EYES();
if(Serial.available() > 0){
command = Serial.read();
Serial.println(command);
//FORWARD..............
if(command == 'F' ){
forward();
}
//BACKWARD..............
else if(command == 'B' ){
backward();
}
//LEFT..............
else if(command == 'L' ){
left();
}
//RIGHT..............
else if(command == 'R' ){
right();
}
//FORWARD LEFT........
else if(command == 'F' && command == 'L' ){
forwardleft();
}
//FORWARD RIGHT........
else if(command == 'F' && command == 'R' ){
forwardright();
}
//BACKWARD LEFT........
else if(command == 'B' && command == 'L' ){
backwardleft();
}
//BACKWARD RIGHT........
else if(command == 'B' && command == 'R' ){
backwardright();
}
//STOP..............
else{
stp();
}
//LED1..............
if(command == 'U' ){
digitalWrite(LED1, HIGH);
}
if(command == 'u' ){
digitalWrite(LED1, LOW);
}
//LED3..............
if(command == 'W' ){
digitalWrite(LED3, HIGH);
}
if(command == 'w' ){
digitalWrite(LED3, LOW);
}
//STEPPER MOTOR..............
if(command == 'X' ){
myStepper.setSpeed(60);
myStepper.step(STEPS);
}
if(command == 'x' ){
myStepper.setSpeed(60);
myStepper.step(-STEPS);
}
}
ULTRASONIC();
if(distance <= 10){
stp();//ROBOT STOP
lcd.setCursor(1, 0);
lcd.print(" OBSTACLE ");
lcd.setCursor(0, 1);
lcd.print(" PLEASE MOVE ");
analogWrite(LED2, 150);
delay(500);
analogWrite(LED2, 0);
delay(500);
lcd.clear();
}
}
void ULTRASONIC(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration*0.034/2;
}
void EYES(){
//LEFT EYE
lcd.setCursor(1, 0);
lcd.write(8);
lcd.write(1);
lcd.write(1);
lcd.write(1);
lcd.write(2);
lcd.setCursor(1, 1);
lcd.write(3);
lcd.write(4);
lcd.write(4);
lcd.write(4);
lcd.write(5);
//NOSE
lcd.setCursor(7,1);
lcd.write(4);
//RIGHT EYE
lcd.setCursor(9, 0);
lcd.write(8);
lcd.write(1);
lcd.write(1);
lcd.write(1);
lcd.write(2);
lcd.setCursor(9, 1);
lcd.write(3);
lcd.write(4);
lcd.write(4);
lcd.write(4);
lcd.write(5);
}
void forward(){
analogWrite(LMT1, 0);
analogWrite(LMT2, 130);
analogWrite(RMT1, 130);
analogWrite(RMT2, 0);
}
void backward(){
analogWrite(LMT1, 130);
analogWrite(LMT2, 0);
analogWrite(RMT1, 0);
analogWrite(RMT2, 130);
}
void left(){
analogWrite(LMT1, 130);
analogWrite(LMT2, 0);
analogWrite(RMT1, 130);
analogWrite(RMT2, 0);
}
void right(){
analogWrite(LMT1, 0);
analogWrite(LMT2, 130);
analogWrite(RMT1, 0);
analogWrite(RMT2, 130);
}
void stp(){
analogWrite(LMT1, 0);
analogWrite(LMT2, 0);
analogWrite(RMT1, 0);
analogWrite(RMT2, 0);
}
void forwardleft(){
analogWrite(LMT1, 0);
analogWrite(LMT2, 0);
analogWrite(RMT1, 130);
analogWrite(RMT2, 0);
}
void forwardright(){
analogWrite(LMT1, 0);
analogWrite(LMT2, 130);
analogWrite(RMT1, 0);
analogWrite(RMT2, 0);
}
void backwardleft(){
analogWrite(LMT1, 0);
analogWrite(LMT2, 0);
analogWrite(RMT1, 0);
analogWrite(RMT2, 130);
}
void backwardright(){
analogWrite(LMT1, 130);
analogWrite(LMT2, 0);
analogWrite(RMT1, 0);
analogWrite(RMT2, 0);
}
0 Comments
Please do not Enter any Spam Link in the Comment Box
Emoji