Serial communication from arduino to c#

Hi guys, am working on a home automation project and am implementing arduino with an AI. But am having trouble to make the arduino send an int to serial port that the AI can catch in C# and interpret it.

can anyone help me please.
thank you very much in advance. :slight_smile:

Post your code - both C# and what's on the arduino

can anyone help me please.

Start out using the serial monitor for testing, then move to your C application.

code in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;

namespace arduino_test_2
class Program

public static void Main()
SerialPort mySerialPort = new SerialPort("COM6");

mySerialPort.BaudRate = 9600;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.None;

mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);


Console.WriteLine("Press any key to continue...");

private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
Console.Write("Data Received:");

public static object on { get; set; }

but with this code i can only see the data, i can`t use it.

and the code for arduino its working its sending " on " when a button is pressed. But i want in c# to differentiate from all the data it gets.

it should be able to notice the " on " and do an action or an " off " to do another action..

Am stuck with it for like two weeks, plz help, that would be great if i get this to work.
thank you guys in advance

Am stuck with it for like two weeks, plz help, that would be great if i get this to work.

Have you looked for a C programming forum? The Processing programming application might be of use as it is apparently similar to the arduino type coding.

so no one can figure this out here ? :confused:

so no one can figure this out here ? :confused:

#7 below:,148850.0.html