Move Servo Motor using Arduino and c#

Introduction

Move Servo motor using c# code through Arduino

Background

For this we need c#, arduino device and arduino code
Using the code

for Arduino

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos; // variable to store the servo position

void setup()
{
myservo.attach(7);

Serial.begin(9600);
}
void loop()
//////////////////////////
{
// scan from 0 to 180 degrees
if(Serial.available())
{
int c=Serial.read();
if (c=='1')
{
//////
for(angle = 0; angle < 180; angle++)
{
servo.write(angle);
delay(10);
}
}
}
// now scan back from 180 to 0 degrees
for(angle = 180; angle > 0; angle--)
{
servo.write(angle);
delay(10);
}
}

For C#

using System.IO.Ports;
using CA.Properties;

public Form1()
{
InitializeComponent();
serialPort1.PortName = "COM7";
serialPort1.BaudRate = 9600;
serialPort1.Open();

}

private void button1_Click(object sender, EventArgs e)
{
serialPort1.Write("1");
}

private void button2_Click(object sender, EventArgs e)
{
serialPort1.Write("0");
}

Points of Interest

It's easy.. have fun