Basic Turn Light ON/OFF with Mobile phone - Arduino + Android App




Arduino Sketch


int relayPin = 7;
int state = 0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(relayPin , OUTPUT);
  digitalWrite(relayPin , HIGH );
 
}

void loop() {
  // put your main code here, to run repeatedly:
   if(Serial.available() > 0)
     state = Serial.read();

 if (state == '0')
    digitalWrite(relayPin, LOW);
 else if (state == '1')
    digitalWrite(relayPin, HIGH);
 
}

ความคิดเห็น