how to control LED of pin 12

System.ComponentModel.IContainer components = new System.ComponentModel.Container();
serialPort1 = new System.IO.Ports.SerialPort(components);
serialPort1.PortName = "COM3";
serialPort1.BaudRate = 9600;

serialPort1.Write("1");

Not setting the pin "1" as led not glowing .

How to program pin specific like 5 , 10 or 12 .

I want to control the LED of the mentioned pin .

Could you be a little less cryptic, and could you please stop cross-posting?
Thank you

(duplicate post deleted)

Ok.

Sure .

I knew how to control arduino , specific port using loop() .. etc

But not able to control using c#.

Please suggest .

Do you want to control your Arduino using C# on your computer?

Start with controlling your Arduino using serial monitor. When you have the code working, you can change to your C# program, or use anything else that can use serial communication on your computer.

can you provide a sample example in c#

biswa07:
serialPort1.Write("1");

Serial port is not the same as a pin... is it?

biswa07:
can you provide a sample example in c#

Ever heard of google? Anyway, SerialPort class

What you might want to change:

_serialPort.WriteLine(
String.Format("<{0}>: {1}", name, message));

to something like

_serialPort.Write(
String.Format("<{0},{1}>", pinnumber, onoff));

Obviously you must prompt the user to give a pin number and the onoff status.

And next study Serial Input Basics - updated to read and parse the received data.

Thank you . I wll try .

My code ,

Page Load,

System.ComponentModel.IContainer components = new System.ComponentModel.Container();
serialPort1 = new System.IO.Ports.SerialPort(components);
serialPort1.PortName = "COM3";
serialPort1.BaudRate = 9600;
serialPort1.DtrEnable = true;

Then in button click , (desired pin 12 )

1st try--

serialPort1.Open();
serialPort1.Write(String.Format("<{0},{1}>", 12, "on"));
serialPort1.Close();

2nd try --

serialPort1.Open();
serialPort1.Write(String.Format("<{0},{1}>", 12, "1"));
serialPort1.Close();

3rd try --

serialPort1.Open();
serialPort1.Write(String.Format("<{0},{1}>", 12, "true"));
serialPort1.Close();

But fail all cases .
Please help .

But fail all cases .

Opening the serial port resets the Arduino. You don't give it time to reset before you jam data at it. Of course that data isn't going to be recognized/acted on.

Open the port ONCE. Close the port ONCE.

Can you please help me with code ?

What to do next ?

Thanks ..
Biswa

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

PaulS:
Opening the serial port resets the Arduino. You don't give it time to reset before you jam data at it. Of course that data isn't going to be recognized/acted on.

Open the port ONCE. Close the port ONCE.

I have modified the code & done suggested by you .
Still failing to control pin 12 / 11 /10 etc .

biswa07:
I have modified the code & done suggested by you .
Still failing to control pin 12 / 11 /10 etc .

Show your updated code if you want us to look at it.

Have you tested your arduino code using the serial monitor by sending the data that is formatted in the same way as what your C# program sends?

Ok , I will upload the code.

Thank you for helping me.

sterretje:
Show your updated code if you want us to look at it.

Have you tested your arduino code using the serial monitor by sending the data that is formatted in the same way as what your C# program sends?

Code -

private void Form1_Load(object sender, EventArgs e)
{
System.ComponentModel.IContainer components = new System.ComponentModel.Container();
serialPort1 = new System.IO.Ports.SerialPort(components);
serialPort1.PortName = "COM3";
serialPort1.BaudRate = 9600;
serialPort1.DtrEnable = true;
serialPort1.Open();
}

//FOR PIN - 12

private void button2_Click(object sender, EventArgs e)
{

serialPort1.Write(String.Format("<{0},{1}>", 12, "1"));

}

Can you plessr read reply #11 again and follow the procedure to properly post code.

For now, I like to see your Arduino code first (and use code tags !!) and want to know if you can switch the led on pin 12 on and off using the serial monitor by sending

<12,1>

and

<12,0>

arduino code working perfectly , and led blinking as per code - :slight_smile:

void setup() {
  // put your setup code here, to run once:
pinMode(12, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(12, LOW);    // turn the LED off by making the voltage LOW
  delay(5000);                    
}

but c# not working .

Hey there, biswa07. I think you've got a basic misunderstanding. Your C# code runs on your PC. Your Arduino sketch runs on your Arduino. In order for your C# app to blink an LED on your Arduino, your C# app and your Arduino sketch have to communicate with one another. Right now, your Arduino sketch isn't reading from the serial port or doing anything that would permit it to know that your C# app wants it to twiddle an LED.

Read serial input badics - updated first. And get something working based on that in combination with serial monitor.

Next you can work on the c# code.