element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Design For A Cause 2021
  • Challenges & Projects
  • Design Challenges
  • Design For A Cause 2021
  • More
  • Cancel
Design For A Cause 2021
Blog Remote Agriculture Solution #08: Linking Everything to Arduino Nano 33 IOT
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: aaryan2134
  • Date Created: 27 May 2021 11:41 PM Date Created
  • Views 848 views
  • Likes 3 likes
  • Comments 0 comments
  • arduino_nano_33_iot
  • iot system
  • arduino nano 33 iot
  • design for a cause design challenge
  • design_for_a_cause_2021
  • agriculture
Related
Recommended

Remote Agriculture Solution #08: Linking Everything to Arduino Nano 33 IOT

aaryan2134
aaryan2134
27 May 2021

Remote Agriculture Solution

Blog Links:

#01: Introduction

#02: Components and Design Structure

#03: Setting up the AgroBot

#04: Setting up Arduino Nano 33 IOT

#05: Monitoring System

#06: Irrigation System

#07: Pest Control System

#08: Linking Everything to Arduino Nano 33 IOT

#09: Time to See the Work in Action

#10: Future Improvements

 

In this blog, we will link all individual components to Arduino Nano 33 IOT and setup the remote control server.

 

Finally, all the code and wiring has been completed. I have uploaded the same here as well as on Github. The pictures have been added so that you can see how the setup can be done on both hardware and software end.

 

The Arduino Uno code has been changed a bit. I have had to remove the servo as I was left with no space on my chassis. So, I have removed that code and the servo. Due to that, the bot will always more left when it encounters an obstacle(or right if you would like to change it). I completely forgot about the size before starting and getting a new chassis right now would be a little too difficult. Any case, we worked with both things so it was fun.

 

The Arduino Nano 33 IOT code is same as in the last blog as everything was linked in that post.

 

The working video will be shown in the next Blog. Hope you are as excited as me!!!

 

Wiring:

image

image

image

 

Code:

AgroBot final code(for Arduino Uno):

https://github.com/aaryan2134/Remote-Agriculture-Solution/tree/main/Final_Arduino_Uno_Code_-_Agrobot

 

//Remote Agriculture Solution  
// Autonomous Agro Bot  
/*          Arduino based bot for automatic movement around the farm 
  Dev: Aaryan Arora 
  For Design For A Cause 2021 
*/
//Libraries
#include <Servo.h>
int TurnDelay = 1100;
#define TRIGGER_PIN1  8  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN1     12  // Arduino pin tied to echo pin on the ultrasonic sensor.
long duration, cm;


//Constants
const int motorA1 = 6;    //motor A positive (+) pin to pin 6 (PWM) (from L293D module!)
const int motorA2 = 9;        //motor A negative (-) pin to pin 9 (PWM)
const int motorB1 = 10;   //motor B positive (+) pin to pin 10 (PWM)
const int motorB2 = 11;   //motor B negative (-) pin to pin 11 (PWM)


//Variables
int distance;         //Variable to store distance from an object
int checkRight;       //To store right distance
int checkLeft;        //To store left distance


//declaring functions
void forward();
void backward();
void stop();
void left();
void right();
int ultraFront();


void setup()
{
  //Setting Motor control pins to output
  pinMode(motorA1, OUTPUT);
  pinMode(motorA2, OUTPUT);
  pinMode(motorB1, OUTPUT);
  pinMode(motorB2, OUTPUT);
  //Setting pins from Ultrasonic Sensor
  pinMode(TRIGGER_PIN1, OUTPUT);
  pinMode(ECHO_PIN1, INPUT);
}


void loop()
{


  //Read distance...
  distance = ultraFront();
  
  //Check for objects...
  if (distance > 15) {
    forward(); //All clear, move forward!
  }


  else
  {
    left(); //turn left otherwise
  }

}


// functions for various type of motions
void forward() {
  digitalWrite(motorA1, HIGH);
  digitalWrite(motorA2, LOW);
  digitalWrite(motorB1, HIGH);
  digitalWrite(motorB2, LOW);
}
void backward() {
  digitalWrite(motorA1, LOW);
  digitalWrite(motorA2, HIGH);
  digitalWrite(motorB1, LOW);
  digitalWrite(motorB2, HIGH);
}
void right() {
  digitalWrite(motorA1, HIGH);
  digitalWrite(motorA2, LOW);
  digitalWrite(motorB1, LOW);
  digitalWrite(motorB2, HIGH);
}
void left() {
  digitalWrite(motorA1, LOW);
  digitalWrite(motorA2, HIGH);
  digitalWrite(motorB1, HIGH);
  digitalWrite(motorB2, LOW);
}


void stop() {
  digitalWrite(motorA1, LOW);
  digitalWrite(motorA2, LOW);
  digitalWrite(motorB1, LOW);
  digitalWrite(motorB2, LOW);
}


//for measuring distance using ultrasonic sensor
int ultraFront() {
  
  digitalWrite(TRIGGER_PIN1, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGGER_PIN1, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGGER_PIN1, LOW);


  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(ECHO_PIN1, INPUT);
  duration = pulseIn(ECHO_PIN1, HIGH);
  
  // Convert the time into a distance
  cm = (duration / 2) * 29.1;   // Divide by 29.1 
  return cm;
}

 

