Prototype 005
Materials: PIC16F88, breadboard, servo, pot
Notes:
- The servo could keep turning left and right, but I couldn’t control its speed and directions.
- I found that Arduino has a servo library that is easy to use for controlling servos. So I decided to switch to Arduino board.
servo test from maze on Vimeo.
Prototype 006
Materials: Arduino, servo, breadboard, IR sensor
Notes:
- In the very beginning, the range of IR sensor was too small. Thus the servo only moved when I almost touched the sensor. Here I scaled the value of IR sensor from 0-1023 to 0-179.
- The servo had a problem of drawing too much current.
- So I did iteration by separating power supply for the servo, but joined the grounds of the two power supplies. I also added decoupling capacitors to stabilize my voltage regulator.
prototype_arduino+servo+ir sensor from maze on Vimeo.
- Here is the code:
--------------------------------------------------------------------------------------------------------
#include <Servo.h>
Servo myservo; //create servo object to control a servo
int sensor = 0; // analog pin used to connect the sensor
int motorPin=11;
int val; // variable to read the value from the analog pin
void setup()
{
myservo.attach(11);
myservo.setMaximumPulse(2200);
Serial.begin(9600); // set up Serial library at 9600 bps
pinMode(sensor, INPUT);
//pinMode(relay, OUTPUT);
pinMode(motorPin, OUTPUT);
myservo.setMaximumPulse(2000);
myservo.setMinimumPulse(700);
Serial.print("Ready\n");
}
int getSensor() {
val = analogRead(sensor); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val=max(val,5);
val=min(val,180);
return val;
} //end of getSensor
/*
int moveFoward() {
analogWrite(motorPin, getSensor());
delay(1000);
digitalWrite(motorPin, LOW);
delay(1000);
//digitalWrite(relay, HIGH);
//Serial.println(getIR());
delay(1000);
}
int moveBackward() {
analogWrite(motorPin, getSensor());
delay(1000);
digitalWrite(motorPin, LOW);
delay(1000);
//digitalWrite(relay, LOW);
//Serial.println(getIR());
delay(1000);
}
*/
void loop()
{
/*
val=getSensor();
if (val<140){
val=180;
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}//end of if
while(getSensor()>30){
myservo.write(getSensor());
Serial.println(getSensor());
delay(15);
}//end of while
*/
myservo.write(getSensor());
Serial.println(getSensor());
delay(15);
//moveFoward();
//moveBackward();
Servo::refresh();
}
-------------------------------------------------------------------------------------------------
- I tried to pause the servo after every time it turns by expanding the delay time of myservo.write(). However, its movement became unpredictable. Then I tried moveFoward() and moveBackward() above, but they didn’t work well either.
- Another problem I have is the click sound of servo. I was wondering if extreme turning angles like 179 or 180 caused those noise.
Recent Comments