Go Down

Topic: Write an 11 to turn on LED PhysicalPIXEL example (Read 1 time) previous topic - next topic


Hello all,

I have an Arduino UNO.  I am really curious to know how I can write the number '11' from the serial monitor to the Arduino to turn on the LED?  Is this possible?  I am pretty much new to the Arduino programming environment.  The physicalpixel example is what I've been trying to use to do this.  In the example the code uses an L and H.  I would like to use an 11 and 12 respectively.

const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte = 10) {
      digitalWrite(ledPin, HIGH);
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte = 11) {
      digitalWrite(ledPin, LOW);

Thanks alot for your help!


The numbers 10 and 11 are actually two ASCII characters 0x30 & 0x31 with 11 being 0x31 & 0x31. So instead of looking for just a single character you have to wait for two to arrive and compare them both.

Go Up