
আজ আমরা Arduino দিয়ে Android এর Bluetooth এর মাধ্যমে কোনোকিছু Contorl করবো।
এই কাজের জন্য প্রয়োজনঃ
১ টি Arduino
১ টি Bluetooth Module
2/3 টি LED
আর প্রয়োজন মত তার
নিচের চিত্রের মত করে সব কিছু Connect কর। কাজটা আমাদের দুই ভাগে করতে হবে। প্রথম ভাগ Bluetooth এর সংযোগ, অন্যটি LED/Relay বা Output Connection।
Bluetooth এর Tx pin arduino এর Rx pin এ আর Rx pin Arduino এর Tx pin এ বসিয়ে দেই। আরপর VCC এবং GND connect দেই। তাহলেই আমাদের Bluetooth এর কাজ শেষ।
এরপর Arduino এর Digital 3, 5, 6 No pin এ LED/Relay বা Output এর Positive (+) প্রান্ত সংযোগ দিয়ে Output এর অন্য প্রান্ত GND তে সংযোগ দেই। তাহলেই আমাদের Connection Complete।
এখন আমাদের Code Upload করার পালা...
char blueToothVal; //value sent over via bluetooth
char lastValue; //stores last state of device (on/off)
int led = 3;
int ledone = 5;
int ledtwo = 6;
void setup()
{
Serial.begin(9600);
pinMode(led,OUTPUT);
pinMode(ledone, OUTPUT);
pinMode(ledtwo, OUTPUT);
}
void loop()
{
if(Serial.available())
{//if there is data being recieved
blueToothVal=Serial.read(); //read it
}
if (blueToothVal=='n')
{//if value from bluetooth serial is n
digitalWrite(led,HIGH); //switch on LED
if (lastValue!='n')
Serial.println(F("LED is on")); //print LED is on
lastValue=blueToothVal;
}
else if (blueToothVal=='f')
{//if value from bluetooth serial is n
digitalWrite(led,LOW); //turn off LED
if (lastValue!='f')
Serial.println(F("LED is off")); //print LED is on
lastValue=blueToothVal;
}
if (blueToothVal=='a')
{//if value from bluetooth serial is n
digitalWrite(ledone,HIGH); //switch on LED
if (lastValue!='a')
Serial.println(F("ledone is on")); //print LED is on
lastValue=blueToothVal;
}
else if (blueToothVal=='b')
{//if value from bluetooth serial is n
digitalWrite(ledone,LOW); //turn off LED
if (lastValue!='b')
Serial.println(F("ledone is off")); //print LED is on
lastValue=blueToothVal;
}
if (blueToothVal=='c')
{//if value from bluetooth serial is n
digitalWrite(ledtwo,HIGH); //switch on LED
if (lastValue!='c')
Serial.println(F("ledtwo is on")); //print LED is on
lastValue=blueToothVal;
}
else if (blueToothVal=='d')
{//if value from bluetooth serial is n
digitalWrite(ledtwo,LOW); //turn off LED
if (lastValue!='d')
Serial.println(F("ledtwo is off")); //print LED is on
lastValue=blueToothVal;
}
delay(1000);
}
Code Upload হয়ে গেলে Download করে নাও "BShaniuno" Android Apps
Apps Install করে চিত্রের মত করে Operate করুন...