Skip to main content

How to connect soil moisture sensor to android mobile via arduino

What is IOT ?


Over the past few years Internet of thing has made a revelation in IT, Operations of the techniques are made of connecting objects to a network to transfer data without human to human or human-computer interaction, IoT is an interdisciplinary field, which requires working with electronics and sensors to capture data from physical objects, computer networking for data transfer and IT skills for building meaningful applications.

In this blog I will introduce how to connect soil moisture sensor to Arduino board and receive the data via a HC-006 Bluetooth module.

Required Items

  • Arduino Board(UNO)
  • Soil Moisture Sensor
  • Bread Board
  • Bluetooth Module(HC-006)
  • Jumper Cables
Bread board

Arduino Board(UNO)

soil moisture sensor

Bluetooth Module

Check out the video in the link for better understanding how these devices are assembled and connected  https://www.youtube.com/watch?v=Pm83L104naY

Check out the code below how to receive the data via Bluetooth module 

#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11); // RX | TX
#define ledPin 7

char c = ' ';
int x;
boolean get1 = true;
const int buttonPin = 2;
const int led = 8;
String color;
String state;
boolean call;
boolean standS = true;
boolean standS1 = true;

void setup() {
  Serial.begin(9600); // Default communication rate of the Bluetooth module
  BTserial.begin(9600);  
  Serial.println("Arduino is Ready");
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  pinMode(buttonPin, INPUT);
  pinMode(led, OUTPUT);
  digitalWrite(led, HIGH);
}

void Bluetooth (){
  
  while (BTserial.available())
    {  
      delay(10);
        c = BTserial.read();
        color += c;   
        if(color=="on"){
          call = true;
        }
    }
      if (color.length() >0)
       {
        
        if(call){
          while(get1){
          digitalWrite(ledPin,HIGH);
          delay(200);
          digitalWrite(ledPin,LOW);
          delay(200);         
         c = BTserial.read();
         Serial.print(c);
//         BTserial.flush();
         if(c == 'f'){
//          BTserial.flush();
          break;
         }
         c=' ';
         
          }
//        }else if(color == "off"){
//          get = false;
//          digitalWrite(ledPin, LOW);
//          delay(20);
//        }
    }
 
color ="";
}
}

void loop() {
  
  Bluetooth();
  stand();

}

void stand(){
  int butt = digitalRead(buttonPin);
  int LED = digitalRead(led);

  if(butt == HIGH){
    digitalWrite(led,LOW);
    standS1 = true;
    if(standS){
    Serial.print("yes");
    BTserial.print("yes");
    delay(100);
    }
      standS=false;
    
    
  }else{
    digitalWrite(led,HIGH);
    standS=true;
    if(standS1){
    Serial.print("no");
    BTserial.print("no");
    delay(100);
    }
    standS1=false;
  }

//  if(digitalRead(buttonPin)==HIGH && standS == true){
//    
//    digitalWrite(led,LOW);
//
//    state = "yes";
//    BTserial.print(state);
//    delay(1000);
//
//    BTserial.flush();
//
//
//  }else{
//    standS = false;
//     digitalWrite(led,HIGH);
//
//
//    delay(1000);
//
//
//    BTserial.flush();
//   
//  }

}



Comments