arduino:arduino_crash_course:serial_communication
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
arduino:arduino_crash_course:serial_communication [2012/09/14 01:18] – created mithat | arduino:arduino_crash_course:serial_communication [2012/11/03 21:40] – mithat | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Serial Communication ====== | ====== Serial Communication ====== | ||
+ | |||
+ | Serial communication is a two-way stream of text that is communicated over a **serial port**--most often between the Arduino board (called the **target**) and the computer you are using to develop Arduino programs (called the **development host** or just **host**). It is one way to let the host system communicate with the Arduino board. | ||
+ | |||
+ | Serial communication is often used to make the Arduino report back to the host the value of the program' | ||
===== Switch controlled LED with serial reporting ===== | ===== Switch controlled LED with serial reporting ===== | ||
+ | |||
+ | The following is the [[arduino: | ||
+ | |||
+ | Once you have uploaded the program to the Arduino and it is running, open the serial monitor using the IDE's //Tools > Serial Monitor// menu item. Notice the values that are reported in the Serial Monitor window when you press and unpress the switch. | ||
+ | |||
<file c LightSwitchMonitored.ino> | <file c LightSwitchMonitored.ino> | ||
/* | /* | ||
Line 7: | Line 16: | ||
Turn an LED on and off and send switch state to serial monitor | Turn an LED on and off and send switch state to serial monitor | ||
*/ | */ | ||
- | + | ||
int pushButtonPin = 2; // connect the push button to digital pin 2 | int pushButtonPin = 2; // connect the push button to digital pin 2 | ||
int ledPin = 13; // connect the LED to pin 13 | int ledPin = 13; // connect the LED to pin 13 | ||
- | + | ||
void setup() { | void setup() { | ||
Serial.begin(9600); | Serial.begin(9600); | ||
Line 22: | Line 31: | ||
void loop() { | void loop() { | ||
int buttonState = digitalRead(pushButtonPin); | int buttonState = digitalRead(pushButtonPin); | ||
- | + | ||
// set LED state accordingly | // set LED state accordingly | ||
if (buttonState == LOW) // if the button is pushed | if (buttonState == LOW) // if the button is pushed | ||
Line 28: | Line 37: | ||
else // otherwise | else // otherwise | ||
digitalWrite(ledPin, | digitalWrite(ledPin, | ||
- | + | ||
Serial.println(buttonState); | Serial.println(buttonState); | ||
delay(500); | delay(500); | ||
} | } | ||
</ | </ |
arduino/arduino_crash_course/serial_communication.txt · Last modified: 2012/11/12 18:23 by mithat