const int Power = 11; const int button1Pin = 3; const int motor1Pin = 4; char val; boolean button1State = LOW; void setup() { Serial.begin(115200); establishContact(); pinMode(button1Pin, INPUT); pinMode(motor1Pin, OUTPUT); } void loop() { if (Serial.available() > 0) { val = Serial.read(); if (val == '1') { // If 1 was received button1State = !button1State; digitalWrite(button1State, button1State); // turn the LED on } delay(100); } else { Serial.println("hello"); button1State = digitalRead(button1Pin); } if (button1State == LOW) { digitalWrite(motor1Pin, LOW); } else { for(int i = 0; i < 2; i ++) { digitalWrite(motor1Pin, HIGH); delay(1000); digitalWrite(motor1Pin, LOW); delay(1000); } } } void establishContact() { while (Serial.available() <= 0) { Serial.println("A"); // send a capital A delay(300); } }