#define fanSwitch 12 // Defining that Fan Switch is connected on Digital Pin 12 and giving it name. #define lightSwitch 10 // Defining that Light Switch is connected on Digital Pin 12 and giving it name. #define doorSwitch 11 // Defining that Door Switch is connected on Digital Pin 12 and giving it name. #define M1_a 3 // Defining M1_a i.e. 1st terminal of Left Motor is connected to Digital Pin 3 #define M1_b 5 // Defining M1_b i.e. 2nd terminal of Left Motor is connected to Digital Pin 5 #define M2_a 6 // Defining M2_a i.e. 1st terminal of Right Motor is connected to Digital Pin 6 #define M2_b 9 // Defining M2_b i.e. 2nd terminal of Right Motor is connected to Digital Pin 9 char code; // Defining a character data type variable in which whatever character that has to be sent corresponding to each condition is stored. void setup() { pinMode (M1_a, OUTPUT); // Defining M1_a as OUTPUT i.e. Output is being given to M1_a pinMode (M1_b, OUTPUT); // Defining M1_b as OUTPUT i.e. Output is being given to M1_b pinMode (M2_a, OUTPUT); // Defining M2_a as OUTPUT i.e. Output is being given to M2_a pinMode (M2_b, OUTPUT); // Defining M2_b as OUTPUT i.e. Output is being given to M2_b digitalWrite(M1_a,LOW); // Providing Low value to M1_a and M1_b so that there is no potential difference between the terminals and motor is OFF. digitalWrite(M1_b,LOW); // Providing Low value to M1_a and M1_b so that there is no potential difference between the terminals and motor is OFF. digitalWrite(M2_a,LOW); // Providing Low value to M2_a and M2_b so that there is no potential difference between the terminals and motor is OFF. digitalWrite(M2_b,LOW); // Providing Low value to M2_a and M2_b so that there is no potential difference between the terminals and motor is OFF. Serial1.begin(9600); // Initiating Serial Communication for Bluetooth. Serial.begin(9600); // Initiating Serial Communication for Serial Monitor. pinMode(lightSwitch, INPUT); // Defining Light Switch as INPUT pinMode(doorSwitch, INPUT); // Defining Door Switch as INPUT pinMode(fanSwitch, INPUT); // Defining Fan Switch as INPUT } void loop() { int xVal = analogRead(A1); // Reading X-Axis Input from Potentiometer Analog Input A1 int yVal = analogRead(A0); // Reading Y-Axis Input from Potentiometer Analog Input A2 if(xVal>700) // On testing, it came out that when we are pushing the joystick in the Right direction, then the xVal is greater than 700 { analogWrite(M1_a,200); // Commands for Moving Wheel Chair Right analogWrite(M1_b,0); analogWrite(M2_a,200); analogWrite(M2_b,0); delay(500); } else if(xVal<200) // On testing, it came out that when we are pushing the joystick in the Left direction, then the xVal is less than 200 { analogWrite(M1_a,0); // Commands for Moving Wheel Chair Left analogWrite(M1_b,200); analogWrite(M2_a,0); analogWrite(M2_b,200); delay(500); } else if (yVal>=700) // On testing, it came out that when we are pushing the joystick in the backward direction, then the yVal is greater than 700 { analogWrite(M1_b,0); // Commands for Moving Wheel Chair Backward analogWrite(M1_a,200); analogWrite(M2_b,200); analogWrite(M2_a,0); delay(200); } else if ( yVal <=300) // On testing, it came out that when we are pushing the joystick in the forward direction, then the yVal is less than 300 { analogWrite(M1_b,200); // Commands for Moving Wheel Chair Forward analogWrite(M1_a,0); analogWrite(M2_b,0); analogWrite(M2_a,200); delay(200); } else { // If nothing is pressed, then Wheel Chair should be Stop. digitalWrite(M1_a,LOW); digitalWrite(M1_b,LOW); digitalWrite(M2_a,LOW); digitalWrite(M2_b,LOW); } if(digitalRead(lightSwitch)==0 && digitalRead(doorSwitch)==0 && digitalRead(fanSwitch)==0) { // If LightSwitch is equal to 0, that means the Switch is ON. So for turning on Fan, Light and Door, Command 'A' is sent. code='A'; } if(digitalRead(lightSwitch)==0 && digitalRead(doorSwitch)==0 && digitalRead(fanSwitch)==1) { // For turning on Light and Door, and turning Off fan, Command 'B' is sent. code='B'; } if(digitalRead(lightSwitch)==0 && digitalRead(doorSwitch)==1 && digitalRead(fanSwitch)==0) { // For turning on Light and Fan, and closing the door, Command 'C' is sent. code='C'; } if(digitalRead(lightSwitch)==0 && digitalRead(doorSwitch)==1 && digitalRead(fanSwitch)==1) { // For turning on Light, CLosing Door, and turning Off fan, Command 'D' is sent. code='D'; } if(digitalRead(lightSwitch)==1 && digitalRead(doorSwitch)==0 && digitalRead(fanSwitch)==0) { // For turning on Fan, Opening Door, and turning Off Light, Command 'E' is sent. code='E'; } if(digitalRead(lightSwitch)==1 && digitalRead(doorSwitch)==0 && digitalRead(fanSwitch)==1) { // For Opening Door, and turning Off fan and Light, Command 'F' is sent. code='F'; } if(digitalRead(lightSwitch)==1 && digitalRead(doorSwitch)==1 && digitalRead(fanSwitch)==0) { // For turning on Fan, Closing Door, and turning Off Light, Command 'G' is sent. code='G'; } if(digitalRead(lightSwitch)==1 && digitalRead(doorSwitch)==1 && digitalRead(fanSwitch)==1) { // For turning off Light and Fan, and closing door, Command 'H' is sent. code='H'; } Serial1.write(code); // Writing the code on to the bluetooth so that it can be sent to the Disabled Friendly House Serial.println(code); }