Advertisement
Guest User

Untitled

a guest
Dec 29th, 2016
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. char data = 0; //Variable for storing received data
  2. void setup()
  3. {
  4. Serial.begin(9600); //Sets the data rate in bits per second (baud) for serial data transmission
  5. pinMode(13, OUTPUT); //Sets digital pin 13 as output pin
  6. }
  7. void loop()
  8. {
  9. if(Serial.available() > 0) // Send data only when you receive data:
  10. {
  11. data = Serial.read(); //Read the incoming data and store it into variable data
  12. Serial.print(data); //Print Value inside data in Serial monitor
  13. Serial.print("\n"); //New line
  14. if(data == '1') //Checks whether value of data is equal to 1
  15. digitalWrite(13, HIGH); //If value is 1 then LED turns ON
  16. else if(data == '0') //Checks whether value of data is equal to 0
  17. digitalWrite(13, LOW); //If value is 0 then LED turns OFF
  18. }
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement