HELP NEEDED DEADLINE AT MARCH 14TH! TRYING TO MAKE ELECTRIC BALL VALVE WORK

I have a USS-MSV00011 that I’m trying to control with an arduino. When something gets close enough, a servo will spin (for something else to trigger) and the valve should open. I read that it can be used with an arduino, but Google gives me no results on how to actually use it. I should also probably mention that the valve needs a 9-volt input, and I’ve been trying to figure out how to send a 9-volt input to it. Here’s my code:

#include <Servo.h>
int trigPin = 4; //Trig - green Jumper
int echoPin = 2; //Echo - yellow Jumper
long duration, cm, inches;
int servoPin = 6;
int OnPin = 12;
int OffPin = 13;
boolean unturnNeed = false;

Servo servo;
int angle = 0;

void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(OnPin, OUTPUT);
pinMode(OffPin, OUTPUT);
servo.attach(servoPin);
// command to move from 0 degrees to 180 degrees

}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(5); // put low first to make sure there are no disturbances
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // keep it on high for 10 microseconds
digitalWrite(trigPin, LOW); // stop the pulse
// Read the signal from the sensor: a HIGH pulse whose duration is the time (in microseconds)
// from the sending of the ping to the reception of its echo off of an object.
duration = pulseIn(echoPin, HIGH); // this function measures the time until the echo
cm = (duration / 2) / 29.1; // formula to convert the time into a distance
inches = (duration / 2) / 74; // more formula
String c = ("" + inches);
String x = “Distance; " + c + “in, " + (”” + cm) + “cm”;
Serial.print("Distance “);
Serial.print(inches);
Serial.print(” in “);
Serial.print(” ");
Serial.print(cm);
Serial.println("cm ");
delay(250); // prevent the sensor from running too fast

if (inches <= 20) {
if (unturnNeed == false) {
digitalWrite(OnPin, HIGH);
digitalWrite(OffPin, LOW);
for (angle = 0; angle < 180; angle += 5) // command to move from 0 degrees to 180 degrees
{
servo.write(angle); //command to rotate the servo to the specified angle
delay(1);
}
}
unturnNeed = true;

//digitalWrite(solenoidPin, HIGH);
} else {
if (unturnNeed == true) {
digitalWrite(OnPin, LOW);
digitalWrite(OffPin, HIGH);
//digitalWrite(solenoidPin, LOW);
for (angle = 180; angle >= 1; angle -= 5) // command to move from 180 degrees to 0 degrees
{
servo.write(angle); //command to rotate the servo to the specified angle
delay(1);
}
unturnNeed = false;
}
}

}

Can you post a data sheet for the valve?

BTW, heres a circut diagram for the valve

(mod edit)
download.png

download.png

Look at SPDT (Single Pole Double Throw) relay modules to control the valve. They have the required driver transistor and flyback diode built in plus some are optically isolated.

WUT? (Sorry, I'm a small brain)

The below relay setup would probably work to control your valve. I've ordered from this vendor and received my order in the US in about 5 days.

2 Channel DC 5V Relay Switch Module for Arduino Raspberry Pi ARM AVR DSP | eBay?

@trex0225

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

The valve is designed to with 9V to 24V DC supply, I’d chose 12V over 9V for better performance and more
choice of power supplies.

The datasheet in one place says the wiring pinout is:

common: yellow
open: red
close: blue

and in another place says:

common: yellow/blue
open: red
close: green/blue

the 00011 model is self-parking, ie the the supply current drops to zero once fully open or fully closed, allowing a simple SPDT switch or relay to be used.