Arduino Bluetooth Light Switch with Servos SOURCE CODE: //CREATED BY ROBOTIC NATION //https://www.youtube.com/c/RoboticNation#include <Servo.h>Servo servo1; Servo servo2; char getstr; //Defines a function that receives the Bluetooth character int pos = 0; //create servo position variable int pos2 = 0;void setup() { servo1.attach(9); servo2.attach(3); Serial.begin(9600); }void turnOn(){servo1.write(75); delay(2000); servo1.write(1); delay(2000); }void turnOff(){servo2.write(75); delay(2000); servo2.write(1); delay(2000);} void loop() { getstr = Serial.read(); if (getstr == 'h'){ turnOn(); Serial.write("The light is on"); } if (getstr == 'l'){ turnOff(); Serial.write("The light is off"); }}
SOURCE CODE: //CREATED BY ROBOTIC NATION //https://www.youtube.com/c/RoboticNation#include <Servo.h>Servo servo1; Servo servo2; char getstr; //Defines a function that receives the Bluetooth character int pos = 0; //create servo position variable int pos2 = 0;void setup() { servo1.attach(9); servo2.attach(3); Serial.begin(9600); }void turnOn(){servo1.write(75); delay(2000); servo1.write(1); delay(2000); }void turnOff(){servo2.write(75); delay(2000); servo2.write(1); delay(2000);} void loop() { getstr = Serial.read(); if (getstr == 'h'){ turnOn(); Serial.write("The light is on"); } if (getstr == 'l'){ turnOff(); Serial.write("The light is off"); }}