Mini Project


After working on HW6, I wanted to explore actuating a pendulum using feedback and magnetism. So I built a large scale pendulum as a test bed for this idea.


Wood for pendulum frame

4*AA battery holder

5V regulator – LD1117

Attiny85 microcontroller

Large magnet – (1/2” neodymium cube magnet ~25lb pull force)

Electromagnet – (homemade coil of magnet wire)

IR photogate or reflectivity sensor

Large mosfet or transistor to drive coil (Zetex ZXMN2A02)

Resistors for sensor and mosfet

(10-100uF) capacitor to handle spikes


As the pendulum swings the circuit needs to impart a force on the pendulum to keep it from slowing down. By using a large magnet as the pendulum mass, the circuit can affect the pendulum by switching an electromagnet. This has to be done very precisely, because the magnetic field from the electromagnet can increase or decrease the speed of the pendulum depending on how it’s switched. The goal is to switch the electromagnet on as the pendulum approaches and turn it before the pendulum moves halfway through the electromagnet’s field. This way the magnetic field doesn’t attract the magnet as both as the pendulum approaches and as it leaves, thus canceling out any increase in momentum.


The circuit consists of a microcontroller, mosfet, sensor and a voltage regulator. The sensor consists of an IR LED and an IR phototransistor. There are resistors to set the current through the LED and to set the gain of the phototransistor.  The microcontroller will sample the reflectivity sensor voltage with an ADC pin. When a desired threshold is crossed the microcontroller will send a pulse to the gate of the mosfet to energize the electromagnet.


To actuate the pendulum I chose a very simple and effective algorithm. Since the max speed of the pendulum can be determined experimentally, I chose to energize the coil for a fixed amount of time corresponding to the speed of the pendulum at max amplitude. This proved the be extremely robust. Experiments with dynamic timing proved less reliable and, at best, only improved the pendulum’s start up time.

This entry was posted in 07. Mini-Project. Bookmark the permalink.

2 Responses to Mini Project

  1. ahilleni says:



    #define COIL PB3
    #define IR PB4
    #define COIL_TB 900
    #define COIL_TW 045

    void init_IO();
    void init_ADC();
    int read_POS();
    void coil(int on);

    volatile int position;

    int main (void)

    //main program loop
    // _delay_ms(800);



    void init_IO()
    DDRB = (1<<PB3)|(0<<PB4); //mosfet pin as output, IR pin as input

    void init_ADC()
    ADMUX |= (0 << REFS0)|(1<<MUX1); // VCC as Reference, ADC2 PB3 mux
    ADCSRA |= (1 << ADEN); // Enable ADC

    void coil(int on)
    PORTB |= (1<<PB3);
    else if(!on)
    PORTB &= ~(1<<PB3);


    int read_POS()

    ADMUX = (0 << REFS0)|(1<<MUX1)|(0<<MUX0); // VCC as Reference
    ADCSRA |= (1 << ADSC); // Start Converstion

    while((ADCSRA & 0x40) !=0){}; //wait for conv complete

    return ADC;

  2. mgiraldo says:

    hey the capacitor worked wonders!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s