Manual

www.nexusrobot.com Robot Kits manual
19
Select the display Baud Rate
¾ Analog Read Serial
Sharp 2D12 Example
This example shows you how to read analog input, which from the physical world using a Sharp 2D12. A
Sharp 2D12 is a simple mechanical device that provides a varying amount of resistance when its shaft is
turned. By passing voltage through a Sharp 2D12 and into an analog input on your Arduino, it is possible
to measure the amount of resistance produced by a Sharp 2D12 (or pot for short) as an analog value. In
this example you will monitor the state of your Sharp 2D12 after establishing serial communication
between your Arduino and your computer.
Sample code
const int GP2Y0A21 = 0; //set analog pin 0 as the signal pin
void setup()
{
Serial.begin(9600);
}
void loop()
{
int val = 0;
val = ((10485/(analogRead(ISRpin[0])+5))-4); //read the data from signal pin
Serial.println(val,DEC); // display
delay(500);
}
¾ Servo Motor Theory
Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be
connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be
connected to a ground pin on the Arduino board. The signal pin is typically yellow, orange or white and
should be connected to a digital pin on the Arduino board. Note servos draw considerable power, so if