send character to serial port using c#

Hello everyone,

I wrote a simple program on the arduino interface that turns on the LED when the user sends 'a' to the serial port, and turns off the LED when the user sends 'b' to the serial port.

if (Serial.available() > 0) {
    int incomingByte = Serial.read();

    if (incomingByte == 'a') {
      digitalWrite(ledPin, HIGH);
    }

    if (incomingByte == 'b') {
      digitalWrite(ledPin, LOW);
    }

My program works fine using the arduino interface serial monitor. However now I would like to send the characters using c#.

in c# I wrote a simple program

serialPort1.PortName = "COM13";
serialPort1.BaudRate = 9600;

serialPort1.Open();
if (serialPort1.IsOpen) {
serialPort1.WriteLine("a");
}

after running this c# code i cant get the led to turn on. Any ideas how I can get this to work?

Thanks!!! :slight_smile:

Assuming all the settings are right, could it be that you are using WriteLine, which includes a newline (/n) character? Is there a function just to send a character in c#? If this doesnt help, edit the program to spit back whatever it receives so you can see whats happening.