Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

const int buttonPin = 9; // the number of the pushbutton pin

int buttonState = 0; // variable for reading the pushbutton status


int relaypin = 10; //Output Pin ON - OFF
char str;
void setup() {
Serial1.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(relaypin, OUTPUT);
digitalWrite(relaypin, HIGH);
Serial1.flush();
Serial1.println();
Serial1.println("Connect Door Control Complete : RS232 Receive & Transmit Data");
Serial1.println("Press key for open door");
Serial1.print(">");
}

void loop() {
buttonState = digitalRead(buttonPin); // read the state of the pushbutton
value:
if (buttonState == HIGH)
{
digitalWrite(relaypin, LOW); // turn ON
delay(5000); // wait 5s
digitalWrite(relaypin, HIGH); // turn OFF
}
if (Serial1.available() > 0)
{
str = Serial1.read();
if(str == 'o')
{
Serial1.println();
//Serial1.print(">");
Serial1.write(str);
digitalWrite(relaypin, LOW); // turn ON
delay(5000); // wait 5s
digitalWrite(relaypin, HIGH); // turn OFF

} } }

You might also like