You are on page 1of 6

De La Salle University-Dasmarinas

College of Engineering Architecture and Technology

Electronics Engineering Department

Fundamentals of Robotics Laboratory

Experiment # 4

Sensor(Potentiometer) with Serial Communications

Group # 6

ECE51

GOMEZ, John Jewel F.

DOP: March 16,2018

DOS: March 23, 2018

Engr. Roselito E. Tolentino

Instructor
I. DATA

Arduino

// Controlling a servo position using a val = analogRead(potpin); // reads the


potentiometer (variable resistor) value of the potentiometer (value between 0
and 1023)
#include <Servo.h>
val = map(val, 0, 1023, 0, 179); // scale it to
Servo myservo; // create servo object to
use it with the servo (value between 0 and
control a servo
180)

myservo.write(val); // sets the servo


int potpin = 0; // analog pin used to position according to the scaled value
connect the potentiometer
Serial.println(val);
int val; // variable to read the value from
delay(15); // waits for the servo
the analog pin
to get there

}
void setup()

Serial.begin(9800);

myservo.attach(9); // attaches the servo


on pin 9 to the servo object

void loop()

{
Visual Studio

Public Class Form1


Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SerialPort1.Open()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


SerialPort1.Write(TextBox1.Text & vbNewLine)
TextBox3.Text &= "Group 1: " & TextBox1.Text & vbNewLine
TextBox1.Clear()
End Sub

Private Sub SerialPort1_DataReceived(sender As Object, e As


IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
readtext(SerialPort1.ReadLine)

End Sub

Private Sub readtext(ByVal [text] As String)

If TextBox2.InvokeRequired Then
Dim x As New SetTextCallback(AddressOf readtext)
Invoke(x, New Object() {(text)})
Else
TextBox2.Text &= "Group 1: " & [text] & vbNewLine
End If
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles
TextBox2.TextChanged, TextBox2.EnabledChanged

End Sub
End Class

II. OUTPUT

Figure 1. Arduino Connections


Figure 2. Configuration and Setup

Figure 3. Data Display Interface

III. Analysis

In this experiment , we are about to learn to how to control the servo motor using the

potentiometer as a sensor. The maximum single rotation of the potentiometer has

approximately 270 degrees. The first part in the code is setting up the potentiometer

which is analog read and it’s designated pins. The second part is setting up the servo

motor and it’s pins. In the visual studio, the first part is setting up the serial port for the

potentiometer. The second part is setting up for the serial monitor like in the arduino.
IV. Conclusion

Based on the experiment, the researchers learn how to control the servo motor using the

potentiometer as a sensor. The potentiometer has an approximately 270 degrees rotation.

As you rotate the potentiometer, the servo motor also rotates. In the visual studio it shows

the received message that is coming from the arduino which is like counter part of the

serial monitor.

You might also like