Motion Sensor Controlling servo motor

Hello,

Please help me with this project i want to work on. I am working on automated blind that uses motion sensor to open and close the blind with a wave of hand.

I have attached the code but i want to modify it to detect motion and go to a certain degree and stay on that stage until it gets another input(motion).

Thank you!

motion_Sensor.ino (3.62 KB)

What sensors are you using for motion and position?

Weedpharma

We are using PIR Motion Sensor. And the degrees i want the servo to go is from 20, 85, 135, and 180.

The PIR is basically a switch so treat as one. Once triggered drive your servo appropriately for the motor you have.

There are many examples of connecting and driving servos. You will need to do the research for something that matches your servo.

Weedpharma

This looks like a double post on the same subject.

These tend to annoy people especially if the extra info is in the other post!!

Weedpharma

Sorry for posting the same thing twice, i didn't mean to annoy people but i really needed help to decided what i want to do.

Anyways so do you suggest me to use touch sensor rather than the motion sensor for the action i want to have on the servo. Do you think thats better because it won't have a lot of distraction.

If so, how can i do that? I have a code for the touch sensor. The servo moves from 0 to 180 when i touch it and when i let go it goes from 180 to 0. But i have to do the other 4 stages i have described for the motion sensor.

Well assuming the touch sensor is really just an on/off switch, you could handle that in one of two ways that I can think of:

  • Have more than one switch, so depending which one is pressed, act one way or the other
  • Have one switch, and count the number of times it is pressed and move to a different position each time. This example shows how to count presses.

JimboZA your post was very helpful, i am very new to arduino but i will got with the second option you gave if hoping i can achieve the 4 stages i want. I probably will need help with the coding so i will post as i go along.

Thank you!

I already have a question, so when i do the count presses. rather than the push button i have to use the touch button, right?

I'm not sure what you mean..... to me, a "touch" button seems the same as a "push" button.

I mean they are basically the same except a touch sensor is where you just touch on it but for pushbutton you have to press the button. But let me try it and will let you know.

I don't think i am doing right on this code.

The one i have right below is how the website "http://arduino.cc/en/Tutorial/ButtonStateChange " declared but they are using buttonPin and ledPin.I wanted to use touchsensorPin as an input and servoPin as an output. How can i do that?

const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to

This should work for you.

#include <Servo.h>
Servo blind;
int blindPin = 2; //sensor input
int blindangle = 0; //sets blind to fully open

void setup()
{
pinMode(blindPin, INPUT);
blind.attach(9); //blind servo connected to pin 9
blind.write(blindangle); //set servo to open position

}

void loop()
{

if (digitalRead(blindPin) == HIGH) //check blind input for signal
{
blindangle = (blindangle+20);
blind.write(blindangle); //move blind down 20 degrees
delay(500);
}

if (blindangle< 180) //if blind fully closed then further signal will fully open blind
{
blindangle = 0;
blind.write(blindangle);
}

}

Thanks for that code, but after uploading it to the arduino and connecting the pins, it did not work. I have studied the code and it looks accurate to me, but could you reevaluate it to see why it may not be working? Also, I thought the touch sensor was analog and not digital pin. Could you explain your reason for using digital pins in the code?

Use digital and sense for pin going "HIGH"