Show Posts
Pages: [1]
1  Using Arduino / Sensors / Re: slight change in sketch means sensor won't let servo run with the +5v connected on: January 27, 2013, 06:30:19 pm
The specs for the sonar says that it can work from 0 - 255 inches but I will try plugging in a bit longer distance.
2  Using Arduino / Sensors / slight change in sketch means sensor won't let servo run with the +5v connected on: January 26, 2013, 02:25:26 am
Hi hi! I will preface this by saying that I am an artist and don't have a great depth of knowledge with electronics but I am working away at it anyways (what better way to learn?). I have a show coming up where I am using my arduinos and I have them set up with a sketch where a servo runs when my maxsonar EZ sensor is tripped. I have one sketch that I run on most of them and I have modified it slightly for my opening (where the room will be crowded). Basically, I have only changed two variables in my sketch (distance where the sensor will be tripped, from two feet to two inches) and the time between pings from the sonar (from .5 seconds to 1 second) so that they don't run constantly if the room is crowded. Both versions of the sketch upload and have been verified and where it gets weird is when I plug everything together. Using the sketch with the shorter sensor distance, the motor won't run if the sensor is connected to the +5v on my board (I have the adafruit motor shield) but it runs just fine when its only connected to the ground and pin. The initial sketch runs whether its connected to the +5V or not. I don't know enough to know why (other than maybe with the shorter distance it draws less power and the 5v is too much?) so maybe you guys can help! Two questions:
1. Any ideas as to why this happens?
2. Do I need to attach my EZ sensor to the +5v on my shield or can I just leave it unconnected (and have it only connected to the ground and analog pin)?

Thanks for any help and I apologize for any wrong language (or if this doesn't make sense). 
3  Using Arduino / Programming Questions / Re: Help with servo code to make servo run for a few seconds when sensor is tripped on: July 02, 2011, 02:05:21 am
Thanks!  I also changed the code from servoStop to exServo.detach(); (and added exServo.attach (servoPin); into the start of the loop section) and that seems to have stopped the buzzing. I figured the stop just held it in place whereas the detach would actually shut it off.  I will also run your code, I need to start understanding the Serial info as well. 
4  Using Arduino / Programming Questions / Re: Help with servo code to make servo run for a few seconds when sensor is tripped on: July 01, 2011, 01:41:09 pm
Thanks so much for your help!  It is working now (the motor kind of hums or buzzes gently when the sensor isn't tripped - I'm going to assume this is normal?). I'm not surprised I messed up the code and wasn't using the servo library very well.  Is there a site/book with some good servo tutorials that I can use (that go beyond the servo ones on the arduino site)?  I can't seem to figure out the library by just looking at what I have on my computer, I guess a lack of experience.  Many of the examples I found didn't use the commands that you've written so I'm guessing I'm not finding the right stuff.  I have gone through many tutorials with LEDs and have gone through the Getting Started With Arduino book but was really having trouble with servo code.  It is a bit overwhelming to be jumping into something that I have no experience with but its super interesting and I am enjoying figuring things out and being able to get help when I can't.   Thanks again, I really appreciate it.
5  Using Arduino / Programming Questions / Help with servo code to make servo run for a few seconds when sensor is tripped on: July 01, 2011, 02:14:27 am
Hello!  I am super new to programming, electronics and arduinos!  I am trying to figure out the code to run my project but I am stuck.  I am trying to run a servo for five seconds when a sensor is tripped and then stop when it is not tripped.  Currently, my servo runs when the sensor is tripped but does not stay on for five seconds as I would like (it turns off the instant that I am out of sensor range).  What am I missing in my code to make it stay on for five seconds?  I have run this program for a LED and it works fine but I am obviously missing something with the servo code.  I am having trouble understanding some of the code as I am seeing either really basic code (which I understand) or overly complex code.  I am using:
Arduino Duemilanove
Adafruit mshield
GWS S35/STD continuous rotation servo
MaxSonar Sensor

Thanks for any help!  

Here is my code:
Code:
#include "WProgram.h"
#include "Servo.h"
int servoPin = 9;  //motor on pin 9
int pin_sensor  =0;  //sensor on analog 0
int inchesAway;    //inches away from maxsonar sensor
int pos=0; //variable to store the servo position
static void refresh();

void setup()
{
pinMode(servoPin,OUTPUT);
digitalWrite(servoPin,HIGH);
delay(5000);
digitalWrite(servoPin, LOW);

Serial.begin(9600);
}


void loop()
{
inchesAway = analogRead(pin_sensor) /2;
Serial.print(inchesAway, DEC);
  
  if(inchesAway <24) {  //if something is 24" or less away, motor on
    digitalWrite(servoPin,HIGH);
    delayMicroseconds(5000);  //stays on for five seconds THIS IS NOT HAPPENING
    digitalWrite(servoPin,LOW);
    delay(20); //20ms
    
  }
  
  else
  {
      Serial.print("OFF");        
      digitalWrite(servoPin, pos);  //when sensor isn't tripped, motor is off
  }
  delayMicroseconds(300);  //checks sensor every .3 seconds for person/object  

}
Pages: [1]