(deleted)
LCD_Code_test_2.ino (7.06 KB)
(deleted)
LCD_Code_test_2.ino (7.06 KB)
You could post the code, and we could take a look at it.
Don't forget the code tags.
(deleted)
(deleted)
The code you posted is incomplete.
Please remember to use code tags when posting code
Ok, your code will be posted shortly!
-jim lee
(deleted)
exit(0); :o
(deleted)
(deleted)
(deleted)
So what values are you seeing in your prints of sensorvalue? Any over 1000 or less than 40?
Which values constitute "seeing an object"? And what does the code do?
Steve
(deleted)
And what does your code do NOW!
Steve
sazgar001:
There I corrected the code so you dont see that blunder. Do you know how I should fix this code?#include <Servo.h>
Servo myservoA;
int servopinA = 13;
int IR_A = A0;
int sensorValue = 0;
void setup() {
Serial.begin(9600);
myservoA.attach(servopinA);
myservoA.write(180);
Serial.println();
}
void gosubAservo(){ //servo rotates back and forth until IR Sensor detects pill 1.
delay (500);
sensorValue = analogRead(IR_A);
Serial.println(sensorValue);
if (sensorValue > 1000){
myservoA.write(0);
delay (3000);
myservoA.write(180);
delay(3000);
}else if (sensorValue < 40){
Serial.println(sensorValue);
myservoA.write(180);
}
}
void loop() {
gosubAservo();
}
I don't see an ELSE part in the function gosubAservo. Try using If(sensorValue<40) inside else.Here I corrected for you .Try uploading this and then check.
#include <Servo.h>
Servo myservoA;
int servopinA = 13;
int IR_A = A0;
int sensorValue = 0;
void setup() {
Serial.begin(9600);
myservoA.attach(servopinA);
myservoA.write(180);
Serial.println();
}
void gosubAservo(){ //servo rotates back and forth until IR Sensor detects pill 1.
delay (500);
sensorValue = analogRead(IR_A);
Serial.println(sensorValue);
if (sensorValue >= 1000){
myservoA.write(0);
delay (3000);
myservoA.write(180);
delay(3000);
}else {
if (sensorValue <= 40){
Serial.println(sensorValue);
myservoA.write(180);
}
}
}
void loop() {
gosubAservo();
}
add karma if you like
Topics on the same subject merged
(deleted)
sazgar001:
I tested your code. The outcame makes it to where the servo keeps rotating but stops when IR sensor detects something. However, immediately after the IR sensor no longer detects something, the servo turns again. I want it to where once the object is detected, the servo doesnt move even when the IR sensor does not detect anything. Like once IR sensor detects something even for a short second, the servo goes to 180 degrees and the system ends.
I have made some changes copy and paste exactly it should work now as you want.
#include <Servo.h>
Servo myservoA;
int servopinA = 13;
int IR_A = A0;
int sensorValue = 0;
void setup() {
Serial.begin(9600);
myservoA.attach(servopinA);
myservoA.write(180);
Serial.println();
gosubAservo();
Serial.println("end");
}
void gosubAservo(){ //servo rotates back and forth until IR Sensor detects pill 1.
while(1){
delay (500);
sensorValue = analogRead(IR_A);
Serial.println(sensorValue);
if (sensorValue >= 1000){
myservoA.write(0);
delay (3000);
myservoA.write(180);
delay(3000);
}else {
if (sensorValue <= 40){
Serial.println(sensorValue);
myservoA.write(180);
break;
}
}
}
}
void loop() {
}
Add Karma if you like
goto p; :o
TheMemberFormerlyKnownAsAWOL:
goto p;:o
Corrected it in the original post .Thanks for pointing out.
If he didn't see the correction I'll post the code again here
#include <Servo.h>
Servo myservoA;
int servopinA = 13;
int IR_A = A0;
int sensorValue = 0;
void setup() {
Serial.begin(9600);
myservoA.attach(servopinA);
myservoA.write(180);
Serial.println();
gosubAservo();
Serial.println("end");
}
void gosubAservo(){ //servo rotates back and forth until IR Sensor detects pill 1.
while(1){
delay (500);
sensorValue = analogRead(IR_A);
Serial.println(sensorValue);
if (sensorValue >= 1000){
myservoA.write(0);
delay (3000);
myservoA.write(180);
delay(3000);
}else {
if (sensorValue <= 40){
Serial.println(sensorValue);
myservoA.write(180);
break;
}
}
}
}
void loop() {
}