Show Posts
Pages: [1]
1  Using Arduino / Motors, Mechanics, and Power / Re: Detach Servo When Not In Use on: December 19, 2012, 08:05:41 pm
yes, i believe I have a digital servo. With that in mind, is there anyway to switch the power supply on or off with the arduino?
2  Using Arduino / Motors, Mechanics, and Power / Re: Detach Servo When Not In Use on: December 19, 2012, 07:26:27 pm
Well, with the Arduino, when the external power supply is hooked up, even if the Arduino is not powered on, the servo maintains position, and will not move if i try and do so with my hand (without power supply, servo is easily moveable with my hand).

yes battery life, and the fact the the door lock (connected to the servo via some hardware) needs the be able to move (i.e. move the servo)

L
3  Using Arduino / Motors, Mechanics, and Power / Detach Servo When Not In Use on: December 19, 2012, 06:36:08 pm
I have built a door lock actuator with an arduino, ethernet shield and and high torque servo.

The servo, as it draws ~ 7.2v is powered via a secondary battery pack (5*1.5v). As I would still like the door to be able to be opened with a key, and the servo will be connected to the lock, I am wondering is there an easy way to sever the power supply while the servo is not receiving a command? I assume I would need an extra switch of some sort, but I am not sure.

Attached is code, let me know if you need anymore information or if I missed anything.

L

Code:

#include <SPI.h>         // for Arduino later than ver 0018
#include <EthernetUdp.h>   // UDP library from bjoern@cs.stanford.edu
#include <Ethernet.h>
#include <Servo.h>

         
                         // source:  http://code.google.com/p/arduino/source/browse/trunk/libraries/?r=1094#libraries%2FEthernet


//////////  NETWORK INFO  ////////////////

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};  //Set your Ethernet Shield's MAC address here - make sure you replace the ZZs with your shield's values!
byte ip[] = { 192,168,1,103 };    // Set your shield's desired IP address here - check your network for configuration details
byte gateway[] = { 192,168,1,1 };   //if you need to set a gateway IP
byte subnet[] = { 255,255,255,0 };    // Change this to your subnet address
 
unsigned int localPort = 7777;      // local port to listen on (set this the same as Port # on Ardumote Params Screen)


IPAddress iPhoneIP(192, 168, 1, 110);  //Set the iPhone/iPod/iPad's IP address to send messages back to Ardumote...
unsigned int iPhonePort = 7777;      //Set the Port # of the message table you configured in Ardumote (default is 7777)...


///////////////////////////////////////////

Servo lockservo;
///////// Pin Assignments /////////////////

int redled = 7;
int greenled = 6;  //Set LED_Pin to Pin 6 - Place an LED on Pin 6 of your ethernet shield for testing this code
int servo2 = 45;
int servo3 = 120;


///////////////////////////////////////////



///////////////// UDP Variables  //////////////////

// the next two variables are set when a packet is received
//byte remoteIp[4];          // holds received packet's originating IP
//unsigned int  remotePort;   // holds received packet's originating port

// buffers for receiving and sending data
char packBuff[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,

/////////////////////////////////////////////////


EthernetUDP Udp;


void setup() {
 
  // More info on Ethernet on Arduino's website:  http://arduino.cc/en/Reference/EthernetBegin
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);   // If you don't need to set your default gateway or subnet manually, use this
//  Ethernet.begin(mac,ip,gateway,subnet);  // Use this line instead if you've manually set all the parameters
 
 
  Udp.begin(localPort);    //Setup UDP socket on port defined earlier

  Serial.begin(9600);    //Start Serial Communications with PC
   Serial.write("SYSTEM BOOT");   
  pinMode(redled,OUTPUT);
  pinMode(greenled,OUTPUT);    //Designate pin 6 as Output Pin
  lockservo.attach(5);
   lockservo.write(servo2);   
digitalWrite(greenled,HIGH);    //Turn off LED_Pin
}

