Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views3 pages

Week 2 Robotics Code

This document provides instructions for using the Arduino IDE to control a crane using servo motors. It includes steps for uploading code, connecting the Arduino, and modifying values to control motion. The code utilizes potentiometers to read input values and map them to servo positions.

Uploaded by

Riya Mitra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Week 2 Robotics Code

This document provides instructions for using the Arduino IDE to control a crane using servo motors. It includes steps for uploading code, connecting the Arduino, and modifying values to control motion. The code utilizes potentiometers to read input values and map them to servo positions.

Uploaded by

Riya Mitra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

​ Open up the Arduino IDE


2.​ Copy and paste the code below into the IDE
3.​ Connect the Arduino to the computer using a cable
4.​ Click on “Tools” and select the Port and Board
5.​ Click the arrow in the top left hand corner to upload the code onto
the Arduino

6.​ Spend a lesson changing the values to control the motion of the
crane

#include <Servo.h>

Servo myservo1; // create servo object to control a servo


Servo myservo2;

int potpin1 = A0;


int potpin2 = A1; // analog pin used to connect the potentiometer

int val1;
int val2; // variable to read the value from the analog pin

void setup() {

myservo1.attach(9); // attaches the servo on pin 9 to the servo


object
myservo2.attach(10);
Serial.begin(9600);
}

void loop() {

val1 = analogRead(potpin1); // reads the value of the


potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 0, 200);
val2 = analogRead(potpin2);
val2 = map(val2, 0, 1023, 0, 200); // scale it to use it with the
servo (value between 0 and 180)

int potpin = A0;

Serial.print("value of x - ");
Serial.println(val1);
Serial.print("value of y - ");
Serial.println(val2);

myservo1.write(val1);
myservo2.write(val2);

You might also like