Help with writing first Arduino program

Thread Starter

navyguy

Joined Sep 27, 2019
48
Hi all.

First time using my Arduino uno. Trying to learn how to program Arduino to control 2 servos.
I could use some help with the set up instructions.
I tried to copy a program off the internet but it wasn’t accepted as valid.

Any help greatly appreciated.

Thanks
 

dl324

Joined Mar 30, 2015
8,847
Post the code and any errors you're getting. Are you using the latest version of the IDE?
 

Thread Starter

navyguy

Joined Sep 27, 2019
48
Hi thanks.
It says “servo was not declared in this scope.”

Not sure if I have the latest IDE. I’ll check
 

Thread Starter

navyguy

Joined Sep 27, 2019
48
Just uploaded the program you gave me.
Showing “redefinition of void set up ()’”
 

Thread Starter

navyguy

Joined Sep 27, 2019
48
ok looks like that worked but now it says I need to select a serial port. That part is grayed out under tools.
 

btebo

Joined Jul 7, 2017
89
ok looks like that worked but now it says I need to select a serial port. That part is grayed out under tools.
Someone else is going to have to help with that - I've never messed with servos and arduino together....
 

Thread Starter

navyguy

Joined Sep 27, 2019
48
One last question:
The servo slowly rotates in one direction then very quickly rotates in the opposite direction.
How can I get it to rotate both directions at the same speed?

Thanks again
 

btebo

Joined Jul 7, 2017
89
One last question:
The servo slowly rotates in one direction then very quickly rotates in the opposite direction.
How can I get it to rotate both directions at the same speed?

Thanks again
Again - I've never played with them. But looking at the code from the Adafruit website- the program called "Sweep"

In the Loop, you see sections where it is changing the angle. Notice after each Servo.write command, there is a command delay(15)

Make sure that the same delay value is used when then angle is increasing (angle++) and decreasing (angle--).

What's happening is, the program increases the angle by 1 degree and delays for 15mS. It repeats until it hits 180 degrees.

Then the program decreases the angle by 1 degree and delays for 15mS. It repeats until it hits 0 degrees.

Not sure what else to recommend.
 

Thread Starter

navyguy

Joined Sep 27, 2019
48
Again - I've never played with them. But looking at the code from the Adafruit website- the program called "Sweep"

In the Loop, you see sections where it is changing the angle. Notice after each Servo.write command, there is a command delay(15)

Make sure that the same delay value is used when then angle is increasing (angle++) and decreasing (angle--).

What's happening is, the program increases the angle by 1 degree and delays for 15mS. It repeats until it hits 180 degrees.

Then the program decreases the angle by 1 degree and delays for 15mS. It repeats until it hits 0 degrees.

Not sure what else to recommend.
Ok thanks. Yes I did check the information of the sweep program and it’s working fine.
 

Thread Starter

navyguy

Joined Sep 27, 2019
48
One thing I’m hoping to do is install a servo or motor in a skeleton to make his jaw move up and down very rapidly like he’s talking. Is that possible with the Arduino?

Thanks again
 

dendad

Joined Feb 20, 2016
2,977
I like the "ASKmanual.pdf" as a good introduction. That seems to be freely available as a download.
Also, a very good series of courses are available from https://randomnerdtutorials.com/ and they cover Arduinos, ESP8266 and ESP32 boards. Each week or so, a further project is published. Well worth the cost.
 

djsfantasi

Joined Apr 11, 2010
5,570
One thing I’m hoping to do is install a servo or motor in a skeleton to make his jaw move up and down very rapidly like he’s talking. Is that possible with the Arduino?

Thanks again
Yes, it’s definitely doable. You need to know the position over time... or simply, determine by experiment how fast you want the mouth to use. And, what the servo positions are...

Let’s say the variable servoMouthClosed is one position. servoMouthOpen is the other.

You’d write a loop to
  1. close the mouth,
  2. delay a bit (determine how much a “bit” is by experimentation),
  3. then open the mouth.
Repeat as often as you want...
 
Top