# The c# was not connected to my arduino hardware.

**URL:** <https://community.sparkfun.com/t/the-c-was-not-connected-to-my-arduino-hardware/27256>\
**Category:** Arduino\
**Created:** [August 13, 2013, 2:20am UTC](https://community.sparkfun.com/t/the-c-was-not-connected-to-my-arduino-hardware/27256 "2013-08-13T02:20:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shankar](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@shankar](https://community.sparkfun.com/u/shankar)\
**Post date:** [August 13, 2013, 2:20am UTC](https://community.sparkfun.com/t/the-c-was-not-connected-to-my-arduino-hardware/27256/1 "2013-08-13T02:20:28Z")

</div>

**Arduino code**

byte relayPin[4] = {2,7,8,10};

//D2 → RELAY1

//D7 → RELAY2

//D8 → RELAY3

//D10 → RELAY4

void setup(){

for(int i = 0; i \< 4; i++) pinMode(relayPin\*,OUTPUT);\*  
_}_

_// an sample to switch the 4 relays_

_void loop(){_

_int i;_  
_for(i = 0; i \< 4; i++) digitalWrite(relayPin,HIGH);_  
 _delay(1000);  
 for(i = 0; i \< 4; i++) digitalWrite(relayPin,LOW);  
 delay(1000);_

 

_}_  
_I was written below c# code for my arduino code.But the C# code was getting error._  
_The c# was not connected to my arduino hardware. How to solve this issue._  
_Please help me to solve this problem._  
_ **C# code** _  
_private void button1\_Click(object sender, EventArgs e)_  
_{_

_serialPort1.PortName = “COM25”;  
 serialPort1.BaudRate = 9600;  
 serialPort1.Open();  
 Byte[] data = new byte[4];  
 data[0] = 2;  
 data[1] = 3;  
 data[2] = 8;  
 data[3] = 10;  
 serialPort1.Write(data, 0, serialPort1.BytesToWrite);  
 }_

---

<div class="post-metadata">

**Author:** ![jremington](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/jremington/32/6595_2.png) [@jremington](https://community.sparkfun.com/u/jremington)\
**Post date:** [August 13, 2013, 3:17am UTC](https://community.sparkfun.com/t/the-c-was-not-connected-to-my-arduino-hardware/27256/2 "2013-08-13T03:17:51Z")

</div>

If you expect an answer, you will have to ask a question in a way that make some sense and provides some information about the actual problem. Your post does neither. See [http://www.catb.org/~esr/faqs/smart-questions.html](http://www.catb.org/~esr/faqs/smart-questions.html)

---

<div class="post-metadata">

**Author:** ![Mee\_n\_Mac](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Mee\_n\_Mac](https://community.sparkfun.com/u/Mee_n_Mac)\
**Post date:** [August 13, 2013, 5:02am UTC](https://community.sparkfun.com/t/the-c-was-not-connected-to-my-arduino-hardware/27256/3 "2013-08-13T05:02:51Z")

</div>

Even Carnac couldn’t figure out what to say on this one.

---

<div class="post-metadata">

**Author:** ![Ross\_Robotics](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@Ross\_Robotics](https://community.sparkfun.com/u/Ross_Robotics)\
**Post date:** [August 13, 2013, 9:27am UTC](https://community.sparkfun.com/t/the-c-was-not-connected-to-my-arduino-hardware/27256/4 "2013-08-13T09:27:49Z")

</div>

I am guessing that the Arduino is on COM25 and he’s trying to connect to it from a program on his PC… But his Arduino code doesn’t have Serial enabled.

Add

```auto
Serial.begin(9600);

```

To the Arduino setup code.

---

<div class="post-metadata">

**Author:** ![n1ist](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@n1ist](https://community.sparkfun.com/u/n1ist)\
**Post date:** [August 13, 2013, 1:37pm UTC](https://community.sparkfun.com/t/the-c-was-not-connected-to-my-arduino-hardware/27256/5 "2013-08-13T13:37:01Z")

</div>

Not only does it not have serial enabled, there’s no code on the Arduino to read the serial port or do anything with the data.

So what do you want the Arduino to do when it receives 0x02 0x03 0x08 0x0A?

/mike
