Advertisement
salmancreation

relay - task -3 arduino

Jun 27th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. int relay = 7;
  2. char data;
  3. // replay - task -2
  4. void setup() {
  5.   pinMode(relay, OUTPUT);
  6.   Serial.begin(9600);
  7. }
  8.  
  9. void loop() {  
  10.   if(Serial.available()>0){
  11.   // data available
  12.  
  13.   data = Serial.read();
  14.  
  15.   if(data=='a'){
  16.     digitalWrite(relay, HIGH);
  17.     Serial.println("Relay ON");
  18.   }
  19.   else if(data=='b'){
  20.     digitalWrite(relay, LOW);  
  21.     Serial.println("Relay OFF");  
  22.   }
  23.   }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement