Não, só troquei os fios, e to utilizando os pinos 2 e 3. Vou tentar com o 20 pra ver no que dá.
O pushbutton pra testar também não foi uma boa ideia.. a transição do contato do botão é imperfeita..
Vou tentar a dica do capacitor.
O código que estou utilizando para testar é esse: ( com uma arduino mega )
#include <SD.h>
const int chipSelect = 51;
volatile byte rpmcount_D1 = 0;
unsigned long timeold_D1 = 0;
float rpm_D1 = 0, V_D1 = 0;
const int rodaD1 = 2;
void setup()
{
Serial.begin(57600);
Serial.print("Initializing SD card...");
// pinMode(53, OUTPUT);
if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); return; }
Serial.println("card initialized.");
// Velocidade das Rodas ------------------------------------------------------
pinMode(rodaD1,INPUT);
attachInterrupt(0, rev_add, FALLING);
// Velocidade das Rodas ------------------------------------------------------
}
void loop()
{
// Bloco do Sensor Hall ------------------------------------------------
if (rpmcount_D1 >= 4) {
rpm_D1 = 6283.19 / (millis() - timeold_D1) * rpmcount_D1/4;
V_D1 = rpm_D1 * 0.9576; // V [Km/h]
Serial.print("RPMcount: "); Serial.println(rpmcount_D1, DEC);
Serial.print("DeltaT: "); Serial.println((millis()-timeold_D1), DEC);
rpmcount_D1 = 0; timeold_D1 = millis();
Serial.print("V: ");Serial.println(V_D1);
}
// Bloco do Sensor Hall -------------------------------------------------
// make a string for assembling the data to log:
String dataString = "";
// read three sensors and append to the string:
//dataString += String(tempo);
dataString += "DATA";
dataString += ", "; // Adiciona o tempo no inicio da String
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) { dataString += ", "; }
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else { Serial.println("Error opening datalog.txt"); }
}
// Funcoes do Sensor Hall --------------------------------------
void rev_add() { rpmcount_D1++; }