Code not working? Error?

Hi all, I wrote code to take input from a flip switch and output signal to turn a Servo. I want to say if the switch is true (on), turn servo 180 degrees (which will turn my blinds), otherwise (else) don’t move at all. I get a weird runtime error.

error:

Arduino: 1.6.0 (Mac OS X), Board: “Arduino Uno”

BlindsControlCode.ino: In function ‘void setup()’:
BlindsControlCode.ino:8:26: error: cannot convert ‘Servo’ to ‘uint8_t {aka unsigned char}’ for argument ‘1’ to ‘void pinMode(uint8_t, uint8_t)’
BlindsControlCode.ino: In function ‘void loop()’:
BlindsControlCode.ino:18:5: error: ‘myServo’ was not declared in this scope
Error compiling.

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

CODE:

#include <Servo.h> 

Servo myservo;
boolean blindSwitch;

void setup() {
  pinMode(blindSwitch, INPUT);
  pinMode(myservo, OUTPUT);
} 

void loop() {
  myservo.attach(9);
  
  if (blindSwitch == HIGH) {
    myservo.write(170); 
  }
  else {
    myServo.write(0);
  }  

}

The variable myservo is a servo object NOT an output pin. You need to replace the word myservo with it's pin number in the pinMode function call.

BTW your myservo.attach function call belongs within setup NOT the loop function.

ALSO you might think of changing: if (blindSwitch == HIGH) with if ( digitalRead(blindSwitch) == HIGH)

I changed my code and got a new error.

Arduino: 1.6.0 (Mac OS X), Board: “Arduino Uno”

BlindsControlCode.ino: In function ‘void loop()’:
BlindsControlCode.ino:22:5: error: ‘myServo’ was not declared in this scope
Error compiling.

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

#include <Servo.h>

int myservoPin = 9;
int switchPin = 8;
int switchpinState;
Servo myservo;

void setup() {
  pinMode(switchPin, INPUT);
  pinMode(myservoPin, OUTPUT);
  myservo.attach(myservoPin);
} 

void loop() {
  switchpinState = digitalRead(switchPin);
  
  
  if (switchpinState == HIGH) {
    myservo.write(10); 
  }
  else {
    myServo.write(0);
  }  

}

Check your spelling is it an UPPERCASE S or lower case s?

I'm not sure what you mean? If the servo object is myservo and you call the method attach (attaching it to a pin) and you do myservo.attach(myservoPin); where myservoPin is equal to 9, the pin the servo will be attached to pin 9?

ilovearduinosomuch: I'm not sure what you mean? If the servo object is myservo and you call the method attach (attaching it to a pin) and you do myservo.attach(myservoPin); where myservoPin is equal to 9, the pin the servo will be attached to pin 9?

Sorry my previous reply was wrong. I've updated it. Please refresh your page.

To try and debug my code I am trying to print the value of the switch and in serial console there is nothing being printed?

#include <Servo.h>

int myservoPin = 9;
int switchPin = 8;
int switchpinState;
Servo myservo;

void setup() {
  pinMode(switchPin, INPUT);
  pinMode(myservoPin, OUTPUT);
  myservo.attach(myservoPin);
} 

void loop() {
  switchpinState = digitalRead(switchPin);
  
  
  if (switchpinState == HIGH) {
    myservo.write(10); 
  }
  else {
    myservo.write(0);
  }  
    Serial.println(switchpinState);  
}

Try putting something like Serial.begin(57600); in your setup function and make sure you use the same baud rate in the Serial monitor.