Devices & Components
Arduino Uno Rev3
Resistor 10k ohm
LED (generic)
RGB LCD Shield Kit, 16x2 Character Display
Jumper wires (generic)
Breadboard (generic)
Software & Tools
Visual Studio 2015
Arduino IDE
Project description
Code
Form1.cs
csharp
This is the C# program that send the instruction to the Arduino IDE
1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Linq; 7using System.Text; 8using System.Threading.Tasks; 9using System.Windows.Forms; 10using System.IO.Ports; 11 12namespace ArduinoControl 13{ 14 public partial class Form1 : Form 15 { 16 String[] ports; 17 SerialPort port; 18 bool isConnected = false; 19 String lcd_Text; 20 21 public Form1() 22 { 23 InitializeComponent(); 24 getAvailableCOM_PORTS(); 25 26 foreach (string port in ports) 27 { 28 comboBox1.Items.Add(port); 29 Console.WriteLine(port); 30 31 if (ports[0] != null) 32 { 33 comboBox1.SelectedItem = ports[0]; 34 } 35 } 36 37 38 } 39 40 private void label6_Click(object sender, EventArgs e) 41 { 42 // PASS 43 } 44 45 private void label7_Click(object sender, EventArgs e) 46 { 47 // PASS 48 } 49 50 private void label2_Click(object sender, EventArgs e) 51 { 52 53 } 54 55 private void checkBox2_CheckedChanged(object sender, EventArgs e) 56 { 57 if (isConnected) 58 { 59 if (checkBox2.Checked) 60 { 61 port.Write("$LEDGON"); 62 } 63 else 64 { 65 port.Write("$LEDGOF"); 66 } 67 } 68 } 69 70 private void checkBox3_CheckedChanged(object sender, EventArgs e) 71 { 72 if (isConnected) 73 { 74 if (checkBox3.Checked) 75 { 76 port.Write("$LEDBON"); 77 } 78 79 else 80 { 81 port.Write("$LEDBOF"); 82 } 83 } 84 } 85 86 private void label3_Click(object sender, EventArgs e) 87 { 88 89 } 90 91 private void Form1_Load(object sender, EventArgs e) 92 { 93 94 } 95 96 private void getAvailableCOM_PORTS () 97 { 98 ports = SerialPort.GetPortNames(); 99 } 100 101 private void connectToArduino () 102 { 103 isConnected = true; 104 string selectedPort = comboBox1.GetItemText(comboBox1.SelectedItem); 105 port = new SerialPort(selectedPort, 9600, Parity.None, 8, StopBits.One); 106 port.Open(); 107 button2.Text = "Disconnect"; 108 } 109 110 private void disconnectFromArduino () 111 { 112 isConnected = false; 113 port.Close(); 114 button2.Text = "Connect"; 115 } 116 117 private void button2_Click(object sender, EventArgs e) 118 { 119 if (!isConnected) 120 { 121 connectToArduino(); 122 } 123 124 else 125 { 126 disconnectFromArduino(); 127 } 128 } 129 130 private void checkBox1_CheckedChanged(object sender, EventArgs e) 131 { 132 if (isConnected) 133 { 134 if (checkBox1.Checked) 135 { 136 port.Write("$LEDRON"); 137 } 138 139 else 140 { 141 port.Write("$LEDROF"); 142 } 143 } 144 } 145 146 private void textBox1_TextChanged(object sender, EventArgs e) 147 { 148 // PASS 149 } 150 151 private void label4_Click(object sender, EventArgs e) 152 { 153 // PASS 154 } 155 156 private void label5_Click(object sender, EventArgs e) 157 { 158 // PASS 159 } 160 161 private void checkBox4_CheckedChanged(object sender, EventArgs e) 162 { 163 if (isConnected) 164 { 165 if (checkBox4.Checked) 166 { 167 port.Write("$LEDYON"); 168 } 169 170 else 171 { 172 port.Write("$LEDYOF"); 173 } 174 } 175 } 176 177 private void groupBox2_Enter(object sender, EventArgs e) 178 { 179 180 } 181 182 private void button1_Click(object sender, EventArgs e) 183 { 184 if (isConnected) 185 { 186 port.Write(string.Format("$LCD_{0}", textBox1.Text)); 187 } 188 } 189 } 190} 191
Arduino Code
Arduino Code to accept, decode and execute instructions from C# program
Arduino Code
Arduino Code to accept, decode and execute instructions from C# program
Downloadable files
LCD CONNECTION
LCD CONNECTION

LCD CONNECTION
LCD CONNECTION

Comments
Only logged in users can leave comments