Wireless communication with PC and Arduino board using bluetooth


SUBMITTED BY: rabah75

DATE: July 24, 2016, 1:13 p.m.

UPDATED: July 24, 2016, 1:46 p.m.

FORMAT: C

SIZE: 897 Bytes

HITS: 8911

  1. Code:
  2. Wiring code this code will wait for signals from processing. When it receives a H signal, the LED on pin 8 will turn on. When it receives an L signal the LED on pin 8 will turn off.
  3. Wiring code
  4. char val; // variable to receive data from the serial port
  5. int ledpin = 8; // LED connected to pin 48 (on-board LED)
  6. void setup() {
  7. pinMode(ledpin, OUTPUT); // pin 48 (on-board LED) as OUTPUT
  8. Serial.begin(9600); // start serial communication at 9600bps
  9. }
  10. void loop() {
  11. if( Serial.available() ) // if data is available to read
  12. {
  13. val = Serial.read(); // read it and store it in 'val'
  14. }
  15. if( val == 'H' ) // if 'H' was received
  16. {
  17. digitalWrite(ledpin, HIGH); // turn ON the LED
  18. } else {
  19. digitalWrite(ledpin, LOW); // otherwise turn it OFF
  20. }
  21. delay(100); // wait 100ms for next reading
  22. }

comments powered by Disqus