Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Inputs to a microcontroller

Status
Not open for further replies.

akira181

New Member
Hi there

I'm pretty new to the world of microcontrollers so I am using a BASIC Stamp module for the easier learning curve.

I have a question about sensor inputs to the microcontroller.

I plan on using PID control to stay on the line and light sensors to detect the line. Also, I'd like to be able to regain the line if lost, hence the use of a microcontroller. On a side note, what would be the best sensor, phototransistors/photodiodes or IR detectors?

My main question is, what is better, analogue inputs or digital inputs to the microcontroller? What are the pro's and con's?

Also, if digital, how would PID control work as there are no longer values to sum to find the error signal.
 
Analog vs digital

Well,

I think it don't makes much different because analog will be in the end an digital number....

And digital comm will be digital anyway.

I think the best thing is to use digital, itw ill make the project robuseter
and easyer to do. Offcourse it will depend on the sensors used..

Analog will be easier building but more hardware will be needed..

Tks
 
can you expand on that?

What do you mean by the analogue will end up digital?

How do the sensors affect it?

How will PID control work for digital if there are not any seperate values from each sensor to sum and find the error?
 
It will be very difficult to get this working with one sensor. Normally you would have 2 sensors positioned so that when you are over the black line the sensors both see white. As the bot moves off the line then you turn toward the sensor that sees black.

To implement a PID algorithm, you need to get something more than on/off. This can be achieved by counting one sensor as negative. You then end up with 0 for central, +1 for right of line and -1 for left of line.

Your proportional part will simply turn your bot toward the line.

Your integral part will grow bigger the longer your error exists.

Your differential part will oppose your integral and so will correct when you find the line.

Good luck.

Mike.
 
the sensors I'm using are just plain photodiodes. The output signal from them will be analogue, and I will convert it to digital when going to the microcontroller. It was a stupid question to begin with I think.

I was wondering though, how would I go about measuring the error for PID control if I use 5 sensors?
 
If you use 5 sensors and your line is only wide enough to activate 1 sensor at a time and your sensors give 0 for black and 1 for white then.

11011 = on line and a value of zero.
10111 = left of line and a value of -1
01111 = more left of line and a value of -2
11101 = right of line and a value of 1
11110 = more right of line and a value of 2

In reality, you will not get a clean switch between values and will end up with values like 10011 between 11011 and 10111. You can use these inbetween values to get a error value between ±4.

Mike.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top