I had this incredibly minor issue where when the Arduino is initially turned on it goes through the setup bit of the code setting pins to be what ever you want them to be and making them inputs or outputs. As it was doing this and where I had relays attached to these outputs, the relays would momentarily come go into the on position before being turned off in the body of the code as the input is pulled down and then the switch position read. This only really became an issue when I get the horn working on the Arduino. Each time the ignition was turned on the horn would just do the tiniest beep. I did some reading on forums and found a easy coding fix for this.
void setup() {
pinMode(sl, INPUT_PULLUP);
pinMode(db, INPUT_PULLUP);
pinMode(mb, INPUT_PULLUP);
pinMode(FlashLeftHL, INPUT_PULLUP);
pinMode(FlashRightHL, INPUT_PULLUP);
pinMode(ri, INPUT_PULLUP);
pinMode(li, INPUT_PULLUP);
pinMode(hz, INPUT_PULLUP);
pinMode(ws, INPUT_PULLUP);
pinMode(wp, INPUT_PULLUP);
pinMode(dl, INPUT_PULLUP); //dash lights input switch on
pinMode(hn, INPUT_PULLUP); //Horn input switch stalk
pinMode(wk, INPUT_PULLUP); //Wind screen wiper park limit switch input
pinMode(fn, INPUT_PULLUP); //Fan switch
pinMode(potPin, INPUT); //A1
debouncer.attach(7,INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
debouncer.interval(25); // Use a debounce interval of 25 milliseconds
digitalWrite(fld, HIGH);
pinMode(fld, OUTPUT);
digitalWrite(frd, HIGH);
pinMode(frd, OUTPUT);
digitalWrite(frm, HIGH);
pinMode(frm, OUTPUT);
digitalWrite(flm, HIGH);
pinMode(flm, OUTPUT);
digitalWrite(frs, HIGH);
pinMode(frs, OUTPUT);
digitalWrite(fls, HIGH);
pinMode(fls, OUTPUT);
digitalWrite(tls, HIGH);
This fix was to add the digitalWrite in before the pin is set to be an output. Simple eh? it’s worked a real treat. Also I read that moving the pullup’s to before the outputs are set gives the voltage a chance to stabilise before, though I am less convinced by this advice as I don’t think it made any difference.
Comments are closed