Monitoring System(for Arduino Nano 33 IOT):

https://github.com/aaryan2134/Remote-Agriculture-Solution/tree/main/Final_Arduino_Nano_33_IOT_Code_-_monitoring_system

 

//Remote Agriculture Solution
//Monitoring System
/*          Using Arduino Nano 33 IOT to monitor farm conditions using IOT
  Dev: Aaryan Arora
  For Design For A Cause 2021
*/


//libraries
#define BLYNK_PRINT SerialUSB
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
#include <EduIntro.h>
/* Used this library for getting temperature reading from DHT 11
  Can be downloaded from here or arduino library manager
  https://github.com/arduino/EduIntro
*/


//for water level
#define TRIGGER_PIN1  8  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN1     12  // Arduino pin tied to echo pin on the ultrasonic sensor.


//for pesticide level
#define TRIGGER_PIN2  9  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN2     10  // Arduino pin tied to echo pin on the ultrasonic sensor.




//water pump
const int motorA1 = 2;    //motor A positive  pin to pin 6 (PWM) (from L293D module!)
const int motorA2 = 3;        //motor A negative  pin to pin 9 (PWM)




//pesticide pump
const int motorB1 = 5;   //motor B positive  pin to pin 10 (PWM)
const int motorB2 = 6;   //motor B negative  pin to pin 11 (PWM)




DHT11 dht11(D7);  // creating the object sensor on pin 'D7'
int water_level(); //to measure level of water in container
int pesticide_level(); //to measure level of pesticide in container




//Use your authorization token after creating new project in Blynk App
char auth[] = "";


// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";




//constants
int LDRpin = A0; // select the input pin for LDR
int LDRvalue = 0; // variable to store the value coming from the LDR
int lux = 0;         //to store the intensity of light in lux
long duration, cm;
int soil_pin = A2; //soil sensor pin
int moisture_value ; //storing result from soil sensor


BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.

  //for spraying pesticide when user calls it
  int value;
  BLYNK_WRITE(V2)
  {
    value = param.asInt();
  if (value == 1)
  {
    digitalWrite(motorB1, HIGH);
    digitalWrite(motorB2, LOW);
    delay(30);
    digitalWrite(motorB1, LOW);
    digitalWrite(motorB2, LOW);
  }
  }


void myTimerEvent()
{
  //starting the DHT 11 sensor
  dht11.update();


  //Getting the LDR analog value
  LDRvalue = analogRead(LDRpin);
  //Using the formula for conversion from analog value to lux
  lux = (512000 / LDRvalue) - 500;


  //calculating moisture percentage using analog value of the sensor
  moisture_value = analogRead(soil_pin);
  //converting to percentage
  moisture_value = (moisture_value * 100) / 1023;
  //using formula to account for resistance
  moisture_value = 35 + (100 - moisture_value);


  //sending all values to the Blynk App using Virtual Pins
  Blynk.virtualWrite(V5, lux);
  Blynk.virtualWrite(V6, dht11.readCelsius());
  Blynk.virtualWrite(V7, dht11.readHumidity());
  Blynk.virtualWrite(V8, moisture_value);
  Blynk.virtualWrite(V0, water_level());
  Blynk.virtualWrite(V1, pesticide_level());


}
void setup() {
  //Setting pins from Ultrasonic Sensor
  pinMode(TRIGGER_PIN1, OUTPUT);
  pinMode(ECHO_PIN1, INPUT);


  SerialUSB.begin(9600);
  Blynk.begin(auth, ssid, pass);
  // Setup a function to be called every 5 seconds
  timer.setInterval(5000L, myTimerEvent);
}


void loop() {
  Blynk.run();
  timer.run(); // Initiates BlynkTimer


//for watering the crop below 60 moisture level
if(moisture_value < 60) 
  { 
    digitalWrite(motorA1,HIGH); 
    digitalWrite(motorA2,LOW); 
    delay(100); 
    digitalWrite(motorA1,LOW); 
    digitalWrite(motorA2,LOW); 
  } 
  
}


int water_level() {


  digitalWrite(TRIGGER_PIN1, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGGER_PIN1, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGGER_PIN1, LOW);


  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(ECHO_PIN1, INPUT);
  duration = pulseIn(ECHO_PIN1, HIGH);


  // Convert the time into a distance
  cm = (duration * 0.0348) / 2;


//sending email when water level falls below 3
  if (cm < 3)
  {
    Blynk.email("Water level alert", "Fill water in the container");
  }
  return cm;


}


int pesticide_level() {


  digitalWrite(TRIGGER_PIN2, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGGER_PIN2, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGGER_PIN2, LOW);


  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(ECHO_PIN2, INPUT);
  long duration = pulseIn(ECHO_PIN2, HIGH);


  // Convert the time into a distance
  long cm = (duration * 0.0348) / 2;


//sending email when pesticide level falls below 4
  if (cm < 4)
  {
    Blynk.email("Pesticide level alert", "Fill pesticide in the container");
  }
  return cm;




}

 

Pictures:

imageimageimage

image

 

Connect with Me:

aaryan2134@gmail.com

Github - aaryan2134

My website

Linkedin

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube