Hello everyone, recently i moved from an arduino uno to a arduino nano (both clones). i need it for a quickshifter on my motorcycle, i basicly want to send a puls (50ms or so) to a transistor that switches the current. i have a coding that worked with the arduino uno but doesnt work on the nano. the only thing that doesn't work is i have a switch and the arduino needs to read when the switch is pressed in but i can't seem to figure it out.
int cutoff=70; // Set Engine Cutoff time (If you're using relay, do not set timing under 40ms)
int dly=20; // Set Delay time before next Upshift
int i=0;
void setup() {
pinMode(3, INPUT_PULLUP); // Sensor pin
pinMode(7, OUTPUT); // Relay Pin
digitalWrite(5, HIGH); // Set Relay on High State
}
void loop() {
int snsrstate=digitalRead(2);
if (snsrstate==HIGH) {
i=0;
delay(50);
}
if (snsrstate==LOW && i==0) {
i+=1;
digitalWrite(7, LOW);
delay(cutoff);
digitalWrite(7, HIGH);
delay(dly);
}
}
Welcome to the forum. Please read the sticky posts at the top to learn how to get the most out of the forum and maximize your chances for help. It starts with using code tags when posting your code (The IDE supports this!) so people can easily copy/paste/try your code.
As for your issue, the UNO and Nano use the same processor. You are not declaring pin 2 so it defaults to an INPUT which requires a pull-up resistor. Is one present? If not, you either need to install one or declare the pin as INPUT_PULLUP (like pin 3) so the internal pullup resistor is used. Then, make sure the switch is wired between the pin and ground.
#define cutoff 70 // Set Engine Cutoff time (If you're using relay, do not set timing under 40ms)
#define dly 20 // Set Delay time before next Upshift
bool i = false;
#define Sensorpin 3
#define RelayPin 7
#define SetRelayPin 5
void setup() {
pinMode(Sensorpin, INPUT_PULLUP); // Sensor pin
pinMode(RelayPin, OUTPUT); // Relay Pin
pinMode(SetRelayPin, OUTPUT); //
digitalWrite(SetRelayPin, HIGH); // Set Relay on High State
}
void loop() {
if (digitalRead(Sensorpin) == HIGH) {
i = false;
delay(50);
}
if (digitalRead(Sensorpin) == LOW && !i ) {
i = true;
digitalWrite(RelayPin, LOW);
delay(cutoff);
digitalWrite(RelayPin, HIGH);
delay(dly);
}
}
The reason I ask ask and you should be aware of this: 20 years ago my electronic assembly company built circuit boards for a pair of motorcycle enthusiast electronic engineers. Their design paused the fuel injection system momentarily to allow the compressed air piston to shift.
I asked about the ignition kill to stop the engine and they told me about engines backfiring and exploding at high rpm when they and others tried that. The FI pause did not cause engine back fire.
Enjoy!
And yet modern motorcycles cut the ignition, apparently because cutting the fuel doesn't give a reliable cut - there is often enough residual fuel in the inlet tract to give another couple of weak, half-hearted fires before it fully cuts out.
Motorcycle quick-shifting is a hideous kludge anyway. Plenty of gearboxes get destroyed unless the timings are spot on, and the gearbox does need to be mechanically robust. It's totally pointless on a road bike - it was only introduced on race bikes to glean an extra few tenths of a second on a lap time. It's nice, but totally not essential, on a road bike.
You need to be careful with a home built design - you don’t want electrical noise etc to trigger false shifts , which could throw you off the bike .
Not a recommended project IMO
I made a small diagram of how the electronics should work, how i think they should work maybe something has to be changed. i haven't tried the code yet @SteveThackery didn't have time for it.
but maybe this just helps the idea
I don't understand what the 20ms delay at the end of the second if statement is for. One fiftieth of a second delay before the next upshift? You can't move your foot anywhere near that fast. Or have I misunderstood?
The 20ms delay is just a random variable but it's a delay for how long till the next shift so for instance make it 5000ms and you can shift 5sec after the last shift
The first delay statement has a similar effect. It checks if the button has been released (setting i to false if it has), and if it has been released it forces a 50ms delay, and then if the button is pressed at the end of the delay it initiates the next ignition cut. It's a very weird control flow. Here is the flow diagram:
(Sorry, it seems you have to click on the picture to make it a readable size.)
This doesn't look like a good way to do it. Every time round the loop, if it reads the button as released, it forces another 50ms delay. So the response time to a button press will vary between 0 and 50ms. This is absolutely not what you want (the button, in reality, being operated by the gear shift lever, I assume).