Simple Arduino Question about input from one pin turning other pin on/off

Hello everyone,

I am currently working on a simply project, I believe.

I have a wind vane with a potentiometer that I am trying to get to work in conjunction with a solenoid. I have the wind vane set up on an analog pin at this point, with power going to it.

So, I want the solenoid to close if the wind direction is +/- 20 degrees from 180.
Right now, I can get the solenoid to loop open and close on a delay, but it needs to only be shut IF in the 40 degree range.

Any help would greatly be appreciated.

Let's assume that analogRead() of the pot returns between 500 and 700 when the vane is in the required range then

int direction = analogRead(vanePotPin);
if (direction >= 500 && direction <= 700)
{
  //code here to close the solenoid.
}
else
{
  //code here to open the solenoid
}

Note that the code would be easier to understand if you used map() to convert the value from analogRead() into degrees, but I suggest that you use the raw value to start with and add map() later.

UKHeliBob:
Let's assume that analogRead() of the pot returns between 500 and 700 when the vane is in the required range then

int direction = analogRead(vanePotPin);

if (direction >= 500 && direction <= 700)
{
  //code here to close the solenoid.
}
else
{
  //code here to open the solenoid
}



Note that the code would be easier to understand if you used map() to convert the value from analogRead() into degrees, but I suggest that you use the raw value to start with and add map() later.

Thanks a ton, I may have a bad connection as well somewhere in the RJ11 cable that I am using. Guess I should check that as well.

I'm familiar with the map() function and will definitely try to incorporate that as well.

Okay, Heli...

I have checked connections and all.

I ran the typical blink code to see if the solenoid was OK and that seems to be fine when powered on through the relay.

The code that I have does not trip the solenoid when it reaches that 500-700 range even after map() function was used. Any Suggestions? It's using the Davis anemometer.

Sketch_vane.ino (307 Bytes)

What does:

Serial.println(direction);

tell you?

How exactly is the pot wired to the Arduino ?