![]() | |
| Home Page | Mark Forums Read | Today's Posts | My Replies | Classifieds | Reviews | Photo Gallery | Web Links | Share Files | Advertise With Us | Ad List |
| |||||||
| Hobby Discussion Discuss other CNC-related Hobbies here. |
| This forum is sponsored by: |
![]() |
| | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
| ||||
| ||||
I am trying to get my optical limit switches to work. I have listed what I have below. Think that I have found out how to hook one up to my arduino but I don't quite know how to see if it is working. I have an Arduino Mega 2560 and plan on using a pin above 13 because the lower ones are used for a working stepper and some other things. The optical switch that I have is: Opto Interrupter IRT9608-F [SEN020] - $1.50 : iStore, Make Innovation Easier I tried using this code but didn't have any luck. #define optOutPin 51 #define optInPin 53 void setup() { Serial.begin(9600); pinMode(optOutPin, OUTPUT); pinMode(optInPin, INPUT); } void loop() { int val1; int val2; digitalWrite(optOutPin, HIGH); //digitalWrite(optInPin, HIGH); val1 = digitalRead(optOutPin); val2 = digitalRead(optInPin); Serial.println(optOutPin); Serial.println(optInPin); Serial.println(val1); Serial.println(val2); if(val2==HIGH) { Serial.println("HIGH"); } else { Serial.println("LOW"); } delay(1000); } Can anyone please help me? |
|
#2
| ||||
| ||||
| Can you diagram your connections to the device? Show where you are connecting power (what voltage?), values of any series resistors, and where you are connecting the arduino in and out pins? If you haven't already done so, you might want to experiment with using the part "manually" (using a multimeter to check its operation) before you hook it up to the arduino. |
|
#3
| ||||
| ||||
| This is what was written to me and this is what I am trying to follow except that I am using 51 for 51, 53 for 3 and I use the two grounds at the end of the digital row on the end of the Mega board. Pin (5)1, the anode of the diode should wire to a 250 ohm resistor, the other end of the resistor to a arduino output pin. Pin 2(ground), the cathode should wire to a arduino ground pin. Pin (5)3, collector, should wire to a arduino digital input pin that you also enable the internal pull-up resistor, or use a external pull-up resistor, say 10k ohms, from the digital input pin to +5vdc. Pin 4, emitter, wires to arduino ground pin. |
|
#4
| ||||
| ||||
| Why is the following line commented out: //digitalWrite(optInPin, HIGH); You need to set the input pin HIGH in order to use the arduino's built-in pull-up resistor, which needs to be activated, otherwise you will need to add an external pull-up resistor from the collector to +5 volts. It is possible that the internal pull-up resistor might have too high a value, in which case it might be necessary to to use a lower value external pull-up resistor. The easiest way to determine that would probably be to work with the opto interrupter in a breadboarded circuit, rather than hooked up to the arduino. That way you can make sure that the device is working, and make sure that the resistors are set to appropriate values. Last edited by doorknob; 05-06-2011 at 07:55 PM. |
|
#5
| ||||
| ||||
| One other thing that you can do is figure out if the IR illumination LED is actually illuminated. If you have a video camera or point-and-shoot camera, first make sure that it can view IR in its viewfinder screen by pointing an IR remote control (visible in the viewfinder) at the camera lens, pressing a button on the remote control, and verifying that you can see the IR light signal coming from the remote. If you can indeed see the IR light in the viewfinder, then point the camera lens to the IR emitter portion of the opto interrupter, and see whether you can see a similar light in the viewfinder. (My guess is that even though the opto emitter probably has a narrow field of transmission, you should be able to see the light, either directly or in reflection off of the other side, by looking at it from various angles). |
| Sponsored Links |
|
#6
| ||||
| ||||
| I thought that I would turn digitalWrite over right any information that I would get from the sensor. How do I read the sensor? I don't have a bread board. I didn't get to see your last post before adding this. That is cool. I can see the blinking light of remove. Now I have to hook the sensor back up. |
|
#7
| ||||
| ||||
| You should be able to read the input pin exactly the way that you are doing in your program. But you must either activate the internal pull-up resistor on that input pin by uncommenting that line of code, or else you must connect an external pull-up resistor to that pin. The idea is that you want a "weak" high signal on the input pin when the opto emitter is unblocked, but it will be pulled down to a low signal when the opto emitter is blocked (or vice versa, I haven't thought through the polarities involved). See http://www.arduino.cc/en/Tutorial/DigitalPins where it describes the technique of doing a digital write of HIGH to an input pin in order to activate the arduino's internal pull-up resistor on that input. Disregard the part of the discussion where they talk about dimly lighting an LED through the pull-up resistor - you are not driving an LED that way. As for a breadboard, the hookup is simple enough that all you would need is a few alligator clip leads, a couple of resistors, and a battery or 5-volt DC power supply (plus a multimeter) to do the testing. |
|
#9
| ||||
| ||||
| I don't see a light in the view finder light when I push a button on the remote. I have 5 of these sensor and I need three but if I have success before I burn them all out, I can just order more. I do have a 100 ohm tied to a 150 between the anode and pin one. |
|
#10
| ||||
| ||||
| OK, so you won't be able to use the camera viewfinder trick to view the IR, but you should be able to get it working anyway. I don't think that you need to worry about burning anything out unless you have a short circuit (or close to it) between the anode and +5 volts. Supposedly the arduino can source up to 40ma. of current from an output pin. The rated forward current of the LED in the opto is 50ma., but 40ma should light it up nicely. With a 250 ohm resistance, you will probably have less than half of that, but my guess is that that will also work OK. If you want to boost the current through the LED, but still keep it within the opto's rating as well as the arduino pin's rating, you could use just the 150 ohm resistor and you should be safe. |
| Sponsored Links |
|
#11
| ||||
| ||||
| I used the 150 ohm resister and changed the code. I just added another "if" so I can get val one and well a two. I don't get a change when I interrupt the beam. I get back: 51 53 1 0 Val 1 High Val 2 Low From this code: #define optOutPin 51 //no ; here #define optInPin 53 //no ; here void setup() { Serial.begin(9600); pinMode(optOutPin, OUTPUT); pinMode(optInPin, INPUT); // set pin to input } void loop() { int val1; int val2; digitalWrite(optOutPin, HIGH); digitalWrite(optInPin, HIGH); // turn on pullup resistors val1 = digitalRead(optOutPin); val2 = digitalRead(optInPin); // turn on pullup resistors Serial.println(optOutPin); Serial.println(optInPin); Serial.println(val1); Serial.println(val2); if (val1 == HIGH) { Serial.println("Val 1 HIGH"); } else { Serial.println("Val 1 LOW"); } if (val2 == HIGH) { Serial.println("Val 2 HIGH"); } else { Serial.println("Val 2 LOW"); } delay(1000); } |
|
#12
| ||||
| ||||
| I believe that val2 low is the condition that you should see when nothing is blocking the opto interruptor. And that val2 high should be what you see when you are blocking it. You might see val2 low even when you are blocking it if the pull-up resistor is not activated. What happens if you put a delay right after this line: digitalWrite(optInPin, HIGH); // turn on pullup resistors |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I guess this is an optical limit switch...how to wire? | HereinCS | DIY-CNC Router Table Machines | 17 | 03-09-2011 10:56 AM |
| Need Help!- Optical Switch | boozeboy | General Electronics Discussion | 5 | 05-07-2010 06:40 AM |
| Optical switch, on when I expected off | will gilmore | General Electronics Discussion | 9 | 04-23-2010 01:49 PM |
| optical switch | natchez | Xylotex | 3 | 05-01-2004 07:45 AM |