safwan092

Untitled

Mar 10th, 2022
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. SoftwareSerial softSerial(3, 4); //TX_BT --> D3 / RX_BT --> D4
  3.  
  4. String str;
  5. int blueToothVal;
  6. #define relay 12
  7. int a = 0;
  8. void setup()
  9. {
  10. Serial.begin(9600);
  11. softSerial.begin(9600);
  12. pinMode(relay, OUTPUT);
  13. digitalWrite(relay, HIGH);
  14. }
  15. void loop()
  16. {
  17. bluetooth();
  18. if (a == 1) {
  19. digitalWrite(relay, LOW);
  20. delay(100);
  21. digitalWrite(relay, HIGH);
  22. delay(100);
  23. }
  24. else {
  25. digitalWrite(relay, HIGH);
  26. }
  27. }
  28.  
  29.  
  30.  
  31.  
  32. void bluetooth()
  33. {
  34. while (softSerial.available())
  35. {
  36. {
  37. str = softSerial.readStringUntil('\n');
  38. Serial.println(str);
  39. }
  40.  
  41. blueToothVal = (str.toInt());
  42. Serial.println(blueToothVal);
  43. switch (blueToothVal)
  44. {
  45. case 1:
  46. a = 1;
  47. break;
  48.  
  49. case 2:
  50. a = 2;
  51. break;
  52. }
  53.  
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment