Hello guys,
I am making a project that detects if a laser is blocked and then does some operations.My servo is connected to +5v external power supply but it gets fixed in one position as soon as all the pins are attached.Here is the code:
#include <Servo.h>
Servo servo;
double _speed;
double DIST = 4.5;
long time1;
bool blocked1 = false;
bool blocked2 = false;
bool unblock = false;
bool blocked = true;
bool enter = false;
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 7, d5 = 6, d6 = 4, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
servo.attach(2);
servo.write(5);
pinMode(5,OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setCursor(0,0);
// Print a message to the LCD.
lcd.print("Speed");
lcd.setCursor(0, 1);
lcd.print("");
Serial.begin(9600);
}
void loop()
{
if(analogRead(A5)<500)
blocked1 = true;
else
blocked1 = false;
if(analogRead(A0)<500)
blocked2 = true;
else
blocked2 = false;
if(blocked2&&blocked)
{
if(!enter)//recording the first time the flow enters this if block
{
time1 = millis();
enter = true;
}
analogWrite(5,255);
if(analogRead(A5)<300)
{
lcd.print
(DIST*1000/(millis()-time1));
lcd.print("cm/s");
//delay(3000);
servo.write(90);
blocked = false;
servo.detach();
}
}
if(digitalRead( 8 )==HIGH)
unblock = true;
else
unblock = false;
if(unblock)
{
analogWrite(5,0);
servo.write(0);
unblock = false;
}
Serial.println(analogRead(A5));
}
The servo was working fine untill i just changed made the jumper wires longer by connecting more wires.And i have tested it there is continuity.
Please help guys,its urgent.