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
Components and supplies
1
LAUNCHXL-CC2650 SimpleLink CC2650 BLE Zigbee 6LoWPAN LaunchPad
1
Dual H-Bridge motor drivers L293D
1
Arduino UNO
1
MAX30105 High-Sensitivity Optical Sensor for Smoke Detection Applications
Tools and machines
1
python.microbit.org
1
Materia 101
Apps and platforms
1
ThingSpeak API
Project description
Code
Arduino Code
arduino
1const int trigPin = 13;//Ultrasonic sensor trigger pin 2const int echoPin = 12;// echo pin 3int solenoid = 9;// solenoid from l293d board one pin to ground and other to pin 9 ardiuno 4int forka = 8;//fork lift from l293d board one pin to 8 ardiuno 5int forkb = 7;//fork lift from l293d board other to pin 7 ardiuno 6int sw=6;// switch one pin to 5v and other to pin 6 ardiuno 7int smoke = 11; 8int mot = 10; 9int mota = 5; 10int sw1=4; 11int sw2 = 3; 12int sw3 = 2; 13String aa = ""; 14int smk; 15int sensor_pin = A0;// moisture level sensor output pin 16const int sensor=A1;// temperature sensor output pin 17int output_value ; 18float tempc; 19// defines variables 20long duration; 21int distanceCm, distanceInch; 22//const int sensor=A0; // Assigning analog pin A1 to variable 'sensor' 23//float tempc; 24float vout; 25static unsigned long nextSwitchTime = millis()+500; 26static unsigned long nextMotTime = millis()+500; 27int a=0; 28int mot_count = 0; 29int sw_o = 0; 30void send_data(){ 31 //Serial.print("M"); 32 Serial.print("T"); 33 Serial.print(tempc); 34 Serial.print("D"); 35 Serial.print(distanceCm); 36 Serial.print("M"); 37 Serial.print(String(output_value)); 38 Serial.print("S"); 39 Serial.print(smk); 40 Serial.print("W"); 41 Serial.print(sw_o); 42 Serial.println("E"); 43} 44 45void change_mot(){ 46 //Serial.println("enter"); 47 mot_count++; 48 if(mot_count == 1){ 49 //Serial.println("1"); 50 digitalWrite(mot, LOW); 51 digitalWrite(mota, HIGH); 52 delay(500); 53 digitalWrite(mot, HIGH); 54 digitalWrite(mota, HIGH); 55 } 56 else if(mot_count == 2){ 57 //Serial.println("2"); 58 digitalWrite(mot, LOW); 59 digitalWrite(mota, HIGH); 60 delay(500); 61 digitalWrite(mot, HIGH); 62 digitalWrite(mota, HIGH); 63 } 64 else if(mot_count == 3){ 65 //Serial.println("3"); 66 digitalWrite(mot, LOW); 67 digitalWrite(mota, HIGH); 68 delay(500); 69 digitalWrite(mot, HIGH); 70 digitalWrite(mota, HIGH); 71 } 72 else if(mot_count == 4){ 73 //Serial.println("4"); 74 mot_count = 0; 75 digitalWrite(mot, LOW); 76 digitalWrite(mota, HIGH); 77 delay(500); 78 digitalWrite(mot, HIGH); 79 digitalWrite(mota, HIGH); 80 } 81} 82void setup() { 83 pinMode(sensor_pin,INPUT); 84 pinMode(sensor,INPUT); 85 pinMode(smoke,INPUT); 86 pinMode(sw1,INPUT); 87 pinMode(sw2,INPUT); 88 pinMode(sw3,INPUT); 89 pinMode(mot, OUTPUT); 90 pinMode(mota, OUTPUT); 91 pinMode(solenoid, OUTPUT); 92 pinMode(forka, OUTPUT); 93 pinMode(forkb, OUTPUT); 94 pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output 95 pinMode(echoPin, INPUT); // Sets the echoPin as an Input 96 Serial.begin(9600); // Starts the serial communication 97 digitalWrite(solenoid, LOW); 98 digitalWrite(forka, LOW); 99 digitalWrite(forkb, LOW); 100 //Serial.print("test"); 101} 102 103void loop() { 104 if(digitalRead(sw)==1 && a==0){ 105 Serial.print("a"); 106 a=1; 107 digitalWrite(solenoid, HIGH); 108 digitalWrite(forka, HIGH); 109 digitalWrite(forkb, LOW); 110 delay(200); 111 digitalWrite(forka, LOW); 112 digitalWrite(forkb, LOW); 113 } 114 if(digitalRead(sw)==1 && a==1){ 115 Serial.print("b"); 116 a=0; 117 digitalWrite(solenoid, LOW); 118 digitalWrite(forka, LOW); 119 digitalWrite(forkb, HIGH); 120 delay(200); 121 digitalWrite(forka, LOW); 122 digitalWrite(forkb, LOW); 123 } 124 output_value= analogRead(sensor_pin); 125 output_value = map(output_value,600,250,10,99); 126 //delay(1000); 127 vout=analogRead(sensor); 128 129 if(digitalRead(sw2)==1){ 130 sw_o=2; 131 tempc = 00.00; 132 } 133 else{ 134 tempc=(vout*250)/1023; 135 } 136 //digitalWrite(mot, LOW); 137 digitalWrite(trigPin, LOW); 138 delayMicroseconds(2); 139 // Sets the trigPin on HIGH state for 10 micro seconds 140 digitalWrite(mot, HIGH); 141 digitalWrite(mota, HIGH); 142 digitalWrite(trigPin, HIGH); 143 delayMicroseconds(10); 144 digitalWrite(trigPin, LOW); 145 // Reads the echoPin, returns the sound wave travel time in microseconds 146 duration = pulseIn(echoPin, HIGH); 147 // Calculating the distance 148 distanceCm= duration*0.034/2; 149 distanceInch = duration*0.0133/2; 150 if(digitalRead(smoke)==1){ 151 smk=1; 152 //delay(1000); 153 } 154 else{ 155 smk=0; 156 } 157 if(digitalRead(sw1)==1){ 158 sw_o=1; 159 digitalWrite(mot, LOW); 160 digitalWrite(mota, LOW); 161 } 162 if(digitalRead(sw2)==1){ 163 sw_o=2; 164 } 165 166 else{ 167 sw_o=0; 168 } 169 if(distanceCm <=20){ 170 digitalWrite(mot, LOW); 171 digitalWrite(mota, LOW); 172 delay(2000); 173 distanceCm=10; 174 } 175 else if(distanceCm >20 && distanceCm <= 50){ 176 digitalWrite(mot, LOW); 177 digitalWrite(mota, LOW); 178 delay(200); 179 digitalWrite(mot, HIGH); 180 digitalWrite(mota, HIGH); 181 delay(200); 182 } 183 else if (distanceCm>50){ 184 digitalWrite(mot, HIGH); 185 digitalWrite(mota, HIGH); 186 distanceCm=99; 187 } 188 delay(10); 189 if( nextSwitchTime < millis() ) 190 { 191 send_data(); 192 nextSwitchTime = millis() + 1000; 193 } 194 195 if( nextMotTime < millis() ) 196 { 197 change_mot(); 198 nextMotTime = millis() + 5000; 199 } 200 //delay(1000); 201 //Serial.println(float(distanceCm)); 202} 203 204 205
Comments
Only logged in users can leave comments