Go Down

Topic: how to control LED of pin 12 (Read 1 time) previous topic - next topic

biswa07

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"));

}

sterretje

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
Code: [Select]
<12,1>
and
Code: [Select]
<12,0>
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

biswa07

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


Code: [Select]
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 .

jaholmes

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.

sterretje

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.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

biswa07

#20
Feb 21, 2017, 07:06 am Last Edit: Feb 21, 2017, 07:15 am by biswa07
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.
With c# , can control default pin 13 , so c# is communicating with  Arduino.
Secondly , after sending <12,1> command to serial monitor not able to visualize any change .


#sterretje , thanks for helping me up.


Please suggest .

pert

Post the code you're running on the Arduino to control the pins based on serial input (not the c# code running on your computer).

sterretje

#22
Feb 21, 2017, 12:47 pm Last Edit: Feb 21, 2017, 12:53 pm by sterretje
With c# , can control default pin 13 , so c# is communicating with  Arduino.
Secondly , after sending <12,1> command to serial monitor not able to visualize any change
Your code in reply #13 does not contain a single line that controls a led based on the received data. It does not even contain code to receive data.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

biswa07

Actually I can see data get transferred , using in-built green LED . on button click it blink for 1ms.

When I repeatedly click button , the in-built LED blinks .

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!

Arduino
via Egeo 16
Torino, 10131
Italy