Analog Signal, Digital Feedbacl

Hi All,

I am using an LDR that detect Analog Signals. I would like to control an servomotor, which is reading an digital signal. Is that possible ?

If it does not, how can I ensure both components can communicate well with each other ?

Regards,

YH

An LDR can provide analog information that an Arduino can read. Then some code can translate that into something that sends data to control the servo.

But you'll need a clearer description of what you mean by controlling the servo. What is the servo supposed to do when more or less light is seen by the LDR?

Steve

I am using an LDR that detect Analog Signals.

Nope. An LDR detects light. It outputs a voltage that can be converted to an integer value by the onboard ADC.

I would like to control an servomotor, which is reading an digital signal.

How? Exactly what is to be the relationship between the integer value obtained by analogRead() of the LDR and the position of the servo?

@slipstick I would actually control a saline water bag drip by using a micro-gripper that is controlled by a servomotor.

The example program Knob from the IDE reads an analog signal from a potentiometer and controls a servo with it. So replace the potentiometer with the LDR and a resistor and you're basically there.

As PaulS said you'll have to calibrate it by working out for yourself how far the servo should move and in what direction as the light on the LDR changes.

Steve

Hi Steve. I have tried that but it seems that it is not working.

This is the sample code that I have modified.

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 4, 5, 6, 7);

// the previous reading from the analog input
int previous = 0;

void setup() {
// set the speed of the motor to 30 RPMs
stepper.setSpeed(110);
}

void loop() {
// get the sensor value
int val = analogRead(A0);

// move a number of steps equal to the change in the
// sensor reading
stepper.step(val - previous);

// remember the previous value of the sensor
previous = val;
}

You said Servo. Your code is trying to use a Stepper motor. These are completely different things.

What EXACTLY are you using? Please post a link to the specification.

Steve

I am trying to use a Stepper Motor. I am controlling a Stepper Motor using LDR.

I am using 28BYJ-48 5V Stepper Motor

Since steppers don't have any positional feedback controlling them is a very different proposition from using a servo.

As you are using the Motor Knob program almost unchanged why not first try it with a potentiometer in place of the LDR. That will check that the motor wiring, power etc are correct and working. How exactly is everything wired (schematic/circuit diagram please)? Are you using a motor driver? Which one? How are you powering it all?

And please realise that "it seems that it is not working" is about the most useless thing anyone can say. Is it working or not? Does it do anything? What does it do? What doesn't it do that you are expecting it to do?

You can see what you're doing and what happens. We can't.

Steve

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you go back to ground zero, and tell us exactly what you want to have happen?

What controls the light to the LDR, what do you want the LDR variable signal to do to the stepper motor.

Are you trying to regulate the flow with a micro-gripper?

Thanks.. Tom.. :slight_smile:

Right now I am able to control the speed of my Stepper Motor by modifying the Stepper-Knob Code from the Arduino Website.

Based on Steve's comment, steppers don't have any positional feedback controlling them. So in other words there are no code or command in Arduino to control motor position for stepper motor isn't it ?

Btw, I am also trying to find a Stepper Library where I can have a glance of all the commands to control the stepper motor. Is there a website link to do so ?

Regards,

vader92

Since you continually ignore all of the questions that we ask, I've lost interest. You're on your own.

Steve

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

Btw, I am also trying to find a Stepper Library where I can have a glance of all the commands to control the stepper motor. Is there a website link to do so ?

A stepper can do one thing - step(). Just how many functions does a stepper library need to have?

In any case, a "library" on the Arduino is just a source file and a header file (usually). Feel free to look at the header file to get a list of the methods, and to look at the source file to see how the methods are implemented.

It is up to you to provide the means to know that the stepper has moved the required distance. On MASH, in one episode, Dr. Winchester said "I do one thing at a time, and I do it very well." That perfectly describes a stepper motor. You tell it to step, and it tries it's damnedest to step. If the forces pushing back on the stepper prevent it from stepping, it can't tell you that. So, you need to tell it to step, and then check your sensors to see that it was able to step.

Usually, those sensors are some form of rotary encoder. How they are mounted, and what exactly they are counting/measuring, depends on how you mount them and what your stepper is trying to accomplish.

Hi Tom, I think I have confused by the words I am using. What I want to find out if there are functions which enables me to control the position of the stepper motors.

Hi Paul. Attached is the circuit of my system.

slipstick:
Since you continually ignore all of the questions that we ask, I've lost interest. You're on your own.

Steve

Hi.

Your comment is really unfriendly and unhelpful. I just started trying Stepper motors and I am trying to make it clear as much as I can, NOT ignoring your questions.

Hi,
Try AccelStepper library from this site.

www.airspayce.com/mikem/arduino/AccelStepper/index.html

It contains extensive documentation on all of its many functions an examples.

Tom... :slight_smile:

What I want to find out if there are functions which enables me to control the position of the stepper motors

The mounting screws define the position of the stepper. All you can then do it make the stepper rotate clockwise or counterclockwise one step at a time. It is up to you to know the relationship between the number of steps you have taken and the "position" you want the stepper to be in, and to step() as many times as needed to get to the proper "position".

Hi,
This is not a schematic;


Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom... :slight_smile: