Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - ROCO666

Pages: [1]
Exhibition / Re: a little Servo action
« on: November 26, 2011, 09:34:11 PM »
at the end of the code is the reference but I'll post it again the sensor is Sharp GP2Y0D810Z0F, it's very easy to use and it's also cheap, about 6 or 7 bucks.
Exhibition / a little Servo action
« on: November 25, 2011, 11:01:58 PM »
 hello there, i just got my wiring S and wanted to share a little example of servo controlling using a digital distance sensor. I think this could be helpful to people that are working in robotics and such.

without any more delays here's the code

Code: [Select]
  *Controlling a Servo via distance Sensor
  by ROCO666
#include <Servo.h>

Servo ser1; //create servo object to control a Servo

int sens = 8; // digital pin 8 used to connect the sensor output

void setup()
  ser1.attach(7); //attaches the servo on pin 7 to the servo object

  pinMode(sens,INPUT); //sets digital pin 8 as input

void loop()
  if (digitalRead(sens)==LOW)// if the output is low meaning there's an obstacle
 // (in this case the sensor is  active low)
    ser1.write(0); //this sequence sets the servo position
    //between 0 and 90 degrees every 500  miliseconds
  else            //if the output is high meaning the sensor is clear
    ser1.write(90); //this sequence sets the he servo position
    //between 90 and 180 degrees every 500  miliseconds


hope you like it.  :)
by the way the sensor i used is Sharp GP2Y0D810Z0F since i'm new here i'm not sure if it's okay to post links regarding the specs but you can find the datasheet webrowsing.
Pages: [1]