I am working on a project for my car. I am trying to simplify some of the wiring. My plan is to use my Arduino to turn on a relay, using a relay board (pic of the board below). For the purposes of figuring out my code I am substituting the relay for an LED, I have the + side of the LED on on my bread board with a 10k resistor and I have the - side connected to Digital pin 2 of the Arduino. The relay board is ground activated, meaning the relay is turned on when the pin is grounded, and off when it is not. To minimize the amount of wiring in the car I will have a simple on/off switch. When the switch is on the wire is grounded and when the switch is off there is no ground or voltage. My idea is to have the switch ground pin A0 and have the Arduino ground digital pin 2.
I dont know how to tell the Arduino to do this, or if it is even possible to use a switched ground to A0 as an input.
Below is the code I have come up with so far, I have only gotten as far a defining the different inputs/outputs. I am not even sure if this is correct.
This is the first time I have ever attempted to write my own code. I have watched several YouTube videos and searched several different websites trying to find the answer. But its seems everyone uses 0-5v as an input and not ground.
I am starting with just the 1 circuit, the Fuel Pump. I plan on adding several more circuits once I get the code figured out.
Sorry for the crappy hand drawn wiring schematic.
Thank you for any help you can give me!
Here is the code I have come up with so far:
int fuelpumpPin=2; //Pin that controls the FUEL PUMP relay
int ButtonfuelpumpPin=A0; //Pin that turns on the fuel pump
void setup() {
pinMode(fuelpumpPin,OUTPUT);
pinMode(ButtonfuelpumpPin, INPUT);
}
void loop() {
//Switch is turned ON and grounds A0
if (ButtonfuelpumpPin, LOW){digitalWrite(fuelpumpPin,LOW);}
//Switch is turned OFF and the is no ground or voltage to pin A0
else {digitalWrite(ButtonfuelpumpPin,HIGH);}
}




