Hi, im doing c code for my project and after done verify the done, i try to upload it to my arduino uno board. But it didn't work, My circuit have 3 input and 3 output. 3 Push button and another 3 is LED,Buzzer and Servo Motor. I try to fix the problem but i didn't manage to find it. I attached the code below. Please help me.
Hi, im doing c code for my project and after done verify the done, i try to upload it to my arduino uno board. But it didn't work, My circuit have 3 input and 3 output. 3 Push button and another 3 is LED,Buzzer and Servo Motor. I try to fix the problem but i didn't manage to find it. I attached the code below. Please help me.
Farid23:
Hi, im doing c code for my project and after done verify the done, i try to upload it to my arduino uno board. But it didn't work, My circuit have 3 input and 3 output. 3 Push button and another 3 is LED,Buzzer and Servo Motor. I try to fix the problem but i didn't manage to find it. I attached the code below. Please help me.
You need to describe what it was suppose to due and then what it actually did.
When you define the value for some of the pins,
int pos = 0;
int LED = 12; // do you actually mean 13? The reason I ask, is that The Arduino has a LED connected to pin 13;
int BUZZER = 8;
int BUTTON1 = 4;
int BUTTON2 = 7;
You might want to actually use these declared values for something. Like this:
==> Maybe this part is being 'lagged' because since it's not inside the 'if' function, it would do that everyloop. So if you pushed the button (pin 2), then it would just go back and forth 180 degrees. But if you don't give a signal to the button, then I assume it wouldn't have enough time to go to 180 degree quickly... So that 'might' be a problem
When you do add those braces, I assume that you want them around both servo movements, as suggested by junwoo0914. (I accidentally left out the second movement in the code snippet I quoted.)
You really want this, but you'll need to read a different pin for the conditional:-
(Note the formatting.)
if (digitalRead(2) == HIGH) // *** Not pin 2, it's the servo!
{
for (pos = 0; pos <= 180; pos += 1)
{
myservo.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1)
{
myservo.write(pos);
delay(15);
}
}
An extra tip. To increment and decrement 'pos', it's quicker and easier to do this:-pos++orpos--rather thanpos+=1orpos-=1