I am trying to make a solenoid control for a maple sap tank. The tank is under vaccum to draw the sap into it like a straw. I have two float switches inside to control when a solenoid valve opens to allow air in to drain the tank and to close the valve to return the tank to vaccum. I am using a Alamscn mini Nano v3.0 with a ATmega328p chip, screw down base for the Nano, and a one relay module. it is powered by a 12v, 5A power supply. I would like to have the Nano veiw the switches as momentary push buttons, and I cannot see why that is not possible, both are just switches. The program I wrote compiles good and uploads just fine. The inputs seem to work like they are supposed too (pin 4 bottom switch, pin 5 top switch), but the output (pin 7) does not send any signal to the relay to open and close it. Always read 0v. What i got is below.
#import <Arduino.h>
//Float Switch
int top = 5; //Pin Reed
int bottom = 4;//Pin Reed
int relay = 7; //relaysignal
void setup() { //code that only runs once
// set pin modes
pinMode(top, INPUT_PULLUP);//setup top float switch
pinMode(bottom, INPUT_PULLUP);//setup bottom float switch
pinMode(relay, OUTPUT);//setup relay trigger
Serial.begin(9600);//print to serial
}
// set switch state
int topstate = digitalRead(top); // set hls switch
int bottomstate = digitalRead(bottom); //set lls switch
void loop(){
//compare hls state has changed, open solenoid
if (top != topstate) {
// if the state has changed, turn on solenoid
if (top == HIGH) {
// if the current state is high then switch went from on to off
digitalWrite(relay, HIGH);
}
// little delay to avoid bouncing
delay(500);
}
// save current hls state as last state, for next time through the loop
int topstate = digitalRead(top);
//compare lls state has changed, close solenoid
if (bottom != bottomstate){
// if the state has changed, turn off solenoid
if (bottom = LOW);{
// if the current state is high then button went from off to on
digitalWrite(relay, LOW);
}
delay(500);
}
// save current lls state as last state, for next time through the loop
int bottomstate = digitalRead(bottom);
}
Any help would be nice, thanks
Rob, Backyard Syrup Co.