Please read the post at the start of any forum , entitled "How to use this Forum".
OR http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Well, attached you will find my connection to Arduino UNO.
Here is my code :
#include<Servo.h>
int pos =0 ;
int pin3 = 3;
int LedHi = 5;
int LedLow = 6;
Servo servo1;
void setup() {
pinMode(LedHi, OUTPUT);
pinMode(LedLow, OUTPUT);
pinMode(pin3, INPUT);
servo1.attach(9);
}
void loop() {
if (digitalRead(pin3) == HIGH) {
servo1.write(180);
digitalWrite(LedHi,HIGH);
digitalWrite(LedLow, LOW);
}
else
servo1.write(0);
digitalWrite(LedHi,LOW);
digitalWrite(LedLow, HIGH);
delay(15);
}
Here is what I'm trying to achieve :
While servo motor is moving to "180" position (button HIGH), I want the LedHi to ON, while LedLow to be off.
The opposite when I release the button - (LedHi Off - LedLow On) while servo goes back to "0" position.
Problems with the above code and connections.
The 2nd LED (LedLow) is always "ON" whether the button is HIGH or not.
It just like ignoring the 2nd digitalWrite at " if " state.
The 1st LED (LedHi) seems to work fine while the button is held - but it has too low "power" (and I'm using it without any resistor)
I hope that is more clear to anyone that reading this.
First thing I see is that while your if statement has braces around the statements that follow it, your else does not. That's the reason for your first problem.