Things used in this project

Parts & Materials:
A000066 iso both
Arduino UNO & Genuino UNO
×1
servo motor
×5
regulater power supply board
×1
12v dc adaptor
×1
Software apps and online services:
Ide web
Arduino IDE
visual basic 6
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)

Code

servocontrol.inoArduino
Arduino program
#include <Servo.h> 
#include <EEPROM.h>
 
String inputString = "";        
boolean stringComplete = false; 
Servo myservo3;  
Servo myservo5;  
Servo myservo6;  
Servo myservo9;  
Servo myservo10;   

String P1;
String P2;
String P3;
String P4;
String P5;

int pos1;
int pos2;
int pos3;
int pos4;
int pos5;

int rpos1[100];
int rpos2[100];
int rpos3[100];
int rpos4[100];
int rpos5[100];

int opos1;
int opos2;
int opos3;
int opos4;
int opos5;

int seperator1=0;
int seperator2=0;

int noofrecords=0;
int runstatus=0;
int recpos=0;
int currec=0;
 
int pos = 0;

void setup() {
  myservo3.attach(3);  
  myservo5.attach(5);    
  myservo6.attach(6);  
  myservo9.attach(9);  
  myservo10.attach(10);
  Serial.begin(9600);
  
  noofrecords=EEPROM.read(0);
  
  for(int i=0;i<noofrecords;i++)
  {
    pos=pos+1;
    recpos=(i*5)+1;
    rpos1[pos]=EEPROM.read(recpos);         
    recpos=recpos+1;
    rpos2[pos]=EEPROM.read(recpos);         
    recpos=recpos+1;    
    rpos3[pos]=EEPROM.read(recpos);         
    recpos=recpos+1;    
    rpos4[pos]=EEPROM.read(recpos);         
    recpos=recpos+1;    
    rpos5[pos]=EEPROM.read(recpos);             
  }  
  runstatus=1;
}

void loop() {
  if (stringComplete) {
    stringComplete = false;      
//    Serial.println(inputString);
    if(inputString.substring(0,6)=="Record")
    {
      EEPROM.write(0, 0);
      noofrecords=0;
      runstatus=0;
      Serial.println("Record");    
    }
    else if(inputString.substring(0,4)=="Save")
    {
      noofrecords=noofrecords+1;    
      EEPROM.write(0, noofrecords);
      recpos=noofrecords-1;
      
      recpos=(recpos*5)+1;
      EEPROM.write(recpos, opos1);  
      rpos1[noofrecords]=opos1;      
      
      recpos=recpos+1;
      EEPROM.write(recpos, opos2);         
      rpos2[noofrecords]=opos2;            
      
      recpos=recpos+1;
      EEPROM.write(recpos, opos3);   
      rpos3[noofrecords]=opos3;                  
      
      recpos=recpos+1;
      EEPROM.write(recpos, opos4);   
      rpos4[noofrecords]=opos4;                        
      
      recpos=recpos+1;
      EEPROM.write(recpos, opos5);         
      rpos5[noofrecords]=opos5;
      
      Serial.print("Saved");    
      Serial.println(noofrecords);          
    }    
    else if(inputString.substring(0,3)=="Add")
    {
      runstatus=0;
      Serial.println(noofrecords);     
      delay(100);
      Serial.println("LAST");
      Serial.println(rpos1[noofrecords]);
      Serial.println(rpos2[noofrecords]);
      Serial.println(rpos3[noofrecords]);
      Serial.println(rpos4[noofrecords]);
      Serial.println(rpos5[noofrecords]);  
    }
    else if(inputString.substring(0,3)=="Run")
    {
      currec=0;
      runstatus=1;      
      Serial.print("Run");    
    }        
    else
    {
//      Serial.println(inputString);    
      seperator1 = inputString.indexOf(',');
      P1=inputString.substring(0,seperator1);    
//      Serial.println(P1);
      
      seperator1=seperator1+1;
      seperator2 = inputString.indexOf(',',seperator1);    
      P2=inputString.substring(seperator1,seperator2);            
//      Serial.println(P2);
      
      seperator1=seperator2+1;
      seperator2 = inputString.indexOf(',',seperator1);    
      P3=inputString.substring(seperator1,seperator2);            
//      Serial.println(P3);
      
      seperator1=seperator2+1;  
      seperator2 = inputString.indexOf(',',seperator1);    
      P4=inputString.substring(seperator1,seperator2);            
//      Serial.println(P4);
      
      seperator1=seperator2+1;
      seperator2 = inputString.indexOf(',',seperator1);    
      P5=inputString.substring(seperator1,seperator2);            
//      Serial.println(P5);    
      
      pos1=P1.toInt();
      pos2=P2.toInt();    
      pos3=P3.toInt();        
      pos4=P4.toInt();            
      pos5=P5.toInt();                
      
      if (pos1<20)
      {
        pos1=20;
      }else if(pos1>90)
      {
        pos1=90;
      }
      
      if (pos2<20)
      {
        pos2=20;
      }
      else if (pos2>90)
      {
        pos2=90;
      }            
      pos2=180-pos2;
  
      if (pos3<20)
      {
        pos3=20;
      }
      else if (pos3>90)
      {
        pos3=90;
      }
      
      if (pos4<20)
      {
        pos4=20;
      }
      else if (pos4>90)
      {
        pos4=90;
      }         
      pos4=180-pos4;
         
      if (pos5<20)
      {
        pos5=20;
      }
      else if (pos5>90)
      {
        pos5=90;
      }         
      
      if (pos1!=opos1)
      {
        myservo3.write(pos1);
        opos1=pos1;
      }
      if (pos2!=opos2)
      {
        myservo5.write(pos2);
        opos2=pos2;
      }    
      if (pos3!=opos3)
      {
        myservo6.write(pos3);
        opos3=pos3;
      }    
      if (pos4!=opos4)
      {
        myservo9.write(pos4);
        opos4=pos4;
      }     
      if (pos5!=opos5)
      {
        myservo10.write(pos5);
        opos5=pos5;
      }         
    }
    inputString = "";    
  }  
  
  if(runstatus==1)
  {
    currec=currec+1;
    if (currec>noofrecords)
    {
      currec=1;
      delay(2000);
    }
    pos1=rpos1[currec];
    pos2=rpos2[currec];
    pos3=rpos3[currec];
    pos4=rpos4[currec];
    pos5=rpos5[currec];
    Serial.println("RUNNING");        
    Serial.println(currec);    
    Serial.println(pos1);
    Serial.println(pos2);
    Serial.println(pos3);
    Serial.println(pos4);
    Serial.println(pos5);    
    if (pos1!=opos1)
    {
      myservo3.write(pos1);
      opos1=pos1;
    }
    if (pos2!=opos2)
    {
      myservo5.write(pos2);
      opos2=pos2;
    }    
    if (pos3!=opos3)
    {
      myservo6.write(pos3);
      opos3=pos3;
    }    
    if (pos4!=opos4)
    {
      myservo9.write(pos4);
      opos4=pos4;
    }     
    if (pos5!=opos5)
    {
      myservo10.write(pos5);
      opos5=pos5;
    }    
    delay(1000);
  }
}

