Wednesday 20 June 2018

Arduino Remote Light

Program Def: Create program glow light using wireless media .
 Reuredment:
 two CKT two Arduino
                      one connected LED
                      another Connected Button
                     Each Arduino Connecrted Bluetooth HC-05 SETUP

One as Master Another As Slave :  

Load This Program For Config Bluetooth 
// note : pin cong: 
     BT     Arduino
    Tx         10
   RX         11

   VCC        5v
   Gnd        Gnd

  EN          3.3v or pin 9 (for program)

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup()
{
  pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
  digitalWrite(9, HIGH);
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
}

void loop()
{
 // Serial.println("in LOop");
  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  {
    Serial.write(BTSerial.read());
   // Serial.println(BTSerial.read());
     // Serial.println("in avl...");
      //delay(1000);
  }
  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available())
    BTSerial.write(Serial.read());
      //Serial.println("Write..");
      //delay(1000);
}





Salve :
Write TTL Command
 AT+RMAAD (clear any paired devices)
AT+ROLE=0 (set as slave)
 AT+ADDR (Return H/w address remember it)
AT+UART=38400,0,0 (To fix the baud rate at 38400)


Master :
AT+RMAAD
AT+ROLE=1 (set it as master)
AT+CMODE=0 (To connect the module to the specified Bluetooth address and this Bluetooth address can be specified by the binding command)
 AT+BIND=xxxx,xx,xxxxxx ( XXXXXXXXXXXX Contain slave address)
 AT+UART=38400,0,0 (To fix the baud rate at 38400)

CKT DIG:


 ------------------------------------------------------------------------
// note : pin cong  (Both Arduinos): 
     BT     Arduino
    Tx         0
   RX         1

   VCC        5v
   Gnd        Gnd

  

 

Programs

Android 1 (Button Site)
 ----------------------------------------------------- 
// Button Coding ...

//this is master

//#include <SoftwareSerial.h>

//SoftwareSerial BTSerial(10, 11);


const int buttonPin = 2;
int buttonState = 1;

void setup() 
{
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH);
}

void loop()
{
 // send Signal to Second Arduino.... for glow LED
 buttonState = digitalRead(buttonPin);
 if (buttonState == LOW)
 {
  Serial.write('1');
 }
 else
 {
  Serial.write('0');
 }
 

}

--------------------------------------------------------

LED Site (Arduino 2)

//LED CKT

#include <SoftwareSerial.h>

//SoftwareSerial BTSerial(2, 3);

int data = 0;
const int led = 8;
int flag=0;

void setup() 
{
  //BTSerial.begin(38400);
   Serial.begin(9600);
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
  
}
void loop() 
{
 if(Serial.available() > 0)
 { 

    data = Serial.read(); // incoming data i.e 1
   if(data==1 && flag==0)
   {
    flag=1;
   }
   else if(data==1 && flag==1)
   {
    flag=0;
   }
    
 }

 
  if (flag == '1' ) 
 {
  digitalWrite(led, HIGH); // LED ON
  data = 0;
 }
 else if (flag == '0') 
 {
  digitalWrite(led, LOW); // LED ON
  data = 0;
 }

}







1 comment:

  1. This is why it is far better that you simply applicable investigating well before building. You can actually design more effective share in such a manner. Animated Logo Design

    ReplyDelete

Thank You!!!

create and activate a Python virtual environment on macOS and Windows

create and activate a Python virtual environment on macOS and Windows: Prerequisites: Python 3: Ensure you have Python 3 installed. You ca...