Go Down

Topic: Interact and control a LED using the Serial monitor (Read 1 time) previous topic - next topic


Hello, I want to control a LED, set it to either HIGH or LOW, by sending values through the serial monitor.

Here is one example of something similar, but I dont know what the Arduino code he uses looks like:

I tried with this code, but it does not work:

Code: [Select]

const int ledPin     = 9;
const int ledPin2   = 10;

void setup(){


void loop () {

     if (Serial.available()>0) {
      //int d = 0;
      int d= Serial.read();
            if ( d == 10 )
              digitalWrite(ledPin, HIGH);         
              digitalWrite(ledPin2, HIGH);
            else if ( d == 20 )
              digitalWrite(ledPin, LOW);
              digitalWrite(ledPin2, LOW);

I simply plugg the Arduino into my computer, open the serial monitor and put "1" into the send text field and send it. RX LED on the Arduino flashes when I do this, but the LED does not go on. Anybody know what im doing wrong here?


The serial monitor sends code in ASCII, so when you type 1 it actually sends a value of 49.
Look at the example in the arduino IDE for this under serial communication.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131