void serialEvent() {
  while (Serial.available()) {
     char inChar = (char)Serial.read();
     inputString += inChar;
     if (inChar == '\n') {
      stringComplete = true;
    }
  }
}
Visual basic programVBScript
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Label2 
   BackColor       =   &H00FFFFFF&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Talking Hat"
   ClientHeight    =   5055
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   6795
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5055
   ScaleWidth      =   6795
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmd_add 
      Caption         =   "Add"
      Height          =   420
      Left            =   120
      TabIndex        =   17
      Top             =   3870
      Width           =   1335
   End
   Begin VB.CommandButton cmd_set 
      Caption         =   "Set"
      Height          =   420
      Left            =   1530
      TabIndex        =   16
      Top             =   3870
      Width           =   1335
   End
   Begin VB.VScrollBar VScroll4 
      Height          =   1050
      Left            =   915
      Max             =   20
      Min             =   90
      TabIndex        =   13
      Top             =   1140
      Value           =   20
      Width           =   315
   End
   Begin VB.VScrollBar VScroll3 
      Height          =   1050
      Left            =   3105
      Max             =   20
      Min             =   90
      TabIndex        =   12
      Top             =   1140
      Value           =   20
      Width           =   315
   End
   Begin VB.VScrollBar VScroll2 
      Height          =   1050
      Left            =   1680
      Max             =   20
      Min             =   90
      TabIndex        =   10
      Top             =   2445
      Value           =   20
      Width           =   315
   End
   Begin VB.VScrollBar VScroll1 
      Height          =   1050
      Left            =   2445
      Max             =   20
      Min             =   90
      TabIndex        =   8
      Top             =   2445
      Value           =   20
      Width           =   315
   End
   Begin VB.TextBox txt_rectext 
      Height          =   4095
      Left            =   4440
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   4
      Top             =   195
      Width           =   2250
   End
   Begin VB.CommandButton cmd_run 
      Caption         =   "Run"
      Height          =   420
      Left            =   2940
      TabIndex        =   3
      Top             =   4380
      Width           =   1335
   End
   Begin VB.CommandButton cmd_save 
      Caption         =   "Save"
      Height          =   420
      Left            =   1530
      TabIndex        =   2
      Top             =   4380
      Width           =   1335
   End
   Begin VB.CommandButton cmd_record 
      Caption         =   "Record"
      Height          =   420
      Left            =   120
      TabIndex        =   1
      Top             =   4380
      Width           =   1335
   End
   Begin VB.VScrollBar VScroll5 
      Height          =   1050
      Left            =   2085
      Max             =   20
      Min             =   90
      TabIndex        =   0
      Top             =   120
      Value           =   20
      Width           =   315
   End
   Begin VB.Timer Timer1 
      Interval        =   100
      Left            =   270
      Top             =   2970
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   120
      Top             =   2910
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      CommPort        =   2
      DTREnable       =   -1  'True
   End
   Begin VB.Label Label7 
      Alignment       =   2  'Center
      AutoSize        =   -1  'True
      Caption         =   "No of Records"
      Height          =   195
      Left            =   4470
      TabIndex        =   15
      Top             =   4425
      Width           =   1050
   End
   Begin VB.Label lbl_records 
      AutoSize        =   -1  'True
      Caption         =   "0"
      Height          =   195
      Left            =   5625
      TabIndex        =   14
      Top             =   4425
      Width           =   90
   End
   Begin VB.Label Label2 
      Alignment       =   2  'Center
      AutoSize        =   -1  'True
      Caption         =   "20"
      Height          =   195
      Left            =   1740
      TabIndex        =   11
      Top             =   3555
      Width           =   180
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      AutoSize        =   -1  'True
      Caption         =   "20"
      Height          =   195
      Left            =   2505
      TabIndex        =   9
      Top             =   3555
      Width           =   180
   End
   Begin VB.Label Label5 
      AutoSize        =   -1  'True
      Caption         =   "20"
      Height          =   195
      Left            =   2152
      TabIndex        =   7
      Top             =   1230
      Width           =   180
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      Caption         =   "20"
      Height          =   195
      Left            =   982
      TabIndex        =   6
      Top             =   2310
      Width           =   180
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "20"
      Height          =   195
      Left            =   3172
      TabIndex        =   5
      Top             =   2310
      Width           =   180
   End
   Begin VB.Image Image1 
      Height          =   7485
      Left            =   -2355
      Picture         =   "Form1.frx":0000
      Stretch         =   -1  'True
      Top             =   -900
      Visible         =   0   'False
      Width           =   9060
   End
