Author Topic: arduino uno pin issue  (Read 1295 times)

0 Members and 1 Guest are viewing this topic.

Offline justariderTopic starter

  • Newbie
  • Posts: 2
  • Country: us
  • hello, amature at everything, love to tinker :)
arduino uno pin issue
« on: June 06, 2016, 01:36:40 am »
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);
}
 

Offline botcrusher

  • Regular Contributor
  • *
  • Posts: 192
  • Country: ca
Re: arduino uno pin issue
« Reply #1 on: June 06, 2016, 02:24:44 am »

 /*motor code
  */
digitalWrite(M1F, HIGH);
digitalWrite(M2F,HIGH);

if (distance < 50 ){
  digitalWrite(M1F,LOW);
  digitalWrite(M2F,LOW);
  delay(1000);
}


Here, the problem is that you turn the output on before evaluating the distance. Check the distance first, then output it if you need to.
 
The following users thanked this post: justarider

Offline justariderTopic starter

  • Newbie
  • Posts: 2
  • Country: us
  • hello, amature at everything, love to tinker :)
Re: arduino uno pin issue
« Reply #2 on: June 06, 2016, 01:32:51 pm »
Oh duh lol THANK YOU!  😊
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf