Hi, I have an Arduino Uno, which has been running into a few problems lately.
I've been using it with a range finder with a piezo alarm, which worked perfectly with no issues since pretty much when I made it, until earlier I tried it and the pin which made the rangefinder ping stopped working. I had also programmed it so that it wouldn't turn on the piezo if it recieved 0 as a distance (in case it errors) but when I plug it in, the rangefinder never does anything and it turns on the piezo and it doesn't stop!
I'm using this script:
const int inping = 3;
const int outping = 5;
const int response = 4;
void setup() {
pinMode(11,OUTPUT);
pinMode(3,OUTPUT);
Serial.begin(9600);
pinMode(inping,INPUT);
pinMode(outping,OUTPUT);
}
void loop() {
long duration, inches, cm;
Serial.println("Starting Pulse");
digitalWrite(outping, LOW);
delayMicroseconds(2);
digitalWrite(outping, HIGH);3
delayMicroseconds(5);
digitalWrite(outping, LOW);
Serial.println("Pulse Finished");
duration = pulseIn(inping, HIGH,20000);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
if (cm < 60 != 0) {
alarm();
}
Serial.print(cm);
Serial.print("\n");
delay(10);
}
long microsecondsToInches(long microseconds) {
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds) {
return microseconds / 29 / 2;
}
void alarm() {
for (int i = 0; i < 255; i++) {
tone(response,i);
delay(10);
}
noTone(response);
}
Then to test the pins, I made this simple test script and changed the outping pin to test each one:
const int outping = 4;
void setup() {
// put your setup code here, to run once:
pinMode(outping,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(outping, HIGH);
delay(200);
digitalWrite(outping, LOW);
delay(200);
}
I attatched an LED to the pin I was testing each time, and it NEVER lit up!
Even though the speaker pin for the previous script worked, I have no idea why it didn't work this time?
Is my Arduino Uno broken because it's ignoring parts of my script and pins work 50% of the time?