Have servo move randomly without an IC

Thread Starter

siliconchris

Joined Nov 27, 2017
1
Hi,

I have a servo (Longrunner MicroServo 99 - Typ KY66) that I want to use to move a gun turret of my Millenium Falcon model. To make the movement look more realistic, I thought about having the servo and thus the gun turret move randomly left and right and also turn round instead of simply rotating it.

Now, I know how I would solve that with an Arduino, but I do not want to use such a heavy component. So my question is this:

How can I make a servo move randomly (or erratically)without a microcontroller?

Thanks for any suggestion,

Christian
 

Sensacell

Joined Jun 19, 2012
2,998
Without an MCU it's going to be really hard, and most probably larger and heavier than a micro based idea...

I would program a bare chip, not an entire Arduino - if you need to keep it really small, you need only the chip and a bypass capacitor to do this job.
Use an 8 or 16 pin chip in SMD and it's going to be really small.
The code I would write would have a pseudo-random bit sequence generator drive another piece of code that created the servo control signal.
Oh, and a timer to set the update rate.

https://en.wikipedia.org/wiki/Linear-feedback_shift_register
 

ericgibbs

Joined Jan 29, 2010
15,524
hi s,
Have you considered a light weight mechanical solution, the existing servo driving a Cam and Spigot assembly between the servo and turret?
E
 

Ya’akov

Joined Jan 27, 2019
5,660
An ATTINY could be programmed with the Arduino IDE and a programmer. It’s an 8 pin chip that could do everything you want. The Arduino servo library makes the programming simple.
The ATTiny 13A would be a great solution. In another thread, I tested the feasibility and was able to do this with the chip, a bypass cap, and the servo. I tested the Tiny itself operating reliably down to less than 2V(!) so power sufficient for the servo is all that is really needed.
servo.png
sorry about the crappy gif, I can't upload video here

You will need a programmer (I am using a USBTiny clone from Amazon in the photo. <$10) and very helpful but not required is a development board like the one the ATTiny is in. Key to note is that the red circle is the only component you will need (aside from a couple of passives and the servo) and you can easily tweak the results as many times as you'd like just by editing code.

For an electronic solution you will not get a smaller, simpler, more accessible, and more flexible solution. @ericgibbs suggestion of a mechanical solution is worth considering but of course it will be far more difficult to change it.
 
Last edited:

Ya’akov

Joined Jan 27, 2019
5,660
or just use DigiSpark (or clone). already has firmware and USB interface so no need for external programmer. it is tiny. used to be $2 or so. now it is probably 3x that.

this is original
View attachment 265100
and this is clone
View attachment 265102

either of them will do it nicely. it is my goto trinket for compact solutions when i'm not willing to make custom board.
The one caveat with the DigiSpark is the bootloader. Because of the low pin count, the bootloader controls the MCU for 5 seconds after power up so the programmer and find and flash it. So, unless you load alternative firmware and preserve the RESET pin, there will be a delay.

Sometimes this doesn't matter at all, but sometimes the method of starting the program is powering the MCU so it might.

Otherwise, the ATTIny85 is a good choice. Since it is the same size as the 13A and more capable, it is better even in my version. It's effectively the same thing but more resources and more thoroughly supported.

Other pins could do other things too, like operate LEDs as lighting, or... something.
 

Ian0

Joined Aug 7, 2020
5,131
Assuming that it's the sort of pulse-width controlled servo, then it's easily done in logic.
Pseudo-random number generator made from a shift register.
Various outputs connected through resistors to a 555 to generate a pulse-width that depends on the logic outputs.
If you post the spec for the pulse-width and repetition rate that controls the servo, I'll draw a circuit diagram.
 

MisterBill2

Joined Jan 23, 2018
11,880
To generate a sort of random position setpoint signal without a processor or software, you could use resistors from different stages of a binary counter to a summing point and use that as the analog position command for the position input. Something like a CD 4040 or even a CD4060, that has a built in oscillator. perhaps a count rate of 1 hZ for changing positions.
 

click_here

Joined Sep 22, 2020
541
I'd be thinking about using a PIC (or whatever you are used to program in...), using the c language 'stdlib.h' function 'rand()'.

For the seed of the random number 'srand()' have a start button, which when pressed gets the value of a timer (say, timer 1).

You would then want a smooth movement, so you would want to do something like: if rand() is larger than a value, increment duty cycle, otherwise decrement duty cycle; rather than just using a random number as the duty cycle.
 

MisterBill2

Joined Jan 23, 2018
11,880
OK, now that others who have investigated seem to know, what you have is an "RC servo", which represents a small part of the realm of things called "servos". My error for not realizing the dialect, sorry about that. The position control signal is thus a PWM string with a well defined frequency. A randomly changing PWM signal is more complex by far.
 

click_here

Joined Sep 22, 2020
541
Here is a 5 minute C program, hacked together on my phone... It could probably be cleaned up a lot, but it should give you one way you could write a program

It wouldn't take very long to tweek it to run on any microcontroller...

Code:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

// non portable code, just for this demo...
#include <conio.h>
#include <unistd.h>

/// Returns 0 if no input is found
int NoInput(void)
{
    // You would look for an I/O 
    // input here for a pushbutton
    
    // My version of linux has 'conio.h',
    // so I'll use kbhit() for this demo...
    return !kbhit();
}

