go_away

Author Topic: opto switch  (Read 2262 times)

0 Members and 1 Guest are viewing this topic.

Offline ZolragTopic starter

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
opto switch
« on: February 05, 2009, 03:12:01 PM »
Hi,
I'm trying to use an opto switch to control the movements of my robot. I use a microcontroler ATmega640.
I'm noob in robotic.
I'd like to write a code similar to this:

include libraries
start of the main function
initialisation of variables      //which variables do I need for this operation?
initialisation of the opto switch    // how to initialise the opto switch? opening the corresponding port on the ┬Ácontroler? what is the code?
while(1) (infinite loop)
  if (detection from the opto switch)  //what is the function needed to detect something with this kind of sensors??
     stop motor
     delay for a while
     restart the motor
  end
end

Could you write me a proper code for this application?
thanks a lot
alex

Offline frodo

  • Supreme Robot
  • *****
  • Posts: 329
  • Helpful? 2
  • BOW DOWN TO MY MIGHTY STARE!!
Re: opto switch
« Reply #1 on: February 05, 2009, 03:14:53 PM »
you're basically asking us to write the code for you. it would be better if someone wrote the code and walked you through it, so to speak. explain the code.
OMG!!!! I AM SUPREME ROBOT!!!

Check out my Web

Offline ZolragTopic starter

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
Re: opto switch
« Reply #2 on: February 05, 2009, 03:19:49 PM »
I totally agree with you but nobody I know is able to explain me this so maybe you can do it here....?

Offline ZolragTopic starter

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
Re: opto switch
« Reply #3 on: February 05, 2009, 03:43:55 PM »
Actually I don't really need all the code I just want a function for the detection from the opto swich (something similar to the IR sharp function from the library of avr)
and I need to know how to open the corresponding port to start the opto switch.....
that's all... is it possible to explain me how to do that please?
thank
alex

Offline frodo

  • Supreme Robot
  • *****
  • Posts: 329
  • Helpful? 2
  • BOW DOWN TO MY MIGHTY STARE!!
Re: opto switch
« Reply #4 on: February 05, 2009, 03:53:32 PM »
oh sorry, i misunderstood  ;D  i have never built a robot so have never programmed so i can't help. sorry!!  :(
OMG!!!! I AM SUPREME ROBOT!!!

Check out my Web

Offline ZolragTopic starter

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
Re: opto switch
« Reply #5 on: February 05, 2009, 03:56:12 PM »
It's ok don't worry  ;)  I can program in C++ but it's the first time I built a robot....

Offline frodo

  • Supreme Robot
  • *****
  • Posts: 329
  • Helpful? 2
  • BOW DOWN TO MY MIGHTY STARE!!
Re: opto switch
« Reply #6 on: February 05, 2009, 04:10:29 PM »
cool. put some pics on when you've finished  ;)
OMG!!!! I AM SUPREME ROBOT!!!

Check out my Web

Offline ZolragTopic starter

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
Re: opto switch
« Reply #7 on: February 05, 2009, 04:12:29 PM »
All right I'll do that  ;D if I manage to make the sensors work  :P

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,855
  • Helpful? 53
Re: opto switch
« Reply #8 on: February 05, 2009, 04:18:25 PM »
Could you provide us a link to the opto switch? We need to know how to get the right data from it. If it's just an analog voltage, you can do

int optoswitchreading = a2dConvert10bit(<<insert adc port # here>>);

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: opto switch
« Reply #9 on: February 05, 2009, 04:23:51 PM »
Could you provide us a link to the opto switch? We need to know how to get the right data from it. If it's just an analog voltage, you can do

int optoswitchreading = a2dConvert10bit(<<insert adc port # here>>);

Yes, datasheets are your friend.

Offline ZolragTopic starter

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
Re: opto switch
« Reply #10 on: February 05, 2009, 04:30:24 PM »
I still don't have the datasheet because it's a project with the university so I have nothing at home and I still don't know what are the details of the sensors but I'll send it as soon as I get the information...
Thanks anyway Razor

Offline ZolragTopic starter

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
Re: opto switch
« Reply #11 on: February 08, 2009, 04:07:12 AM »
Apparently our opto switches are numerical  so you don't need to convert the voltage but I still don't understand how to use it...
We also have micro switches which are actually real switches so it should return 1 if it's switch on and 0 if not (for example) but I don't get how the microcontroler can know when the switch is switched on....What is the function that check the state of the switch???
It must be really easy but I'm getting crazy here....
thx
alex
ps: sorry for all the "switch"  ;D

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,694
  • Helpful? 173
    • Society of Robots
Re: opto switch
« Reply #12 on: February 13, 2009, 01:23:08 AM »
Need help and code for the ATmega640 you say?

Have you seen my Axon?
http://www.societyofrobots.com/axon

 


Get Your Ad Here

data_list