hello, new here.
working on a project.
testing it as i go, so I'm just starting the code.
I have 2 LED's to test my outputs. when the signal is low they shut off like they are supposed to, but when they're off, they pulse about once a second, very dim hard to see, but still a problem. I tried it on multiple pins and it still does it.do these need a pulldown resister? any suggestions?
here is my sketch so far, again I'm just starting it so it might not make sense cause its not done
#define echoPin 8 // Echo Pin
#define trigPin 9 // Trigger Pin
#define M1F 7
#define M1R 11
#define M2F 12
#define M2R 10
int maximumRange = 200; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(M1F,OUTPUT);
pinMode(M1R,OUTPUT);
pinMode(M2F,OUTPUT);
pinMode(M2R,OUTPUT);
}
void loop() {
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
/*motor code
*/
digitalWrite(M1F, HIGH);
digitalWrite(M2F,HIGH);
if (distance < 50 ){
digitalWrite(M1F,LOW);
digitalWrite(M2F,LOW);
delay(1000);
}
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
if (distance >= maximumRange || distance <= minimumRange){
/* Send a negative number to computer and Turn LED ON
to indicate "out of range" */
Serial.println("-1");
}
else {
/* Send the distance to the computer using Serial protocol, and
turn LED OFF to indicate successful reading. */
Serial.println(distance);
}
//Delay 50ms before next reading.
delay(50);
}