End
Attribute VB_Name = "Label2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim recrec As Boolean
Dim s As String

Private Sub cmd_add_Click()
    cmd_save.Enabled = False
    cmd_set.Enabled = True
    cmd_record.Enabled = False
    cmd_add.Enabled = False
    recrec = False
    MSComm1.Output = "Add" & vbCrLf
    For i = 1 To 2000
    Next
    MSComm1.Output = "Add" & vbCrLf
    lbl_records.Caption = 0
End Sub
Private Sub cmd_record_Click()
    cmd_save.Enabled = False
    cmd_set.Enabled = True
    cmd_record.Enabled = False
    cmd_add.Enabled = False
    MSComm1.Output = "Record" & vbCrLf
    For i = 1 To 2000
    Next
    MSComm1.Output = "Record" & vbCrLf
    lbl_records.Caption = 0
End Sub
Private Sub cmd_run_Click()
    cmd_set.Enabled = False
    cmd_save.Enabled = False
    cmd_run.Enabled = False
    cmd_record.Enabled = True
    cmd_add.Enabled = True
    MSComm1.Output = "Run" & vbCrLf
End Sub
Private Sub cmd_save_Click()
    cmd_save.Enabled = False
    cmd_run.Enabled = True
    MSComm1.Output = "Save" & vbCrLf
    lbl_records.Caption = Val(lbl_records.Caption) + 1
End Sub
Private Sub cmd_set_Click()
    If Val(lbl_records.Caption) >= 75 Then
        MsgBox "Exit the Save limit", vbInformation, head
        Exit Sub
    End If
    MSComm1.Output = VScroll1.Value & "," & VScroll2.Value & "," & VScroll3.Value & "," & VScroll4.Value & "," & VScroll5.Value & "," & vbCrLf
    cmd_save.Enabled = True
End Sub

Private Sub Form_Load()
    MSComm1.PortOpen = True
    cmd_add.Enabled = True
    cmd_set.Enabled = False
    cmd_save.Enabled = False
    cmd_run.Enabled = False
    recrec = True
End Sub

'Private Sub Timer1_Timer()
'    s = MSComm1.Input
'    If s <> "" Then
'        Text1.Text = Text1.Text & s
'    End If
'End Sub
Private Sub Timer1_Timer()
    s = MSComm1.Input
    If s <> "" Then
        txt_rectext.Text = txt_rectext.Text & vbCrLf & s
        If recrec = False Then
            recrec = True
            lbl_records.Caption = Val(s)
        End If
        txt_rectext.SelStart = Val(Len(txt_rectext.Text))
    End If
End Sub
Private Sub VScroll1_Change()
    Label1.Caption = VScroll1.Value
End Sub
Private Sub VScroll2_Change()
    Label2.Caption = VScroll2.Value
End Sub
Private Sub VScroll3_Change()
    Label3.Caption = VScroll3.Value
End Sub
Private Sub VScroll4_Change()
    Label4.Caption = VScroll4.Value
End Sub
Private Sub VScroll5_Change()
    Label5.Caption = VScroll5.Value
End Sub

Credits

Profile
jegatheesan

Simply A Mechatronics Lover.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login
Community Projects Magazine Maker Faire Shop Share