I simply got my motors to work separately with two different sensors, but with one program.
The solenoid has a digital input from a photo sensor. The solenoid turns on and off depending on if it is dark or light.
The servo has a analog input from a potentiometer. The servo turns in ratio to the potentiometer.
here’s the code:
int servoPin = 3; // connect servo to pin 3
int sensorPin = 2; // connect potentiometer to pin 2
int solePin = 12; // connect solenoid to pin 12
int photoPin = 4; // connect photosensor to pin4
void setup ()
{
beginSerial (9600); //
pinMode (servoPin, OUTPUT); // set servo as analog output
pinMode (sensorPin, INPUT); // set potentiometer as analog input
pinMode (solePin, OUTPUT); // set solenoid as digital output
pinMode (photoPin, INPUT); // set photosensor as digital input
}
void loop ()
{
int val = analogRead(sensorPin) / 11; // set "val" equal to the analog read of the sensor divided by 11
Serial.println(val); // print the value of "val" on the serial monitor
analogWrite(servoPin, val); // as the value of the sensor changes, the servo should spin according to "val"
if (digitalRead(photoPin == HIGH)) // if digital read of photosensor is bright
{ digitalWrite(solePin, HIGH);} // then turn solenoid on
else // otherwise
{ digitalWrite(solePin, LOW);} // turn solenoid off
}