This is my first Arduino based project. The fuel tap on my motorcycle is remote operated and currently works with bowden cables and a rotary control mounted on the fairing. I want to make this a complete electronic and mechanical solution. here is what I want to do:-
Use a servo to rotate the fuel tap on the fuel tank to between on, off and reserve. This will be single connecting rod between the servo output and a crank fitted to the fuel tap.
Use a single button push switch and single multicolour LED to signal status so when I push the switch it cycles through off, on and reserve. This would be signalled on the LED by RED for OFF, GREEN for ON and AMBER for RESERVE.
I want it to be powered by a 9V battery and have a timer off function where after say 10 seconds it automatically turns off unless running in reserve position in which case i want it to stay on until I select off or on when refuelling.
Is this feasible with a Nano circuit board and a 9V battery and what other equipment would I need, Could I feasibly construct this with an Arduino starter set and purchasing an arduino nano board to use. Is there any suitable tutorials to follow tat would help me with this?
What sort of 9V battery do you have in mind ?
Not a PP3 as used in smoke alarms I hope as they cannot supply enough current for long. Does the motorcycle not have its own battery ?
The project as described is well within the capabilities of a Nano
Yes it’s possible, why not power it off your 12v system, with some filtering and power conditioning it is possible to tap off the bikes battery. 9v batteries don’t have much juice and if you time out your circuit shouldn’t have any issues.
For sensing whether the bike is on, you might use a switched power pin to generate an on signal or latching circuit.
Positional control is possible but this will be your biggest challenge and without understand the current set up hard to say much more than that.
You will have to convert 12v levels to 5v for the sensing
For research look up the separate sections in google.. such as how to power Arduino from vehicle or positional control of dc motor... etc
Come up with a plan and check back here for more help and suggestions.
I was thinking PP3 but having just done a quick check on their amp hour rating 500mAh just doesn't cut it. I could use the bikes main wiring loom however splicing into it will require a little bit of research as to where best I can get a supply and that is the long term plan, The short term to get it up and running and operational will be a battery solution, having had a quick look at feasible batteries a AA 4 pack could supply the required current as I have experience of those from IC aircraft. Cheers for the suggestions so far I will have a look and see. Need to purchase a dev kit, nano, a servo and a multicolour LED to start with and practise each stage
You could run the nano directly from a pack of 3 x AA alkaline cells (4.5v) or 4 x AA NiMh cells (4.8v) connected to the 5v pin. However you should check whether the servo would have enough torque at that voltage.
If you can drop the bike's 12v supply down to a regulated 5v it could also directly power the nano.
So working on this a little further. Have designed the circuit in Tinkercad to make sure my thinking is correct and can correct before I start coding, I know it's an Uno even though I plan to use a Nano however I'm hoping transferring to the Nano won't be too difficult. I'm going to put in a 12v-5v step down unit when fitting it to the bike so the Nano has a 5v power source from the motorbike. To address concerns on servo torque its a metal gear servo that kicks out 2.2kg of torque, I can rotate the fuel tap with my finger which I doubt requires more than 2kg of force. Safety I'm taking precautions in that the control unit will be mounted up on the fairing away from the fuel tank and will be in an enclosure that I will try to make as intrinsically safe as I can (ATEX Hazardous Area Electrical Protection concept-encapsulation) and cables will be soldered and heat shrink connections. Further safety protection I'm hoping can be added to the code in the form of power and standby functionality.
Assuming my circuit is correct here is how I wish to use the system and what I think needs to happen however I'm unsure how to begin the coding but here is what needs to happen:-
1-Ignition turns on, relay switches 12v power to step down regulator providing 5v to the arduino
2-Arduino switches on and notes the position of the servo (three choices here will be 0=FUEL ON, 90=FUEL OFF and 180=FUEL RESERVE degrees)
3-The Arduino then uses this positional information to turn on either the red (OFF), green(ON) or orange(RESERVE) LED
4-If the LED is red or green then the light will time out after 30 seconds and the arduino will go into standby awaiting a button press. If LED is orange then the light will blink until the button is pressed to turn the position of the servo to off or on
5-If the button is pressed, The arduino will question the servo position and if it is in the ON position with the Green LED illuminated and the button is pressed again within 10 seconds then the position of the servo will be updated to the RESERVE position and the Orange LED will begin to blink until it is turned to the off position.
6-If the Servo and LED is in the OFF position and the button is pressed the Servo and LED will change to the ON position
I'm going to look at a variety of different tutorials and try and get each section working independent of each other and slowly building up the code so that both work together.
So I've now sorted my circuit and written some basic code and have chosen to simplify this code for just now to make it easy and to get it working. For my first arduino coding project I'm quite pleased how quickly I've been able to get this far in an afternoon using a simulator to test my proof of concept. I've gotten the code to initialise on power on into the default position of FUEL ON (Green LED ON and Servo @ 0 Degrees) so that if there is a problem such as stalling or an electrical outage and reset it will always be on fuel on. I can cycle through my RESERVE and OFF settings however I am stuck as to what code I should write to allow me to cycle back through from OFF to RESERVE to ON. Here is the code i've written so far:-
//Libraries
#include <Servo.h>
//Definitions
#define button 2 //Push Button Input on Pin 2
#define redLED 6 //Red LED on Pin 6
#define orangeLED 5 //Orange LED on Pin 5
#define greenLED 4 //Green LED on Pin 4
int servoPin = 3; //Servo on Pin 3
Servo Servo1; //Create Servo Object
//States
int state = 0; //Integer to hold current state
int old = 0; //Integer to hold old state
int buttonPoll = 0; //Integer to hold button state
//Setup
void setup (){
pinMode(button,INPUT); //Button set as input
pinMode(redLED, OUTPUT); //Red LED set as output
pinMode(orangeLED, OUTPUT); //Orange LED set as output
pinMode(greenLED, OUTPUT); //Green LED set as output
Servo1.attach(servoPin); //Servo set as output
digitalWrite(redLED, LOW); //Sets Red LED to OFF
digitalWrite(orangeLED, LOW); //Sets Orange LED to OFF
digitalWrite(greenLED, HIGH); //Sets Green LED to ON
Servo1.write (0); //Sets Servo position to FUEL ON Position
}
//Loop
void loop (){
//debouncing routine to read button
buttonPoll = digitalRead(button); //poll the state of the button
if (buttonPoll == 1){ //check if it has been pressed
delay(100); //wait 100ms
buttonPoll = digitalRead(button); //poll button again
if(buttonPoll == 0){ //If it is 0 considered one press
state = old + 1; //increase state by 1
}}
else{ //If button has not been pressed
delay (150); //wait 150ms
}
switch (state){ //react to button press and state
case 1:
digitalWrite(greenLED, HIGH); //Green LED ON
digitalWrite(orangeLED,LOW); //Orange LED OFF
digitalWrite(redLED,LOW); //Red LED OFF
Servo1.write(0); //Servo Set to 0 Degrees FUEL ON
old = state; //Set old state to current state
break;
case 2:
digitalWrite(greenLED, LOW); //Green LED Off
digitalWrite(orangeLED, HIGH); //Orange LED ON
digitalWrite(redLED, LOW); //Red LED OFF
Servo1.write(90); //Servo moved to FUEL RESERVE
old = state;
break;
case 3:
digitalWrite(greenLED, LOW); //green LED OFF
digitalWrite(orangeLED, LOW); //orange LED OFF
digitalWrite(redLED, HIGH); //red LED ON
Servo1.write(180); //servo moved to FUEL OFF
old = state;
break;
}
}
And I've now fixed it. Massive thanks to those who helped. If anyone has any suggestions to improve my code, please let me know as it is much appreciated
//Libraries
#include <Servo.h>
//Definitions
#define button 2 //Push Button Input on Pin 2
#define redLED 6 //Red LED on Pin 6
#define orangeLED 5 //Orange LED on Pin 5
#define greenLED 4 //Green LED on Pin 4
int servoPin = 3; //Servo on Pin 3
Servo Servo1; //Create Servo Object
//States
int state = 0; //Integer to hold current state
int old = 0; //Integer to hold old state
int buttonPoll = 0; //Integer to hold button state
//Setup
void setup (){
pinMode(button,INPUT); //Button set as input
pinMode(redLED, OUTPUT); //Red LED set as output
pinMode(orangeLED, OUTPUT); //Orange LED set as output
pinMode(greenLED, OUTPUT); //Green LED set as output
Servo1.attach(servoPin); //Servo set as output
digitalWrite(redLED, LOW); //Sets Red LED to OFF
digitalWrite(orangeLED, LOW); //Sets Orange LED to OFF
digitalWrite(greenLED, HIGH); //Sets Green LED to ON
Servo1.write (0); //Sets Servo position to FUEL ON Position
}
//Loop
void loop (){
//debouncing routine to read button
buttonPoll = digitalRead(button); //poll the state of the button
if (buttonPoll == 1){ //check if it has been pressed
delay(50); //wait 50ms
buttonPoll = digitalRead(button); //poll button again
if(buttonPoll == 0){ //If it is 0 considered one press
state = old + 1; //increase state by 1
}}
else{ //If button has not been pressed
delay (100); //wait 150ms
}
switch (state){ //react to button press and state
case 1:
digitalWrite(greenLED, HIGH); //Green LED ON
digitalWrite(orangeLED,LOW); //Orange LED OFF
digitalWrite(redLED,LOW); //Red LED OFF
Servo1.write(0); //Servo Set to 0 Degrees FUEL ON
old = state; //Set old state to current state
break;
case 2:
digitalWrite(greenLED, LOW); //Green LED Off
digitalWrite(orangeLED, HIGH); //Orange LED ON
digitalWrite(redLED, LOW); //Red LED OFF
Servo1.write(90); //Servo moved to FUEL RESERVE
old = state;
break;
case 3:
digitalWrite(greenLED, LOW); //green LED OFF
digitalWrite(orangeLED, LOW); //orange LED OFF
digitalWrite(redLED, HIGH); //red LED ON
Servo1.write(180); //servo moved to FUEL OFF
old = state;
break;
default:
digitalWrite(greenLED, HIGH); //Green LED ON
digitalWrite(orangeLED,LOW); //Orange LED OFF
digitalWrite(redLED,LOW); //Red LED OFF
Servo1.write(0); //Servo Set to 0 Degrees FUEL ON
old = 0; //reset to state 0
break;
}
}
/code]