I'm trying to run a vent flap actuator with a forward/reverse module through a nano every. I've only used the standard nano before, I accidentally ordered a nano every, so here we go.
It's a simple on/off toggle, meant to operate as: on-flapdown, off-flapup. It's working once, and then not allowing more switch inputs. Once I flip the switch, it follows the correct input from the switch. But just one time. I've tried internal and external pull-ups for the input pin 2, 10k external though not 7.4, if that matters?
I've made a similar unit before with a standard nano, and it worked fine. I must be missing something!
/*
Vent Controller with AC
*/
#include <Servo.h>
int ac = 2; // 0v to pin opens condenser flaps
int openflap = 10;
int closeflap = 9;
int acval;
void setup() {
pinMode(ac, INPUT);
pinMode(openflap, OUTPUT);
pinMode(closeflap, OUTPUT);
digitalWrite(openflap, HIGH);
digitalWrite(closeflap, HIGH);
}
void loop() {
acval = analogRead(ac);
if (digitalRead(acval) == LOW) {
digitalWrite(openflap, LOW);
digitalWrite(closeflap, HIGH);
}
else {
digitalWrite(openflap, HIGH);
digitalWrite(closeflap, LOW);
}
delay(10);
}
So you read an analogue input and use it to determine the pin to read; just consider what happens if acval equals e.g. 500? You're code will read pin 500 (probably 500 - 256); does that pin exists?
I'm clearly not a great programmer lol... I'm just trying to sense a ground input on A2, when ground input is present I want it to trigger D10 to low, and when it's not present I want D9 to go low and 10 to switch high. I think my program might be overcomplicated?
then use it as if it is digital. @someone made the assumption you meant to be testing an analog value for being above, or below, some threshold and used a random value between the extremes possible, 0 to 1023 the range of analogEead().
If it is a digital value or sensor on the pin, use digitslRead(), which will indeed return either HIGH or LOW.
Or make it clear what is on the pin, why you used analaogRead().
You might have
acval = (analogRead(ac) > 500) ? HIGH : LOW;
to do the conversion. Direct use of the analog value like you have is not sensible.
buttons are typically connected between the pin and ground, the pin configured as INPUT_PULLUP to use the internal pullup resistor which pulls the pin HIGH and when pressed, the button pulls the pin LOW.
a button press can be recognized by detecting a change in state and becoming LOW
I've tried internal pullup, but right now I've got a 10k external pullup resistor installed from 5v to the A2 pin. Could this be something to do with the Nano Every? I've not had this problem with the standard Nano
The terminal blocks and 5v regulator aren't being used for this, it's just a little test rig that I use for arduino projects of different types. The switch on the right switches ground from GND pin to pin 4, with an external 10k pullup. The fwd/reverse relay module just looks for ground on the blue/green wires to trigger forward or reverse.
Oh wow, I actually switched it to a4, thinking maybe 2 wasn’t working. I copied the sketch before I updated it. Do I have to call the pin a4 instead of 4? I haven’t had to do that in the past?
After testing with a multimeter, the switch input is registering properly to the arduino. The output pins are reading .6ohm to ground on D9 and nothing on D10. When I flip the switch, D9 goes to no contact, and D10 is .6ohm. It's not enough connection to ground for the fwd/rev relay module to see it though, what could cause this?