10 servo question with additional inputs

Bit of a newb here, so forgive me if I'm in the wrong section for this forum.

I'm building a project where I have ten blinds all with their own servo inside. The goal is to automate them via photocell readings. I'm using the Grove-Base-Shield 1.2 to connect them all. I've also tried to include a switch to override the automation, and provide a potentiometer to control the blinds.

Here is my question, individually all the pieces work fine. I run into a problem when I initialize the 10 servos. When I do, the arduino can't reliably tell the position of the switch. Sometimes it reads "1" and sometimes "0". I've tried using different digital pins for the switch, but it always becomes unreliable when the servos are initialized. If I don't initialize the servos, the switch, photocell, and potentiometer all work fine.

Also, it appears the potentiometer and photocell work fine regardless of servo initialization. Only the switch fails to give reliable readings.

How should I continue to troubleshoot this? Do I need to provide a diagram or pictures of what I have hooked up? If so, what is the best way to do this?

A diagram would really help and also posting your code would help. As it's just the switch that's the problem, how is it connected to the arduino pin (describe the wiring). Sounds like the switch is picking up noise from the servos and may need bigger pullup/pulldown resistor

Is there an easy tool to use to create the diagram?

dnewman: Is there an easy tool to use to create the diagram?

Yes, it is called a pencil. It has an infinite number of built in fonts and symbols. You apply this to something called "paper" then photograph the results and attach them to your post with the options rectangle you get when you press reply button and not use the quick reply.

The usual issue people have with servos is not supplying sufficient power. Servos need to be powered from an external power supply, like below.

servo-wire.jpg

I created a crude diagram of what I'm doing:

http://imgur.com/I99Ttaw

My concern is why when initializing the servos (with something like "myServo1.attach(servoPin1);") why the toggle switch would fail to produce accurate readings.

I'm highly skeptical of the resistors. I followed individual guides online, and have little knowledge of when/why to use resistors.

I followed individual guides online, and have little knowledge of when/why to use resistors.

I've never used resistors with servos.

The resistors are for the photocell and the toggle switch. The servos don't have resistors in-line.

Hi, if you use REPLY rather than QUICK REPLY you will find in the bottom left hand corner the provision for attaching files including images.

Makes it easier to see your image.

Thanks Tom.. :)

Your switch problem lies in the way you wired it. You need to use a pull up or pull down resistor. I noticed you have a resistor on the switch but it is not in the right place. This causes the input to float between high and low.

Here is a schematic to a pull up resistor compare it to your switch wiring.

dnewman: My concern is why when initializing the servos (with something like "myServo1.attach(servoPin1);") why the toggle switch would fail to produce accurate readings.

Yes it looks like the problem is a floating input from the toggle switch and you either need to add a 10K pull down resistor between the Arduino pin and GND where it connects to the Arduino pin and maybe reduce the 10K inline resistor value a bit or wire the switch differently so you don't need external resistors on it. To re-wire toggle switch connect one side of it to GND and the other side to the Arduino pin. In your Arduino code you need to turn on the internal pull up resistor for the pin the switch is attached to with 'pinMode(switch_pin,INPUT_PULLUP);' and adjust any code that reads and acts on the pin so the logic is reversed. The pin will read HIGH when switch is open and LOW when switch is closed.

Simple servo button code.

//zoomkat servo button test 7-30-2011
//Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
  }
  else {
    servo1.write(20);
  }
}

I tried removing the resistor, and connecting one side of the switch to GND and the other to my digital pin (11). I then adjusted my code to use the PULLUP method described, and tried the sample code provided. Now the switch doesn’t change input readings with or without the servos attached. When I had the resistor attached, it at least worked without the servos attached.

What would happen if I connected the 5V power feed to the switch, and then to the digital input? Would that fry the input reading?

Now the switch doesn't change input readings

So now you have different code you have to post it so we can see what new mistakes you have made.

What would happen if I connected the 5V power feed to the switch, and then to the digital input? Would that fry the input reading?

No but without a pull down resistor it would not work.

Please read this about input switches:- http://www.thebox.myzen.co.uk/Tutorial/Inputs.html