BabyO usage of micro-switch

I am using a single-pole double-throw (SPDT) switch with BabyO and I am unbale to get it to work. For testing, I am just trying to the red led on and off.

The code…

#include <pololu/orangutan.h>
int main() {

    DDRD |= 1 << PD1;  // set LED pin PD1 to output

    //Micro-Switch PC1
    DDRC &= ~(1<< PC1);      //set as input
    PORTC |= (1<< PC1);      //enable pull up resistor

    while(1) {
        if (PINC & (1 << PC1)) {    // switch is open 
            PORTD &= ~( 1 << PD1 ); // LED off
        } else {
                                            // switch is closed
           PORTD |= 1 << PD1;     // LED on

The red led never lights…

I have the Common wired to the signal.
I have NO wired to ground
I have left NC floating.
The pull up resistor should enable the circut to see the voltage
Closing the switch should change voltage to zero.


It would be helpful to see a picture of your setup, but there are a few quick tests you can do to try to debug things. For example, try removing the switch from the system completely and just touch a wire from pin PC1 to ground. Does the red LED light while you have it grounded and turn off when you remove the ground connection?

If it passes this first test, the next thing to check is your switch. Connect it to your Orangutan as you described, and use a multimeter look at the voltage on the output when the switch is open and closed. Is it high when open and low when closed?

- Ben

Bypass the switch and grounding signal does not light red LED.

Swich seems to work fine.

Reading across NO and C while open is 330 mV.

Reading across NO and C while closed is 0 mV.

It’s got to be an error in my code…well…not really…it turned out to be a bad soder job.

I tested your code on a Baby Orangutan here and it worked just fine. When I grounded PC1, the red LED turned on, and when I removed the ground connection, it turned off. Are you sure you’re making your connection to PC1? Can you put code on there to blink the LED to make sure you didn’t damage something when you initially connected the switch wrong?

- Ben

Yes…the BlinkLED program still works…after my wiring issue…

After you said the program works on your end, I resodered the PC1-2-3 connections and corrected the problem. I spent to much time trying to figure out the code and didn’t check the most obivious (my sodering skills) issue. What a way to waste a few days.

I’m glad to hear you have things back on track now.

- Ben