void Debounce(void)
{
    // Wait for bouncing of button
    // to stop
    
    // but for this example I'll
    // use this spot to clear stdin...
    getchar();
}

void Delay(void)
{
    // Whatever delay you like on 
    // your device...
    
    // This is for a Linux environment...
    usleep(5000);
}

void SetDutycycle(int newDutycycle, int maxDutycycle)
{
    // This is where you change your PWM dutycycle
    // on the device you are using...
    
    // Just as a quick way of showing the change in location...
    int position = newDutycycle * 32 / maxDutycycle; 
    putchar('<');
    for(int i=0; i<32; i++)
    {
        printf("%c", (i == position) ? '*': ' ');
    }   
    puts(">");
}

int main(void) 
{
    unsigned int count;
    
    while(NoInput())
    {
        count = (count == UINT_MAX) ? 0 : count + 1;       
    }
    
    Debounce();
    
    // Setup random number generator...
    srand(count);
    
    const int maxDutyCycle = 100; // Set this for your system 
    
    // Starting point...
    int dutycycle = count % maxDutyCycle;
    
    while(NoInput())
    {   
        // if odd...
        if(rand() & 1)
        {
            if(dutycycle < maxDutyCycle)
            {
                dutycycle++;
            }
        }
        else
        {
            if(dutycycle > 0)
            {
                dutycycle--;
            }
        }
        
        SetDutycycle(dutycycle, maxDutyCycle);
        
        Delay();
    }
    
    return 0;  
}
 

MisterBill2

Joined Jan 23, 2018
11,880
We do know what the TS has asked for :
"Now, I know how I would solve that with an Arduino, but I do not want to use such a heavy component. So my question is this:
How can I make a servo move randomly (or erratically)without a microcontroller?"
And almost all have suggested variations of a processor. Probably the most reasonable suggestion is one that I concurr with, which is a gear train driving a cam arrangement. An RC servo, unfortunately, has an input requirement that takes a relatively complex circuit to produce. And if not a complex circuit, then a program running on a processor that requires a fair amount of supporting hardware.

AND, I am going to suggest that for this website there should be a request to identify RC-Servos be identified as such, to avoid their confusion with actual standard arrangement servo systems. AN "RC-Servo" is a very specialized device very much different from all other kinds of servo systems.
 

MaxHeadRoom

Joined Jul 18, 2013
25,211
AND, I am going to suggest that for this website there should be a request to identify RC-Servos be identified as such, to avoid their confusion with actual standard arrangement servo systems. AN "RC-Servo" is a very specialized device very much different from all other kinds of servo systems.
I have commented frequently on this also.
For those used to working in mechatronics-CNC etc, I automatically think of motion control applications rather than RC.
 

Sensacell

Joined Jun 19, 2012
2,998
AND, I am going to suggest that for this website there should be a request to identify RC-Servos be identified as such, to avoid their confusion with actual standard arrangement servo systems. AN "RC-Servo" is a very specialized device very much different from all other kinds of servo systems.

Never happen. If people looking for help knew this, they would not need help!
 

Ya’akov

Joined Jan 27, 2019
5,660
We do know what the TS has asked for :
"Now, I know how I would solve that with an Arduino, but I do not want to use such a heavy component. So my question is this:
How can I make a servo move randomly (or erratically)without a microcontroller?"
And almost all have suggested variations of a processor.
The TS seemed to be under the impression that "an Arduino" meant a development board, and on that basis asked how to do something without an MCU. Since he was wrong about how "heavy" an Arduino compatible solution is, his additional specification was suspect.

The ATTiny (13A, 85) is a one chip, two passive solution. do you have a "lighter" solution? I doubt it. Would your non-MCU solution offer the flexibility of the MCU? No, of course not.

MCUs are not the answer to everything, but they are the answer to many things, and this is one that certainly benefits from such a solution based on simplicity, cost (accounting for both BoM and time), size, and flexibility. It is the right solution.

So unless the TS has some additional constraint that precludes it, even "I prefer not to use an MCU", it is not the MCU that is out of place in an answer, it's avoiding one.

[EDIT: specified "cost" to avoid confusion]
 
Last edited:

djsfantasi

Joined Apr 11, 2010
8,324
OK, now that others who have investigated seem to know, what you have is an "RC servo", which represents a small part of the realm of things called "servos". My error for not realizing the dialect, sorry about that. The position control signal is thus a PWM string with a well defined frequency. A randomly changing PWM signal is more complex by far.
It is my observation that when a hobbyist says servo, they are referring to an RC servo. Often, there are additional indications that this is the case in their question.

Rather than being pedantic, I specify RC servo )replacing servo) in my answer, somewhere noting there is a difference.

We have to be careful when responding to reply in an educational manner instead of a critical manner.
 

BobTPH

Joined Jun 5, 2013
4,906
The ATTiny (13A, 85) is a one chip, two passive solution. do you have a "lighter" solution? I doubt it. Would your non-MCU solution offer the flexibility of the MCU? No, of course not.
[EDIT: specified "cost" to avoid confusion]
Well, a small PIC requires only 1 passive, so yes, I can.

Bob
 
Top