Mokshith
Published © GPL3+

Agribot

The bot is developed with an idea to introduce a robot technology to the field of agriculture along with robot enabled with AI and IOT

IntermediateProtip663
Agribot

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Dual H-Bridge motor drivers L293D
Texas Instruments Dual H-Bridge motor drivers L293D
×1
MAX30105 High-Sensitivity Optical Sensor for Smoke Detection Applications
Maxim Integrated MAX30105 High-Sensitivity Optical Sensor for Smoke Detection Applications
×1
LAUNCHXL-CC2650 SimpleLink CC2650 BLE Zigbee 6LoWPAN LaunchPad
Texas Instruments LAUNCHXL-CC2650 SimpleLink CC2650 BLE Zigbee 6LoWPAN LaunchPad
×1

Software apps and online services

ThingSpeak API
ThingSpeak API

Hand tools and fabrication machines

Materia 101
Arduino Materia 101
python.microbit.org
micro:bit python.microbit.org

Story

Read more

Code

Arduino Code

Arduino
const int trigPin = 13;//Ultrasonic sensor trigger pin
const int echoPin = 12;// echo pin
int solenoid = 9;// solenoid from l293d board one pin to ground and other to pin 9 ardiuno
int forka = 8;//fork lift from l293d board one pin to 8 ardiuno
int forkb = 7;//fork lift from l293d board other to pin 7 ardiuno
int sw=6;// switch one pin to 5v and other to pin 6 ardiuno
int smoke = 11;
int mot = 10;
int mota = 5;
int sw1=4;
int sw2 = 3;
int sw3 = 2;
String aa = "";
int smk;
int sensor_pin = A0;// moisture level sensor output pin
const int sensor=A1;// temperature sensor output pin
int output_value ;
float tempc;
// defines variables
long duration;
int distanceCm, distanceInch;
//const int sensor=A0; // Assigning analog pin A1 to variable 'sensor'
//float tempc;
float vout;
static unsigned long nextSwitchTime = millis()+500;
static unsigned long nextMotTime = millis()+500;
int a=0;
int mot_count = 0;
int sw_o = 0;
void send_data(){
  //Serial.print("M");
  Serial.print("T");
  Serial.print(tempc);
  Serial.print("D");
  Serial.print(distanceCm);
  Serial.print("M");
  Serial.print(String(output_value));
  Serial.print("S");
  Serial.print(smk);
  Serial.print("W");
  Serial.print(sw_o);
  Serial.println("E");
}

void change_mot(){
  //Serial.println("enter");
  mot_count++;
  if(mot_count == 1){
    //Serial.println("1");
    digitalWrite(mot, LOW);
    digitalWrite(mota, HIGH);
    delay(500);
    digitalWrite(mot, HIGH);
    digitalWrite(mota, HIGH);
  }
  else if(mot_count == 2){
    //Serial.println("2");
    digitalWrite(mot, LOW);
    digitalWrite(mota, HIGH);
    delay(500);
    digitalWrite(mot, HIGH);
    digitalWrite(mota, HIGH);
  }
  else if(mot_count == 3){
    //Serial.println("3");
    digitalWrite(mot, LOW);
    digitalWrite(mota, HIGH);
    delay(500);
    digitalWrite(mot, HIGH);
    digitalWrite(mota, HIGH);
  }
  else if(mot_count == 4){
    //Serial.println("4");
    mot_count = 0;
    digitalWrite(mot, LOW);
    digitalWrite(mota, HIGH);
    delay(500);
    digitalWrite(mot, HIGH);
    digitalWrite(mota, HIGH);
  }
}
void setup() {
  pinMode(sensor_pin,INPUT);
  pinMode(sensor,INPUT);
  pinMode(smoke,INPUT);
  pinMode(sw1,INPUT);
  pinMode(sw2,INPUT);
  pinMode(sw3,INPUT);
  pinMode(mot, OUTPUT);
  pinMode(mota, OUTPUT);
  pinMode(solenoid, OUTPUT);
  pinMode(forka, OUTPUT);
  pinMode(forkb, OUTPUT);
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
  digitalWrite(solenoid, LOW);
  digitalWrite(forka, LOW);
  digitalWrite(forkb, LOW);
  //Serial.print("test");
}

void loop() {
  if(digitalRead(sw)==1 && a==0){
    Serial.print("a");
      a=1;
      digitalWrite(solenoid, HIGH);
      digitalWrite(forka, HIGH);
      digitalWrite(forkb, LOW);
      delay(200);
      digitalWrite(forka, LOW);
      digitalWrite(forkb, LOW);
    }
    if(digitalRead(sw)==1 && a==1){
      Serial.print("b");
      a=0;
      digitalWrite(solenoid, LOW);
      digitalWrite(forka, LOW);
      digitalWrite(forkb, HIGH);
      delay(200);
      digitalWrite(forka, LOW);
      digitalWrite(forkb, LOW);
    }
  output_value= analogRead(sensor_pin);
  output_value = map(output_value,600,250,10,99);
  //delay(1000);
  vout=analogRead(sensor);
  
  if(digitalRead(sw2)==1){
      sw_o=2;
      tempc = 00.00;
    }
   else{
    tempc=(vout*250)/1023;
   }
  //digitalWrite(mot, LOW);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(mot, HIGH);
  digitalWrite(mota, HIGH);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distanceCm= duration*0.034/2;
  distanceInch = duration*0.0133/2;
  if(digitalRead(smoke)==1){
    smk=1;
    //delay(1000);
    }
    else{
      smk=0;
    }
   if(digitalRead(sw1)==1){
    sw_o=1;
    digitalWrite(mot, LOW);
    digitalWrite(mota, LOW);
    }
    if(digitalRead(sw2)==1){
      sw_o=2;
    }
    
    else{
      sw_o=0;
    }
  if(distanceCm <=20){
    digitalWrite(mot, LOW);
    digitalWrite(mota, LOW);
    delay(2000);
    distanceCm=10;
  }
  else if(distanceCm >20 && distanceCm <= 50){
    digitalWrite(mot, LOW);
    digitalWrite(mota, LOW);
    delay(200);
    digitalWrite(mot, HIGH);
    digitalWrite(mota, HIGH);
    delay(200);
  }
  else if (distanceCm>50){
    digitalWrite(mot, HIGH);
    digitalWrite(mota, HIGH);
    distanceCm=99;
  }
  delay(10);
  if( nextSwitchTime < millis() ) 
   { 
       send_data(); 
       nextSwitchTime = millis() + 1000;
   }

   if( nextMotTime < millis() ) 
   { 
       change_mot(); 
       nextMotTime = millis() + 5000;
   }
  //delay(1000);
  //Serial.println(float(distanceCm));
}  

Credits

Mokshith

Mokshith

1 project • 2 followers

Comments

Add projectSign up / LoginAbout BBC micro:bit