Connect with us

Halloween rat

Discussion in 'General Electronics Discussion' started by bigone5500, Oct 5, 2014.

  1. bigone5500

    bigone5500

    712
    120
    Apr 9, 2014
    Wanted to give these guys some personality. Put some 3mm green LEDs in the eyes. Loaded a modified flicker sketch and ... IT'S ALIVE! IT'S ALIVE!

    Code:
    /*
    Feel free to do whatever you want with this sketch.
    */
    
    int ledPin0 = 2;    // Define LED pins
    int ledPin1 = 3;
    
    void setup()
    {
      pinMode(ledPin0, OUTPUT);    // Define LED pins as Outputs
      pinMode(ledPin1, OUTPUT);
    }
    
    // Both LED outputs will flicker at the same time at a randomly chosen rate.
    
    void loop()
    {
      digitalWrite(ledPin0, HIGH);    // Turn on LEDs
      digitalWrite(ledPin1, HIGH);
      delay(random(100));            // Wait a random amount of time
      digitalWrite(ledPin0, LOW);    // Turn off LEDs
      digitalWrite(ledPin1, LOW);
      delay(random(100));            // Wait a random amount of time
    }
    tmp_27351-20141004_225552-1261561315.jpg

    http://blog.jaredelliott.com/halloween-decor-with-arduino/ <<<---video
     
    Last edited: Oct 5, 2014
    Ian likes this.
  2. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,214
    2,695
    Jan 21, 2010
    Let's see... 1 Uno per rat. Seems exorbitant :)
     
  3. bigone5500

    bigone5500

    712
    120
    Apr 9, 2014
    No. I Wil be using pro minis. Probably will use 1 per 2 or 3 rats. Maybe they won't chew the wires...
     
  4. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    You could always just use a PIC or AVR by itself. At $3-5 a pop, it will cut your cost at least in half ;)
     
  5. bigone5500

    bigone5500

    712
    120
    Apr 9, 2014
    I got these pro minis for about $3.50 each on ebay. I also found 2 atmega328P chips for $5.98 shipped. I just need to find out how to get the 328s on as small a pcb as possible.

    On a side note, is it possible to have the arduino play sounds?
     
    Gryd3 likes this.
  6. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    If you got em that cheap then fly at 'er.

    What kind of sound were you hoping for?
    If you're hoping for a small voice clip or recording, you may be out of luck... grab a wav file, and get your hands on a DAC to see if you can perhaps squeeze it on there.
    Keep in mind that if you manage to get a small audio clip on there, playing back smoothly will require some code magic if you want to flicker the LEDs at the same time. Those delay(random(100)) will not play nice with audio.
    Alternatively, if you wanted to make sound like the arcade games of old, or something like a gameboy or NES, you could play with outputting specific notes. (buzzes, beeps, and such)

    *This is not based on experience, but my understanding thus far on audio for an MCU.
     
  7. bigone5500

    bigone5500

    712
    120
    Apr 9, 2014
    I was thinking of something like rat squeaks or something like that.
     
  8. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    Oh hell... that may not be too hard to do.
    Off the top of my head, there would be two things I would try...
    PWM, at a varying frequencies. (Duty cycle will change the volume... you want to find a good frequency to sound like a squeak when it's run for a fraction of a second.. you may need to slow it down considerably)
    Alternatively, much like your flicker sketch, you could simply toggle a pin with a delay(amount) ... increasing the delay will decrease the frequency

    Do you plan to use a speaker or piezo element?
     
  9. bigone5500

    bigone5500

    712
    120
    Apr 9, 2014
    So is arduino capable of sawtooth waveform? I could mix that and a sine wave to make some cool effects.
     
  10. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    Not that I'm aware of.
    You have PWM to play with as a square wave. There is also an 'analoguewrite' function, but it merely uses PWM to produce your value.
     
  11. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
  12. bigone5500

    bigone5500

    712
    120
    Apr 9, 2014
    I worked on 'Count Ratula' a little more today. I soldered some low profile female headers onto a pro mini and uploaded the sketch. Works great. What's more, the pro mini fits perfectly in his belly.

    Something I want to do however, is to have battery power inside the rat. I really don't want a battery pack sitting about. Can three 3v LR44 cells power this project for a while or will they discharge too quickly?

    I also made a slight change to the sketch. I thought the LEDs were flickering too quickly so I modified the delay.

    Code:
    /*
    Feel free to do whatever you want with this sketch.
    */
    
    int ledPin0 = 2;    // Define LED pins
    int ledPin1 = 3;
    
    void setup()
    {
      pinMode(ledPin0, OUTPUT);    // Define LED pins as Outputs
      pinMode(ledPin1, OUTPUT);
    }
    
    // Both LED outputs will flicker at the same time at a randomly chosen rate.
    
    void loop()
    {
      digitalWrite(ledPin0, HIGH);    // Turn on LEDs
      digitalWrite(ledPin1, HIGH);
      delay(random(50, 200));            // Wait a random amount of time from 50 to 199 ms
      digitalWrite(ledPin0, LOW);    // Turn off LEDs
      digitalWrite(ledPin1, LOW);
      delay(random(50, 200));            // Wait a random amount of time from 50 to 199 ms
    }
     
    Last edited: Oct 8, 2014
  13. Gryd3

    Gryd3

    4,098
    875
    Jun 25, 2014
    Looked at wikipedia, they dont have much in terms of capacity. ~150mAh each.
    I'm sure you can loosely do the math to determine what kind of life you will get from these.
     
  14. bigone5500

    bigone5500

    712
    120
    Apr 9, 2014
    I wasn't sure how much capacity they had. I checked a website with a calculator and came up with 3.25 hours runtime. That's only the LEDs. Probably 2.5 hours with the pro mini. Battery pack sounds a lot better now.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-