NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » ledarray with switch function

May 27, 2011
by escartiz
escartiz's Avatar

Hi, i am trying to build a led array consisting of only 15 columns and 5 rows instead of the 24 from the led array panel project, so i will have some free pins, what i like to do is use those free pins to act as switches.

I have the following code working very accurate to real time to have my led array panel act as a counter.

int main() {
  ledarray_init();
  sei();

  uart_init();
  FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
  stdin = stdout = &uart_stream;

  sec1=0;
  sec2=0;
  min1=0;
  min2=0;
  hr1=0;

 while(1) {   
ledarray_blank();
font_display(hr1+'0', 0);
font_display(min2+'0', 3);  
font_display(min1+'0', 6);    
font_display(sec2+'0', 9);  
font_display(sec1+'0', 12);
    delay_ms(816);

 sec1++;
 if(sec1>9){ sec1=0;
    sec2++;
        }if(sec2>5){
        sec2=0;
        min1++;
           }if(min1>9){
           min1=0;
           min2++;
             }if(min2>5){
              min2=0;
              hr1++;
                 }if(hr1>9){
                  hr1=0;
                    hr2=0;}
  }
  return 0;
}

What I like to do is when ever i get a total of 30 seconds or a minute i like to power a 24v buzzer that will act as an alarm to alert every 30 seconds intervals. Also at the same intervals a 120v solenoid should be powered to open a gate. I believe i can accomplish this with the available free pins. both the alarm and the solenoid need to be powered for only a second or so every 30 sec.

for what i have been reading and watching in some of the tutorials i think i will have to use mosfets connected to the mcu free pins and the external power sources to act as switches but I still have no good clue what to do, i am learning at a slow phase and don't understand many technical definitions. if someone could give me some advice and point me in the right direction I'll appreciate it.

May 28, 2011
by Ralphxyz
Ralphxyz's Avatar

Hi escartiz, my advise is to start simple.

Start with the basic bread board setup. and add a mosfet and led then get the led to light off the mosfet this can use the same power supply.

Then do the buzzer with the 24v power supply.

Then do the solenoid.

Do all of these separately using different pins.

Then after everything is working start to combine them.

Start with lighting a led, you can use the Nerdkit motor tutorial as a guide for all of these.

Ralph

May 28, 2011
by escartiz
escartiz's Avatar

Hi Ralph thanks for your advise, I have now two pins turning leds every 30sec increments :)

these is what i wrote inside main() based on the led blink tutorial

DDRD |= (1<<PD6); DDRD |= (1<<PD7);

and inside the loop

if (sec2==3 && sec1==0) {
PORTD |= (1<<PD6);
PORTD |= (1<<PD7);
} else if (sec2==0 && sec1==0) {
PORTD |= (1<<PD6);
PORTD |= (1<<PD7);
} else {
PORTD &= ~(1<<PD6);
PORTD &= ~(1<<PD7);
}

thanks, now i have to manage the external powers with the mosfet to replace the leds for the buzzer and solenoid, I am reading again the NK guide. I just realized i had read about these before but now that i am reading it again I begin to understand it a lot more. I wasn't paying attention the first time

May 28, 2011
by escartiz
escartiz's Avatar

ok I connected the 2n7000 mosfet to the board, based on the motors and mcu tutorial

  • board's ground going to mosfet left pin "source"
  • MCU pin is going to the mosfet center pin "gate"
  • 100k resistor between "gate" and "source"
  • mosfet right pin "drain" to voltmeter black "-" input
  • voltmeter red "+" input to board's positive

everything seems to be working fine. every 30sec intervals i get about 4 volts displayed in the voltmeter, i will try now with external power instead of that from the board

looking at the 2n7000 datasheet I see a "60v max rating". Now my question is those that mean i can power the mosfet left pin "source" with up to 60v????

Sorry if these is a stupid question, I suppose I should have understood this by now from watching the tutorial and the datasheed info but I am very confused and cannot understand many technical definitions and values.

I guess my next step is to:

- power the buzzer "+" directly from the 24v power source. 
- the buzzer "-" to mosfet "drain" 
- 24v power source "-" to mosfet "source"

Please correct me if I am wrong. I am afraid of damaging my NK by making a wrong connection

May 29, 2011
by Ralphxyz
Ralphxyz's Avatar

escartiz, make sure and use a common ground for all power sources!

Can you draw out a wiring diagram?

Ralph

May 29, 2011
by escartiz
escartiz's Avatar

"Diagram pic"

May 29, 2011
by escartiz
escartiz's Avatar

thanks a lot Ralph. I tried it and its working. I was missing the common ground and it wasn't working until I saw your last reply :)

I was reading other post and I came a cross a suggestion to use a relay after the mosfet for the 110v AC solenoid? would that be correct for the next step?

Post a Reply

Please log in to post a reply.

Did you know that interrupts can be used to trigger pieces of code when events happen? Learn more...