CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > Hobby Projects > Hobby Discussion


Hobby Discussion Discuss other CNC-related Hobbies here.


This forum is sponsored by:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 05-06-2011, 12:22 AM
herring_fish's Avatar  
Join Date: Apr 2011
Location: USA
Posts: 60
herring_fish is on a distinguished road
Optical Limit Switch

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?
Reply With Quote

  #2   Ban this user!
Old 05-06-2011, 11:28 AM
doorknob's Avatar  
Join Date: Jan 2010
Location: USA
Posts: 1,240
doorknob is on a distinguished road
Buy me a Beer?

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.
Reply With Quote

  #3   Ban this user!
Old 05-06-2011, 06:28 PM
herring_fish's Avatar  
Join Date: Apr 2011
Location: USA
Posts: 60
herring_fish is on a distinguished road

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.
Reply With Quote

  #4   Ban this user!
Old 05-06-2011, 07:31 PM
doorknob's Avatar  
Join Date: Jan 2010
Location: USA
Posts: 1,240
doorknob is on a distinguished road
Buy me a Beer?

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.
Reply With Quote

  #5   Ban this user!
Old 05-06-2011, 07:48 PM
doorknob's Avatar  
Join Date: Jan 2010
Location: USA
Posts: 1,240
doorknob is on a distinguished road
Buy me a Beer?

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).
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 05-06-2011, 07:54 PM
herring_fish's Avatar  
Join Date: Apr 2011
Location: USA
Posts: 60
herring_fish is on a distinguished road

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.
Reply With Quote

  #7   Ban this user!
Old 05-06-2011, 08:02 PM
doorknob's Avatar  
Join Date: Jan 2010
Location: USA
Posts: 1,240
doorknob is on a distinguished road
Buy me a Beer?

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.
Reply With Quote

  #8   Ban this user!
Old 05-06-2011, 08:07 PM
herring_fish's Avatar  
Join Date: Apr 2011
Location: USA
Posts: 60
herring_fish is on a distinguished road

I edited in some thoughts in the post below.

I bought a volt meter today so I pulled the sensor out of the board. Pins 51 and 53 are putting out voltage.

Now I will hook it back up.
Reply With Quote

  #9   Ban this user!
Old 05-06-2011, 08:23 PM
herring_fish's Avatar  
Join Date: Apr 2011
Location: USA
Posts: 60
herring_fish is on a distinguished road

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.
Reply With Quote

  #10   Ban this user!
Old 05-06-2011, 08:35 PM
doorknob's Avatar  
Join Date: Jan 2010
Location: USA
Posts: 1,240
doorknob is on a distinguished road
Buy me a Beer?

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.
Reply With Quote

Sponsored Links
  #11   Ban this user!
Old 05-06-2011, 09:11 PM
herring_fish's Avatar  
Join Date: Apr 2011
Location: USA
Posts: 60
herring_fish is on a distinguished road

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);
}
Reply With Quote

  #12   Ban this user!
Old 05-06-2011, 09:27 PM
doorknob's Avatar  
Join Date: Jan 2010
Location: USA
Posts: 1,240
doorknob is on a distinguished road
Buy me a Beer?

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
Reply With Quote

Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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




All times are GMT -5. The time now is 06:58 AM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361