Hello,
This is my first time using an Arduino, I am using an UNO and am stuck with the programming.
What i am attempting to do is turn on an input1 with a push button, and have this input turn on an output, the outputted 5V will trigger a MOSFET which will turn on a 12 V solenoid valve, the valve will stay on as long input2 is below a certain point. The second input (input2) will be an analog input and it will be coming from an amplified pressure sensor bridged scale (the valve will be distributing water onto the scale until the certain voltage is achieved due to the weight). My code is shown below, I am having a problem with almost everything and I am not sure where to start with debugging it. The analog value will not show (I tried to make the analog value between 0-5 with line “float voltage = sensorValue * (5.0 / 1023.0);” but i am not sure if this is correct), another issue is that when the program is uploaded, my arduino automatically turns on the output for the MOSFET, even if the first input button isn’t pressed, I set the analog value to be 5V right now for shutting off the output just so that i can trigger it with a switch directly to a 5V source.
int inpin = 2;
int val = 0;
void setup() {
pinMode(2, INPUT); // set the switch pin to be an input
pinMode(3, INPUT); // set the switch pin to be an input
pinMode(4, INPUT); // set the switch pin to be an input
pinMode(6, OUTPUT); // set the switch pin to be an output
}
void loop() {
//Read the analog input from the scale
int sensorValue = analogRead(A0);
// set voltage between 5 volts
float voltage = sensorValue * (5.0 / 1023.0);
//print the analog value to the analog screen
Serial.println(voltage);
//set "val" to the value on "inpin" (2)
val = digitalRead(inpin);
// read the switch input:
if (val == HIGH) {
do
{
// if the switch is closed
digitalWrite(6, HIGH); // turn on the yellow LED
}
//If the analog input from the scale is equal to or greater then 5
while (voltage < 5.0);
}
else {
digitalWrite(6, LOW);
}
}
Thanks a ton!
Any comments or help with this problem is appreciated