hello, can someone help me with the code i'm working with in tinkercad? my servo seems to only rotate on one direction. it must either rotate on the left for paper and right for plastic
#include <Servo.h>
#define trigPin 6 //Define the HC-SE04 triger pin 6 on the arduino
#define echoPin 5 //Define the HC-SE04 echo on pin 5 on the arduino
Servo myservo_sensor;
int pos_sensor = 0;
int paper;
int plastic;
long distance;
long duration;
void setup()
{
Serial.begin (9600);
myservo_sensor.attach(8);
myservo_sensor.write(0);
pinMode(7,INPUT);//input pin coming from paper
pinMode(9,INPUT);//input pin coming from plastic sensor(black wire)
pinMode(trigPin,OUTPUT);//set the trigpin to output
pinMode(echoPin, INPUT);//set the echopin to input
pinMode(3, OUTPUT); //Buzzer
delay (3000); }
void loop()
{
paper = digitalRead(7);
plastic = digitalRead(9);
digitalWrite(3,LOW);
Serial.print(" waiting for thrash ");
if(paper == LOW);
{
digitalWrite(3,HIGH);
myservo_sensor.write(40);
delay(3000);
}
if (plastic == LOW)
{
digitalWrite(3,HIGH);
myservo_sensor.write(40);
delay(3000);
}
else
{
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(500);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 04)
{
digitalWrite(3,HIGH);
myservo_sensor.write(40);
delay(2000);
}}}
#include <Servo.h>
#define trigPin 6 //Define the HC-SE04 triger pin 6 on the arduino
#define echoPin 5 //Define the HC-SE04 echo on pin 5 on the arduino
Servo myservo_sensor;
int pos_sensor = 0;
int paper;
int plastic;
long distance;
long duration;
void setup()
{
Serial.begin (9600);
myservo_sensor.attach(8);
myservo_sensor.write(0);
pinMode(7,INPUT);//input pin coming from paper
pinMode(9,INPUT);//input pin coming from plastic sensor(black wire)
pinMode(trigPin,OUTPUT);//set the trigpin to output
pinMode(echoPin, INPUT);//set the echopin to input
pinMode(3, OUTPUT); //Buzzer
delay (3000); }
void loop()
{
paper = digitalRead(7);
plastic = digitalRead(9);
digitalWrite(3,LOW);
Serial.print(" waiting for thrash ");
if(paper == LOW);
{
digitalWrite(3,HIGH);
myservo_sensor.write(40);
delay(3000);
}
if (plastic == LOW)
{
digitalWrite(3,HIGH);
myservo_sensor.write(40);
delay(3000);
}
else
{
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(500);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 04)
{
digitalWrite(3,HIGH);
myservo_sensor.write(40);
delay(2000);
}}}