void loop()
{

 
 
  int pwmVal;    // Integer that will hold our PWM values for later use
 
 
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket(); // note that this includes the UDP header
  if(packetSize)
  {
    packetSize = packetSize - 8;      // subtract the 8 byte header
    Serial.print("Packet size: ");
    Serial.println(packetSize);

    // read the packet into packetBuffer and get the senders IP addr and port number
    Udp.read(packBuff,UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Message: ");
    Serial.println(packBuff);

 

 
 /* PWM - If we move a slider on Ardumote, it sends in a 3 digit value attached to the message of the slider.
 
     For example, if your message is set to be "PWM" and your slider is halfway set (slider value is 127),
     then your actual sent message will be received as "PWM127".  Therefore, to set the Pin's PWM value, you simply
     extract the last 3 digits of your message and use that as your PWM value (see below):
     
  */
   
    // Assuming our packBuff's contents at index values 3-5 are our PWM values, you can convert them to an int using this:
 
     pwmVal = (packBuff[3] - '0')*100 + (packBuff[4] - '0')*10 + (packBuff[5] - '0');    //Get PWMXXX message, and use XXX to set an int between 0 and 255.
 
 //////////////////////// Pin 6 (LED_Pin) /////////////////////////////////////       
       
   

    if (packBuff[0] = 'P' && packBuff[1]=='6' && packBuff[2]=='H')  // If we get the message "P6H", then set LED_Pin (6) HIGH
    {
      digitalWrite(greenled,LOW);    //Turn on LED_Pin
          lockservo.write(servo3);
       delay(1000);
      digitalWrite(redled,HIGH);    //Turn on LED_Pin
 
      Serial.println("Door is Locked");    //Write notification
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Door is Locked");    // Send Message back to iPhone
      Udp.endPacket();
 
 

    }
   
     
   
    else if (packBuff[0] = 'P' && packBuff[1]=='6' && packBuff[2]=='L')  // If we get the message "P6L", then set LED_Pin (6) LOW
    {
      digitalWrite(redled,LOW);    //Turn on LED_Pin
       lockservo.write(servo2);
       delay(1000);
      digitalWrite(greenled,HIGH);    //Turn off LED_Pin
 
      Serial.println("Door is Open");    //Write notification
      lockservo.write(servo2);
      Udp.beginPacket(iPhoneIP, iPhonePort);
      Udp.write("Door is Open");    // Send Message back to iPhone
      Udp.endPacket();
     
    }   
   
   
  }
 
  delay(20);
}
4  Using Arduino / Networking, Protocols, and Devices / Re: Arduino WiFi Shield UDP Support on: December 04, 2012, 05:20:41 pm
Hello all,

I too have bought a wifi shield and would like to communicate with my arduino via ardumote or similiar for a door unlocker project. I would love to help move this along, but am quite the newbie and dont have the skills to start reprogramming.

kdecker, I would love to see you code if you would be so inclined, i might be able to get that up and running to tide me over untill UDP support is all figured out.

L
5  Using Arduino / Programming Questions / Re: Problems trying to control Arduino with iPhone and Official Wifi Shield on: November 24, 2012, 04:47:05 am
anybody else? or if someone could direct me in the right direction for more reading etc? Im new to this and greatly appreciate some guidance!

thanks,

L
6  Using Arduino / Programming Questions / Re: Problems trying to control Arduino with iPhone and Official Wifi Shield on: November 22, 2012, 07:20:25 pm
Nothing on those two currently, that will be the future servo. It was in the code from when i originally grabbed it, i just left it because i didn't think it would make a difference in the time being and then would be easier once i added in the servo.
7  Using Arduino / Programming Questions / Problems trying to control Arduino with iPhone and Official Wifi Shield on: November 22, 2012, 06:52:33 pm
Hello All,

My first post here and my first Arduino, so still learning tons and may have overlooked some obvious things that will make this work. I also understand from reading / research etc. that there are still some potential issues with the official wifi shield. Anyways, here is what I am trying to do. Currently just trying to control a few LEDs wired to my Arduino with my iPhone, but ultimately would like to add a servo in to open a door lock. I'm not a complete newbie when it comes to writing code, but am not very familiar with C++. Ive read and googled and searched the forum for as much info as I could find on using the iPhone with an Arduino and wifi shield, but aside from lots of information on using it with a router and an ethernet shield, I have not found much. I tried to adapt my code from the "ardumote" app tutorial, and a another post i read on the subject. Everything compiles fine, and works well with serial control from my computer, but nothing at all from my iPhone. Code / info follows:

I am using an Arduino uno rev3 with an official (Arduino) wifi shield.
I have three 5mm LEDs connected through 300 ohm resistors on pins 5, 6 and 7.

Code:
byte mac[] = { 0x7A, 0xC4, 0x0E, 0x1C, 0xAA, 0xF3 };
byte ip[] = { 192, 168, 1, 140 };
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <SoftwareSerial.h>
#include <Servo.h>

char ssid[] = "Leah Wifi";     //  your network SSID (name)
char pass[] = "le725ahbak";    // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

 
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos = 0;    // variable to store the servo position

SoftwareSerial mySerial(2, 3); // using soft serial to monitor what the arduino is doing. The hardware serial is busy talking to the RN-XV

void setup() 
{
  pinMode(5, OUTPUT); // LED5
  pinMode(6, OUTPUT); // LED6
  pinMode(7, OUTPUT); // LED7
 
 
  Serial.begin(9600);  // used to communicate with the RN-XV module.
  mySerial.begin(9600); // start up the second serial port used to sending messages to Arduino Serial Monitor.
  mySerial.println("Hello, world?"); // check to see if it's working
  myservo.write(pos);
 
   // attempt to connect using WPA2 encryption:
  Serial.println("Attempting to connect to WPA network...");
  status = WiFi.begin(ssid, pass);

  // if you're not connected, stop here:
  if ( status != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    while(true);
  }
  // if you are connected, print out info about the connection:
  else {
    Serial.println("Connected to network");
   


  }
}



void loop() // run over and over
{
  while (Serial.available()) 
 {
    char ch = Serial.read();     //hoping this will transfer the characters from UDP coming in on serial port into ch?
 
    // the meat and potatoes portion of the sketch... this errors out but I want to get the idea of what I want to do down...
 
    if (ch == 'A') //Check to see if the message is "A" if it is set LED7. HIGH
      {
        digitalWrite(7,HIGH);
        mySerial.println(ch); //send the message to mySerial so I can check it.
        Serial.println("LED7 on");  // send this message back via UDP back to my iphone to confirm it happened.
      }
     
      else if (ch == 'B') //check to see if the message is "B" if it is set LED7 LOW
        {
          digitalWrite(7,LOW);
          mySerial.println(ch); //send the message to mySerial so I can check it.
          Serial.println("LED7 Off");  // send this message back via UDP back to my iphone to confirm it happened.
        }
   
      else if (ch == 'C') //check to see if the message is "C" if it is set LED6 HIGH
        {
          digitalWrite(6,HIGH);
          mySerial.println(ch); //send the message to mySerial so I can check it.
          Serial.println("LED6 On");  // send this message back via UDP back to my iphone to confirm it happened.
        }
 
      else if (ch == 'D') // check to see if the message is "D" if it is set LED6 LOW
        {
          digitalWrite(6,LOW);
          mySerial.println(ch);
          Serial.println("LED6 Off");  // send this message back via UDP back to my iphone to confirm it happened.
        }
      else if (ch == 'E') // check to see if the message is "E" if it is set LED5 High for a few seconds then LOW again.
        {
          digitalWrite(5,HIGH);
          delay(1000);           
          digitalWrite(5,LOW);
          mySerial.println(ch); //send the message to mySerial so I can check it.
          Serial.println("LED5 Pulsed"); // send this message back via UDP back to my iphone to confirm it happened.
        }
       
        else if (ch == 'G') // check to see if the message is "G" if it is set LED5 HIGH.
        {
          digitalWrite(5,HIGH);
          mySerial.println(ch); // send the message to mySerial so I can check it.
          Serial.println("LED5 On"); // send this message back via UDP back to my iphone to confirm it happened.
        }
    else if (ch == 'H') // check to see if the message is "H" if it is set LED5 LOW.
        {
          digitalWrite(5,LOW);
          mySerial.println(ch); // send the message to mySerial so I can check it.
          Serial.println("LED5 Off"); // send this message back via UDP back to my iphone to confirm it happened.
        }
   
      else if (ch == 'F') // check to see if the message is "F" if it is set all LEDs LOW.
        {
          digitalWrite(5,LOW);
          digitalWrite(6,LOW);
          digitalWrite(7,LOW);
          mySerial.println(ch); // send the message to mySerial so I can check it.
          Serial.println("All Off"); // send this message back via UDP back to my iphone to confirm it happened.
        }
       
      else if (ch == 'X') // check to see if the message is "X" if it is Dispense the treat.
        {
          myservo.attach(9);  // attaches the servo on pin 9 to the servo object
          Serial.println("Dispencing Treat"); // send this message back via UDP back to my iphone to confirm it happened.
          for(pos = 0; pos < 20; pos += 1)  // goes from 0 degrees to 180 degrees
        {                                  // in steps of 1 degree
          myservo.write(pos);              // tell servo to go to position in variable 'pos'
          delay(15);                       // waits 15ms for the servo to reach the position
        }
          delay(40);
          for(pos = 20; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
        {                               
          myservo.write(pos);              // tell servo to go to position in variable 'pos'
          delay(15);                       // waits 15ms for the servo to reach the position
        }
        myservo.detach();
        Serial.println("Done");  // send this message back via UDP back to my iphone to confirm it happened.
       
        }
     
       
       
       
       
 }
}

Hope I have included everything...

Thanks in advance,

Leighton
Pages: [1]