Help with writing first Arduino program

Thread Starter

navyguy

Joined Sep 27, 2019
108
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
 

Thread Starter

navyguy

Joined Sep 27, 2019
108
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
108
ok looks like that worked but now it says I need to select a serial port. That part is grayed out under tools.
 

Thread Starter

navyguy

Joined Sep 27, 2019
108
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
100
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
108
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
108
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
4,451
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
9,156
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