/* This program blinks pin 13 of the Arduino (the built-in LED)
*/

void setup()
{
pinMode(13, OUTPUT);
}

void loop()
{
// turn the LED on (HIGH is the voltage level)
digitalWrite(13, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
// turn the LED off by making the voltage LOW
digitalWrite(13, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}

void setup()
{
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
}
void loop(){
digitalWrite(8, HIGH);
delay(100); // Wait for 100 millisecond(s)
digitalWrite(8, LOW);
delay(100); // Wait for 100 millisecond(s)
digitalWrite(9, HIGH);
delay(100); // Wait for 100 millisecond(s)
digitalWrite(9, LOW);
delay(100); // Wait for 100 millisecond(s)
digitalWrite(10, HIGH);
delay(100); // Wait for 100 millisecond(s)
digitalWrite(10, LOW);
delay(100); // Wait for 100 millisecond(s)
digitalWrite(11, HIGH);
delay(100); // Wait for 100 millisecond(s)
digitalWrite(11, LOW);
delay(100); // Wait for 100 millisecond(s)
digitalWrite(12, HIGH);
delay(100); // Wait for 100 millisecond(s)
digitalWrite(12, LOW);
delay(100); // Wait for 100 millisecond(s)
}

void setup()
{
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
}
void loop()
{
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
delay(5000); // Wait for 5000 millisecond(s)
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
delay(2000); // Wait for 2000 millisecond(s)
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
delay(5000); // Wait for 5000 millisecond(s)
}

int Flame = 0;

void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}

void loop()
{
Flame = analogRead(A0);
delay(1000); // Wait for 1000 millisecond(s)
Serial.println(Flame);
if (Flame >= 300) {
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
} else {
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}
}

int x = 0;
int val = 0;

void setup()
{
Serial.begin(9600);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}

void loop()
{
val = 0.01723 * readUltrasonicDistance(3, 2);
Serial.println(val);
if (val< 50) {
digitalWrite(4, HIGH);
} else {
digitalWrite(4, LOW);
}
if (val< 40) {
digitalWrite(5, HIGH);
} else {
digitalWrite(5, LOW);
}
if (val< 30) {
digitalWrite(6, HIGH);
} else {
digitalWrite(6, LOW);
}
if (val< 20) {
digitalWrite(7, HIGH);
} else {
digitalWrite(7, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}

long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(5);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

// Define pin numbers

int ldrPin = A0; // LDR is connected to analog pin A0

int ledPin = 13;  // LED is connected to digital pin 8

void setup(){

  pinMode(ledPin, OUTPUT); // Set the LED pin as an output

  pinMode(ldrPin, INPUT);  // Set the LDR pin as an input

  Serial.begin(9600);      // Start serial communication at 9600 baud rate

}

void loop(){

  int ldrStatus = analogRead(ldrPin); // Read the value from the LDR

  Serial.print(“LDR Value: “);

  Serial.println(ldrStatus); // Print the LDR value to the serial monitor

  if(ldrStatus>200){

    digitalWrite(ledPin, HIGH); // Turn on the LED

  }

else{

    digitalWrite(ledPin, LOW); // Turn off the LED

  }

  delay(5000); // Delay for better serial port visualization

}

#include <Servo.h>

long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

Servo servo_9;

void setup()
{
servo_9.attach(9, 500, 2500);
}

void loop()
{
if (0.01723 * readUltrasonicDistance(7, 8) < 15) {
servo_9.write(90);
delay(3000); // Wait for 3000 millisecond(s)
} else {
servo_9.write(0);
}
}

#include<Servo.h>

long readUltrasonicDistance(int triggerPin, int echoPin)

{

pinMode(triggerPin, OUTPUT); // Clear the trigger

digitalWrite(triggerPin, LOW);

delayMicroseconds(2);

// Sets the trigger pin to HIGH state for 10 microseconds

digitalWrite(triggerPin, HIGH);

delayMicroseconds(10);

digitalWrite(triggerPin, LOW);

pinMode(echoPin, INPUT);

// Reads the echo pin, and returns the sound wave travel time in microseconds

return pulseIn(echoPin, HIGH);

}

Servo servo_5;

void setup()

{

servo_5.attach(5, 500, 2500);

}

void loop()

{

if(0.01723 * readUltrasonicDistance(7, 6)<15){

servo_5.write(90);

delay(3000); // Wait for 3000 millisecond(s)

}else{

servo_5.write(0);

} }

#include <Servo.h>

long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

Servo servo_9;

void setup()
{
servo_9.attach(9, 500, 2500);
}

void loop()
{
if (0.01723 * readUltrasonicDistance(7, 8) < 15) {
servo_9.write(90);
delay(3000); // Wait for 3000 millisecond(s)
} else {
servo_9.write(0);
}
}

#include <Servo.h>

int ultrasonicsensor = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

Servo servo_9;

void setup()
{
Serial.begin(9600);
servo_9.attach(9, 500, 2500);
}
void loop()
{
ultrasonicsensor = 0.01723 * readUltrasonicDistance(12, 11);
Serial.println(ultrasonicsensor);
if (ultrasonicsensor > 80) {
servo_9.write(90);
} else {
servo_9.write(0);
}
if (ultrasonicsensor == 80) {
servo_9.write(75);
} else {
servo_9.write(0);
}
if (ultrasonicsensor < 80) {
servo_9.write(45);
} else {
servo_9.write(0);
}
delay(10); // Delay a little bit to improve simulation performance
}

int distance = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

void setup()
{
pinMode(6, OUTPUT);
pinMode(11, OUTPUT);
}

void loop()
{
distance = 0.01723 * readUltrasonicDistance(4, 5);
if (distance < 61) {
digitalWrite(6, HIGH);
digitalWrite(11, HIGH);
} else {
digitalWrite(6, LOW);
digitalWrite(11, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}

int x = 0;
int val = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

void setup()
{
Serial.begin(9600);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}

void loop()
{
val = 0.01723 * readUltrasonicDistance(3, 2);
Serial.println(val);
if (val< 50) {
digitalWrite(4, HIGH);
} else {
digitalWrite(4, LOW);
}
if (val< 40) {
digitalWrite(5, HIGH);
} else {
digitalWrite(5, LOW);
}
if (val< 30) {
digitalWrite(6, HIGH);
} else {
digitalWrite(6, LOW);
}
if (val< 20) {
digitalWrite(7, HIGH);
} else {
digitalWrite(7, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}

Junior Farmer SMART FARM DIY KIT ( 5 Projects) – Check with Math Junior for project videos

int moisture_data = 0;

void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
pinMode(6, OUTPUT);
pinMode(12, OUTPUT);
pinMode(3, OUTPUT);
}

void loop()
{
moisture_data = analogRead(A0);
Serial.println(moisture_data);
if (moisture_data > 22) {
digitalWrite(6, HIGH);
digitalWrite(12, HIGH);
digitalWrite(3, LOW);
} else {
digitalWrite(6, LOW);
digitalWrite(12, LOW);
digitalWrite(3, HIGH);
}
delay(10); // Delay a little bit to improve simulation performance
}

int val = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

void setup()
{
Serial.begin(9600);
pinMode(8, OUTPUT);
pinMode(3, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}

void loop()
{
val = 0.01723 * readUltrasonicDistance(6, 5);
Serial.println(val);
if (val >= 20) {
digitalWrite(8, LOW);
digitalWrite(3, HIGH);
} else {
digitalWrite(8, HIGH);
}
if (val >= 60) {
digitalWrite(9, LOW);
digitalWrite(3, HIGH);
} else {
digitalWrite(9, HIGH);
}
if (val >= 90) {
digitalWrite(10, LOW);
} else {
digitalWrite(10, HIGH);
digitalWrite(3, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}

#include<Servo.h>

int moisture = 0;

Servo servo_7;

void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
servo_7.attach(7, 500, 2500);

moisture = (-40 + 0.488155 * (analogRead(A0) – 20));
Serial.println(moisture);
if (moisture <= 100) {
servo_7.write(90);
} else {
servo_7.write(0);
}
}

void loop()
{
delay(10); // Delay a little bit to improve simulation performance
}

int soundSensor=2;
int LED=13;
boolean LEDStatus=false;

void setup() {
pinMode(soundSensor,INPUT);
pinMode(LED,OUTPUT);

}

void loop() {

int SensorData=digitalRead(soundSensor);
if(SensorData==1){

if(LEDStatus==false){
LEDStatus=true;
digitalWrite(LED,HIGH);
}
else{
LEDStatus=false;
digitalWrite(LED,LOW);
}

}
}

//the time we give the sensor to calibrate (10-60 secs according to the datasheet)

int calibrationTime =5;       

//the time when the sensor outputs a low impulse

long unsigned int lowIn;        

//the amount of milliseconds the sensor has to be low

//before we assume all motion has stopped

long unsigned int pause = 5000; 

boolean lockLow = true;

boolean takeLowTime; 

int pirPin = 7;    //the digital pin connected to the PIR sensor’s output

int ledPin = 10;    //the digital pin connected to the LED output

int Buzzer = 13;   //the digital pin connected to the BUZZER output

/////////////////////////////

//SETUP

void setup(){

  Serial.begin(9600);

  pinMode(pirPin, INPUT);

  pinMode(ledPin, OUTPUT);

  pinMode(Buzzer, OUTPUT);

  digitalWrite(pirPin, LOW);

  //give the sensor some time to calibrate

  Serial.print(“calibrating sensor “);

    for(int i = 0; i < calibrationTime; i++){

      Serial.print(“.”);

      delay(1000);

      }

    Serial.println(” done”);

    Serial.println(“SENSOR ACTIVE”);

    delay(50);

  }

////////////////////////////

//LOOP

void loop(){

     if(digitalRead(pirPin) == HIGH){

       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state

       tone(Buzzer,1000);

       if(lockLow){ 

         //makes sure we wait for a transition to LOW before any further output is made:

         lockLow = false;           

         Serial.println(“—“);

         Serial.print(“motion detected at “);

         Serial.print(millis()/1000);

         Serial.println(” sec”);

         delay(50);

         }        

         takeLowTime = true;

       }

     if(digitalRead(pirPin) == LOW){      

       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

       noTone(Buzzer);

       if(takeLowTime){

        lowIn = millis();          //save the time of the transition from high to LOW

        takeLowTime = false;       //make sure this is only done at the start of a LOW phase

        }

       //if the sensor is low for more than the given pause,

       //we assume that no more motion is going to happen

       if(!lockLow && millis() – lowIn > pause){ 

           //makes sure this block of code is only executed again after

           //a new motion sequence has been detected

           lockLow = true;                       

           Serial.print(“motion ended at “);      //output

           Serial.print((millis() – pause)/1000);

           Serial.println(” sec”);

           delay(50);

           }

       }

  }

#include<LiquidCrystal.h>

char text1[]=”hello world”;
char text2[] =”math junior”;

LiquidCrystallcd(7,6,5,4,3,2);

void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(text1);
lcd.setCursor(0,1);
lcd.print(text2);
}

void loop()
{

}

#include<Servo.h>

Servo tap_servo;
int servo = 9;
intval;
void setup()
{
pinMode(6,INPUT);
pinMode(7,INPUT);
pinMode(8,INPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
tap_servo.attach(9);
}

void loop()
{
val = digitalRead(8);

if (val==0)
{
tap_servo.write(0);
delay(3000);
tap_servo.write(180);
}
if(digitalRead(6)== HIGH &&digitalRead(7)== HIGH &&digitalRead(8)== HIGH )
{
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);

}

else if(digitalRead(6)== HIGH &&digitalRead(7)== HIGH)
{
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
}

else if(digitalRead(7)== HIGH &&digitalRead(8)== HIGH)

{
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}
else if(digitalRead(6)== HIGH &&digitalRead(7)== HIGH)
{
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
}

else if(digitalRead(6)== HIGH)
{
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
}

else if(digitalRead(7)== HIGH)
{
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);

}

else if(digitalRead(8)== HIGH)
{
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);

}
else {

digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);

}

}

#include “LiquidCrystal.h”

LiquidCrystallcd(8,7,6,5,4,3);
intsensorPin = 0;

void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
}

void loop()
{

int reading = analogRead(sensorPin);

float voltage = reading * 4.68;
voltage /= 1024.0;

float temperatureC = (voltage – 0.5) * 100;
Serial.print(temperatureC);
Serial.println(” degrees C”);

lcd.setCursor(0,0);
lcd.print(“Temperature Value “);
lcd.setCursor(0,1);
lcd.print(” degrees C”);
lcd.setCursor(11,1);
lcd.print(temperatureC);

delay(100);
}

#include<LiquidCrystal.h>
LiquidCrystallcd(12,11,5,4,3,2);



#define trigpin1 9
#define echopin1 8
#define first_led A0

#define trigpin2 5
#define echopin2 6
#define sec_led A1

//used variales

long duration,distance, sensor1, sensor2;

char data;
String SerialData=””;

//setup

void setup()
{
 
 
  lcd.begin(16, 2);
  Serial.begin(9600);
 
 
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(” Dry bin “);
  lcd.setCursor(0,1);
  lcd.print(” Wet bin “);
  delay(4000);
  lcd.clear();
 
 
 
  pinMode(trigpin1,OUTPUT);
  pinMode(echopin1,INPUT);
  pinMode(first_led,OUTPUT);
 
  pinMode(trigpin2,OUTPUT);
  pinMode(echopin2,INPUT);
  pinMode(sec_led,OUTPUT);
 
  digitalWrite(first_led,LOW);
  digitalWrite(sec_led,LOW);
}

void loop()
{
  SonarSensor(trigpin1,echopin1);
  sensor1=distance;
 
  SonarSensor(trigpin2,echopin2);
  sensor2=distance;
 
  while(Serial.available())
  {
   
    delay(1000);
    data=Serial.read();
    SerialData+=data;
   
  }
  if(SerialData==”display distance”)
  {
   Serial.println(“distance of 1st sensor”);
   Serial.print(“sensor”);
   Serial.print(“cm”);
   //2
   
   Serial.println(“distance of 2 sensor”);
   Serial.print(“sensor2”);
   Serial.print(“cm”);
   
  }
  SerialData=””;
 
  if(sensor1 <=20)
  {
    digitalWrite(first_led,LOW);
    lcd.setCursor(2,0);
    lcd.print(“EMPTY”);
    delay(1000);
    lcd.clear();
   
  }
 
  else
  {
    digitalWrite(first_led,HIGH);
    lcd.setCursor(9,0);
    lcd.print(“EMPTY”);
    delay(1000);
    lcd.clear();
   
  }
 
  if(sensor2 <= 20)
  {
    digitalWrite(sec_led,LOW);
   
    lcd.setCursor(2,1);
    lcd.print(“EMPTY”);
    delay(1000);
    lcd.clear();
    }
 
  else{
    digitalWrite(sec_led,HIGH);
    lcd.setCursor(9,1);
    lcd.print(” EMPTY”);
    delay(1000);
    lcd.clear();
   
   
  }
 
 
}
void SonarSensor(inttrigpinsensor, intechopinsensor)
 {
   
digitalWrite(trigpinsensor,LOW);
delay(1000);
digitalWrite(trigpinsensor,HIGH);
delay(1000);
digitalWrite(trigpinsensor,LOW);

duration=pulseIn(echopinsensor,HIGH);
distance=(duration/2)/29.1;


}

#include<LiquidCrystal.h>

LiquidCrystallcd(12,11,5,4,3,2);
int in = 8;
int out = 9;
int led = 13;
intin_val;
intout_val;
int count=0;

void setup()
{

pinMode(in, INPUT);
pinMode(out, INPUT);
pinMode(led, OUTPUT);
lcd.begin(16, 2);

}

void loop()
{

// put your main code here, to run repeatedly:
in_val=digitalRead(in);
out_val=digitalRead(out);

if(in_val==LOW) {
count++;
lcd.setCursor(0,0);
lcd.print(“no of people”);
lcd.setCursor(0,1);
lcd.print(count);
delay(1000);
lcd.clear();

}

else if(out_val == LOW){
count–;
lcd.setCursor(0,0);
lcd.print(“no of people”);
lcd.setCursor(0,1);
lcd.print(count);
delay(1000);
lcd.clear();
}

else if(count < 0){
digitalWrite(led,LOW);
lcd.setCursor(0,0);
lcd.print(“no one in room”);
lcd.setCursor(0,1);
lcd.print(“led is off”);
delay(1000);
lcd.clear();
}
else{
digitalWrite(led,HIGH);
}

}

char Incoming_value = 0;

void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
}

void loop()
{
if(Serial.available() > 0)
{
Incoming_value = Serial.read();

if(Incoming_value == ‘1’)
digitalWrite(13, HIGH);
else if(Incoming_value == ‘0’)
digitalWrite(13, LOW);
}
}

How to Setup Bluetooth App on your smart phone

  • Install “Arduino Bluetooth Controller” app on your phone.
  • Enable Bluetooth on your smartphone or computer.
  • Search for nearby Bluetooth devices and pair with the Bluetooth module connected to the Arduino board. The default Bluetooth name for HC-05/HC-06 modules is usually “HC-05” or “HC-06”.
  • Once paired, you can use a Bluetooth terminal app on your smartphone or a serial monitor on your computer to send commands to the Arduino board.
  • Now You can enter your command in the terminal. If you send the value “1” to the Bluetooth, LED will be ON.
  • If you type the value “0” and send to Bluetooth, the LED will go OFF.
  • Not only with 1 & 0, you can configure this for any 2 commands like: “on” & “off”, “yes” & “no”, “0” & “1” And so on.

void setup()
{
pinMode(9,OUTPUT);

Serial.begin(9600);
}
void On()
{
digitalWrite(9,HIGH);
}
void Off()
{
digitalWrite(9,LOW);

}
void loop()
{
int state=Serial.read();
if(state==’A’)
{
On();
delay(2);
}
if(state==’B’)
{
Off();
delay(2);
}
}

How to Setup Bluetooth App on your smart phone

  • Install “Arduino Bluetooth Controller” app on your phone.
  • Enable Bluetooth on your smartphone or computer.
  • Search for nearby Bluetooth devices and pair with the Bluetooth module connected to the Arduino board. The default Bluetooth name for HC-05/HC-06 modules is usually “HC-05” or “HC-06”.
  • Once paired, you can use a Bluetooth terminal app on your smartphone or a serial monitor on your computer to send commands to the Arduino board.
  • Now. You can enter your command in the terminal. If you send the value “A” to the Bluetooth, PUMP will be ON.
  •  If you type the value “B” and send to Bluetooth, the PUMP will go OFF
  • Not only with A & B, you can configure for any 2 commands like: “on” & “off”, “yes” & “no”, “0” & “1” And so on

void setup()
{
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
Serial.begin(9600);
}
void forward()
{
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
void backward()
{
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
void left()
{
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
void right()
{
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
void stop0()
{
digitalWrite(9,LOW);
digitalWrite(8,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}
void loop()
{
int state = Serial.read();

if (state==’F’)

{
forward();
delay(2);
}
if (state==’L’)

{
left();
delay(2);
}
if (state==’R’)

{
right();
delay(2);
}
if (state==’B’)

{
backward();
delay(2);
}
if (state==’S’)
{
stop0();
delay(2);
}
}

How to Setup Bluetooth App on your smart phone

  1. Download and install Bluetooth electronics application in your smart phone, turn ON mobile Bluetooth and Select desired Blue tooth device and pair it.
  2. Now open Bluetooth electronics application select empty panel and press edit.
  3. Next click on “Buttons” to choose arrow keys as required, then edit the keys as F, B, R, L, S (Forward, Backward, Right, Left, Stop) from the key bar.
  4. Now choose the respective keys & click on edit &mention the same letters for both press text & release text as you mentioned in the coding(F, B, R, L, S). Do the same procedure for all the selected keys.
  5. Once the panel is ready, then select the same panel and click on “connect” and select “bluetooth classic”, thenclick on “next”.
  6. Now, on bluetooth classic panel select “discover” and choose “HC-05 device” and pair it. After pairing select the same device and connect. Then click on “Done”.
  7. Now click on “Run” and Control your car with the help of arrow keys.

#define LS 2 // left sensor

#define RS 3 // right sensor

#define LM 19

#define LM 28

#define RM 14 #defineRM25

voidsetup()
{
pinMode(LS, INPUT);
pinMode(RS, INPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
voidloop()
{
if(digitalRead(LS)&&digitalRead(RS)) // Move Forward on line 1 – 1
{
digitalWrite(9,LOW);
digitalWrite(8, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
if(digitalRead(LS)&& !(digitalRead(RS))) // turn left by rotationg left motors in //forward and right ones in backward direction 1-0
{
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
if(!(digitalRead(LS))&&digitalRead(RS)) // Turn right by rotating right motors in //forward and left ones in backward direction 0 – 1
{
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}

if(!(digitalRead(LS))&& !(digitalRead(RS))) // Finish line, stop both the motors 0 //- 0
{
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
}

5. Obstacle Avoiding Robot

#include<Servo.h>

constinttrigPin = 12;
constintechoPin = 11;

constintservoPin=13;

Servo myservo;

// defines variables
long duration;
int distance;
intdistance_f;
intdistance_r;
intdistance_l;
intmaxLowDistance=50;

voidsetup(){
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);

myservo.attach(servoPin);
myservo.write(90);

Serial.begin(9600);
}
voidloop(){
distance_f=ping();
if(distance_f>maxLowDistance){
front();
delay(300);
}else{
Break();
get_Distance();
if(distance_r>maxLowDistance){
right();
delay(300);
front();
}elseif(distance_l>maxLowDistance){
left();
delay(300);
front();
}else{
back();
delay(300);
Break();
}

}
}
voiddisplayDistance(){
Serial.print(“Right Distance : “);
Serial.print(distance_r);
Serial.println(“”);
Serial.print(“Front Distance : “);
Serial.print(distance_f);
Serial.println(“”);
Serial.print(“Left Distance : “);
Serial.print(distance_l);
Serial.println(“”);

}
voidfront(){
Serial.println(“Forward Move”);
digitalWrite(9,HIGH);
digitalWrite(8,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);

}
voidback(){
Serial.println(“Back Move”);
digitalWrite(9,LOW);
digitalWrite(8,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
}
voidleft(){
digitalWrite(9,HIGH);
digitalWrite(8,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
}
voidright(){
digitalWrite(9,LOW);
digitalWrite(8,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
}
voidBreak(){
digitalWrite(9,LOW);
digitalWrite(8,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}

voidget_Distance(){
myservo.write(0);
delay(500);
int temp_r1=ping();
myservo.write(45);
delay(500);
int temp_r2=ping();
if(temp_r1<temp_r2){
distance_r=temp_r1;
}else{
distance_r=temp_r2;
}
myservo.write(90);
delay(500);
distance_f=ping();

myservo.write(135);
delay(500);
int temp_l1=ping();
myservo.write(180);
delay(500);
int temp_l2=ping();
if(temp_l1<temp_l2){
distance_l=temp_l1;
}else{
distance_l=temp_l2;
}
myservo.write(90);

}

intping(){
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
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
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
return distance;
}

6. Light Follower Robot

Void setup(){

  Serial.begin(9600);

  pinMode(13, OUTPUT);

  pinMode(12, OUTPUT);

  pinMode(11, OUTPUT);

  pinMode(10, OUTPUT);

  }

voidloop(){

  intldrright = digitalRead(3);

  intldrleft = digitalRead(2);

  if(ldrright == 1&&ldrleft == 1){

    move_forward();

  }

  if(ldrright == 0&&ldrleft == 1){

    turn_right();

  }

  if(ldrright == 1&&ldrleft == 0){

    turn_left();

  }

  if(ldrright == 0&&ldrleft == 0){

    move_stop();

  }

  delay(100);

}

voidmove_forward(){

  digitalWrite(9, LOW);

  digitalWrite(8, HIGH);

  digitalWrite(4, HIGH);

  digitalWrite(5, LOW);

}

voidturn_right(){

  digitalWrite(9, LOW);

  digitalWrite(8, HIGH);

  digitalWrite(4, LOW);

  digitalWrite(5, HIGH);

}

voidturn_left(){

  digitalWrite(9, HIGH);

  digitalWrite(8, LOW);

  digitalWrite(4, HIGH);

  digitalWrite(5, LOW);

}

voidmove_stop(){

  digitalWrite(9, LOW);

  digitalWrite(8, LOW);

  digitalWrite(4, LOW);

  digitalWrite(5, LOW);

}