Results 1 to 1 of 1

Thread: Dimension Engineering Pico and Battleswitch code

  1. #1
    Join Date
    Feb 2009
    Location
    Mesa, AZ
    Posts
    351
    Images
    84
    Rep Power
    50

    Dimension Engineering Pico and Battleswitch code

    After literally scouring the internet for examples on how to use the D.E. Picoswitch and Battleswitch, I could never get them to work!!! I just chalked it up to both units being DOA, par for the course... So I migrated to the DF Robots Single relay which works great! Just send it a Hi or Lo from your mcu, no problem.
    So I came home today bored, and thought about those useless pwm relays sitting in the junk box. Reading the product description, it hit me! These are intended to be controlled from R/C transmitters and are used much like servos. Only problem now, what is the correct pulse width to turn these things off and on??? So, with a lil experiment using my SB Freeduino, a 10K pot, and my wrongly maligned picoswitch, I extracted the correct on/off values by slowly turning the pot and watching the terminal window. 1400 microsecond max for off, and 1580 microsec minimum to turn on. Further experimentation revealed 2200 microseconds is around the max and yields the best performance for switching a motor on. Enjoy, and I hope this can help someone else.

    This first one is a modified sketch to print the values from a potentiometer, but instead of moving a servo, we'll turn on a relay!

    Code:
    // Controlling a servo position using a potentiometer (variable resistor) 
    // by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> 
    // modified by 'MannyR7' Ramirez
    #include <Servo.h> 
     
    Servo myservo;  // create servo object to control a servo 
     
    int potpin = 0;  // analog pin used to connect the potentiometer
    int val;    // variable to read the value from the analog pin 
    int pulse;  // variable to show pulse width 
    
    void setup() 
    { 
      Serial.begin(9600);  // begins serial communication with the computer
      myservo.attach(12);  // attaches the servo on pin 12 to the servo object 
    } 
    
    void loop() 
    { 
      val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
      val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
      pulse = map(val, 0, 179, 750, 2250); // get a pulse width for current pot position
      myservo.write(val);                  // sets the servo position according to the scaled value 
      Serial.print("degrees   ");
      Serial.print(val);
      Serial.print("   pulse"   );  
      Serial.println(pulse);
      delay(15);                           // waits for the servo to get there 
    }
    This next one is a simple program to demonstrate the functionality.

    Code:
    // Dimension Engineering Picoswitch Demo
    // by 'MannyR7' Ramirez
    // https://sites.google.com/site/mannysrobotpage/
    #include <Servo.h>
    Servo picoswitch;
    int gunTime = 4; // number of seconds to leave trigger on
    
    void setup()
    {
      picoswitch.attach(12);
      Serial.begin(9600);
    }
    
    void loop()
    {
      picoswitch.write(1400);  
      Serial.print("Cease Fire!\n");
      delay(1000);                  // waits for a second
      picoswitch.write(2200);  
      Serial.print("Fire!\n");
      for (int i=1; i <= gunTime; i++)
      {
        delay(1000);                // waits for a second
        Serial.print(i);
        Serial.print("\n"); 
      }     
    }
    Last edited by mannyr7; 03-23-2010 at 09:53 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •