This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CNY70 Wiring Problem with TM4C123

Other Parts Discussed in Thread: LMC6482

Above figure  CNY70 (reflective optical sensor) wiring diagram that I found in the internet. I'm using TM4C123 series MC. Have 2 questions:

1) Can I use the 3.3V output of the microcontroller rather than 5V? If you suggest external voltage source, which components should I use to protect the MC?

2) As you see I'm quite noob at electronics, and electronic components. I've started taking Edx: 6.002x Circuits and Electronics. Which courses, or books do you suggest further to study?

Thank you

  • Hello Emrah,

    Which Pin of TM4C123 gives an output of 3.3V? The GPIO's when driven 1 can generate ~3.3V and may be able to drive the CNY70. However if the current drain is to high this may drop the voltage of the device or damage the IO.

    In the past we have used a 3.3V supply with a FET whose Gate is connected to the GPIO to allow for large drive currents.

    Regards
    Amit
  • Hello Amit

    I was thinking of supplying power to the CNY70 from the +3.3V pin (as seen in the image). Ground is also from the TM4C's GND port. I would connect the output of the CNY70 to PB0. This was the plan.

    And a new idea comes into my mind:

    1) I get a 5V battery, and supply 5V and GND to CNY70.

    2) I replace the 10K resistor with a lower one, so I can obtain lower CNY70 output voltage. But I can't find the internal resistance value of the CNY70's transistor.

  • If your circuit is correct then that LED is drawing significant current. Drawing from the supply rather than an I/O pin is certainly the correct thing to do. You can lower the resistance in the LED circuit and get the same current flow and the circuit should remain operational (do not forget the voltage drop across the LED).

    Do not assume the transistor and LED have to share the same voltage (or ground for that matter).

    You can hook up the transistor in the other direction and use it as a pull down. You will have to check that its drop is low enough.

    You probably won't find a resistance for the transistor, they are more usually characterized by voltage drop.

    Add Horowitz and Hill to your references. They talk about a new edition although I've not seen one.

    Robert
  • Hello Emrah,

    That should do. But do put a current limiting resistor on the path.

    Regards
    Amit
  • Might I add - "PRIOR to making any connection to MCU's I/O - check & recheck that the external signal being attached remains - at all times - w/in the MCU's specified voltage ratings. (3V3 to 0V - yet many pins may accept to 5V - although 3V3 remains safest.)
  • Um, Amit

    That may work with 5V tolerant inputs but the transistor to a first approximation is a constant voltage drop device. It's quite possible the transistor will burn up from overcurrent before the voltage output changed significantly from changing the load resistor.

    It may be a bad idea to drop much load across the transistor in any case but that's a separate worry.

    Robert
  • Hello Robert,

    The CNY has a forward current of 50mA and Surge current of 3A (tp<=10us, which is a significant lot). A current limiting resistor would be a good to have on the LED part.

    Regards
    Amit
  • Isn't that what the 200 Ohm resistor on the LED currently does? By my back of the envelope calculation it sets the LED current at approximately 20mA. I cannot ever imagine shorting an LED across a power supply.

    If that's a 50mA rating on the transistor then lowering the load resistance isn't going to make very much difference, if any, to the output voltage of that circuit.

    Robert
  • Hello Robert,

    Ouch. You are right. The way the diagram was made makes the "2nd run though" miss the "R" for me.

    Regards
    Amit
  • That's one reason for recommending Horowitz & Hill, they have a short section on drawing clear schematics (among other recommendation don't draw little loops over crossing wires and supplies should be at the top with returns at the bottom as much as is possible). No many references I've seen go to the trouble of suggesting how to make schematics that communicate clearly.

    Robert
  • Robert Adsett said:
    recommending Horowitz & Hill, they have a short section on drawing clear schematics

    Roger that - and my firm's (sole) copy "disappeared" w/last year's intern crue.    (not that any accusation is (much) suggested)

    Does it make sense to urge poster - prior to launching test/verify of that external circuit - to first emply a simple switch (w/proper pull-up/down Rs) and exercise the target GPIO pin - so that its operation - in response to valid signal levels - is confirmed?

    Skipping that - both GPIO pin handling - input reading - AND the external circuit all rise to, "Likely Suspect!"    Two of (those three) may be eliminated - quickly/smartly - by the simple application of (drumbeat) KISS...

  • I like that idea.

    Do a simple test with only a few components involved

    Robert
  • Thank you - thank you very much!     (think Elvis - sotto voice)

    Note that our firm has "stylized these" - small, clean pcb - w/plug-in cable - used repeatedly & proves robust... (our board designs - most always - employ mating headers for, "eased - repeat" use.)

    Anything so that we do not (always) have to stop/think/search for - and "re-invent the wheel!"    (death to any small biz - and (unfortunately) we see so often @ clients/others...)   [i.e. death by 1000 cuts]

  • After all the helpful responses, I realised that it is impossible to solve this problem without trial and error on the breadboard. So I bought and used a multimeter for the first time. Took some time to get used to it. Sorry for the delay.

    In order to keep things simple as you suggest, and not to harm the MC, I have tested the CNY70 without connecting to MC. Used a 9V battery as voltage source. I have built the setup according to the figure below. The figure is screenshot from a Spanish youtube video (I have no Spanish, but the video helped alot). Please note that, I have modified the figure according to final resistance values I use. I've changed the resistance value in the circuit till lowering the AB voltage to 2V max for safety.

    (Sadly, I wasn't able to find the book, and wasn't work on creating proper schematics neither.)

    Hopefuly my last question comes: Since I have output voltage less than 3V, should I connect the B to a MC port set as ADC? If so, how should I select the resistance value between B and the port? I couldn't find the maximum possible allowable current limit for the GPIOs.

    P.S: Adding the link of the Spanish youtube video. May help people who may have the same problem in the future.

    www.youtube.com/watch

  • You're correct in noting that ~2V0 will "not" be seen as logic "1" by your MCU's digital input. Yet - employing an ADC in this role adds further complexity - "KISS" rebels/protests.

    Usually a, "low drop diode" (i.e. Schottky) can be wired to limit the input excursion of your GPIO to "just above" 3V3 - which should prove safe. You'd tie the cathode of that diode to 3V3 - the anode to the junction of your emitter resistor & emitter - and then allow the voltage to "flirt" with 3V (via resistor value tweak) when the transistor is conducting.

    Might it be that your (inventive) pull of a "Spanish, youtube video" to serve as a more legible "schematic" breaks new ground in Tivaland?

    Do continue to experiment (before) you introduce the signal to your MCU - recall the adage - test measure many times - NEVER replace the MCU!

  • I second the suggestion of using a diode to protect the micro input.

    I was initially surprised by the low measured voltage. I had expected that the transistor would switching. However, you do still appear to be in the safe power region. The output should vary with the reflectivity of the target.

    You could increase the resistor value to get better output but I'd also use A comparator to improve the quality and robustness of the signal. Unless you want to measure variances from different surfaces. In which case the ADC and more experimentation is called for.

    Robert
  • Robert Adsett72 said:
    Unless you want to measure variances from different surfaces.

    As responsive and descriptive as this poster has been - point Robert brings - flew (far) over this reporter's dull head.    Indeed - the "Anti-KISS" use of the ADC may be justified - if signal level gradations - rather than simple logic levels - is "in play."

    Poster may do himself - and helpers - more good by (bit) detailing his application.    Having to "guess" is very much second to a clear, complete project description...

  • Dear Friends

    In my test setup is a vertical transparent plastic pipe, with tennis balls inside. The balls can be in any color (yellow, orange, blue etc). Example display of the pipe and balls can be seen in photo below:

    I will drill a small hole on plastic pipe from side, and open the pipe from top and bottom. Will use CNY70 like a level sensor.
    All I care is if there is a ball at the predefined level or not. The colors of the balls are not important. This is the most easy to use sensor that seller in the radioshack offered, ofcourse there may be much easier/better applications.

    I must admit that, it is easier for me to find/search a random safe spot for both the circuit and MC, and dealing the output signal via ADC. Because I'm quite a beginner in electronic components and circuits, but i'm abit better and more practiced in programming. The system doesn't have to be very robust, and efficient at the momement. But I hope to create better circuits as I read, learn, and practice more.

  • Substantial application detail now arrives - good that - thank you.

    Some quick observations/comments:

    a) will the "real" application actually detect tennis balls?    (your photo/illustration may (again) display your resourcefulness in, "gathering source material.")    Ask that as there must be minimal/marginal "reflectance" from such surface - but surely near total blockage of an imposed, "light-beam."    Reflectance vs. Light Beam blockage is most likely to impact, "Rules of design engagement."

    b) You note, "Seller in the RadioShack" - in the US - RadioShack is (effectively) "no more" and some have suggested that (sometimes) components supplied - had not met all performance test requirements.    I am simply reporting (thus hearsay) but such may signal that your (assumed) single CNY70 may perform "outside" of normal/customary device specifications.    Multiple devices - likely bearing newer date codes - may present better & more consistent operation & recovered signal performance.

    c) ball velocity may prove an issue - as will the separation - between adjacent (or successive) balls in transit.    And note that gravity's "pull" will accelerate ball descent - which may be further influenced by the rate of "launch."   (launch = initial speed of propulsion)

    Surely more issues lurk.    (I leave (some) meat on the bone for Robert, Veikko, Luis)

    Running a small tech firm - while your "vertical pathway" is bit unexpected - your search for, "Conveyor's,  "missing or improper object" detection methods" is sure to provide very fertile ground for your exploration/exploitation...

  • Dear Friend

    Thank you for all suggestion and help, especialy about the "Clear Object Detection" part. I have found quite a good industrial sensors in the internet after your suggestion, which can be/should be used in the final product if all goes well. But I don't have much chance to buy one of them at the moment. I see your concerns, I will try to answer them:

    a) Trust me this small sensor is a non-critical component in the current design and most of the critical parts had already been designed. It is only a small part in the design. I'm thinking of CNY70 and its circuit as a "replecable" sensor or design in the future, as I (hopefuly) learn more about electronics. At the moment all I need is a some howworking sensor, that doesn't have to be very efficient, that doesn't have to detect balls %100 all the time. I'm trying to avoid much money/time spend on this prototype #0. Resources are very criticaly scarce, until I build a dirty but somehow working device, and some how get funded.

    I have checked the reflectance of the tennis balls with CNY70, altough they don't have as much as reflection as the white plain paper, there is some. At least I have detected some voltage change (in the order of 1.5V) with the multimeter when doing the tests. As the balls get dirty and darken, I guess I will have some problems with the detection. But it is not the a concern at the moment, because the sensor would already been replaced with a better one such as clear object detection photoelectric sensors at that time. Bytheway if I have a problem with the reflection from the pipe, I will replace it with dark plastic pipe of similar diameter.

    b) You are probably right about the seller, and the device. But I got a feel that I'm very close to operating this sensor. It is sad, but that will be the only operating electronic sensor in my tiny little arsenal :)

    c) The balls will stationary during the sensor check. I will design another dirty and cheap mechanical gate for the bottom of the pipe. (I had already checked some old patents). I will not count the number of balls. All I need is if there are enough number of balls inside the pipe before the operation starts.

    Hope this answered most of your concerns. Thanks for all the assist my friend :)

  • Thank you - as well - always nice to receive quick/detailed feedback - just as you have supplied.

    My sense - just working w/the facts presented herein - you'll speed, ease & enhance your design by switching from, "Reflective" to Light Blockage."    It should not be hard for you to locate properly matched, "Light Transmitters & Receivers" (often IR - think TV remote) and to simply detect the "LOS" (from NASA - "Loss of Signal") when a ball blocks the receiver.     (you do not have to utilize the TV code modulation scheme - simple, pulsed On/OFF should be sufficient.

    As for funding - when we started my small firm (dinosaurs ruled the earth) we faced similar issues - most were solved by our approaching qualified users (i.e. buyers)  of our proposed projects - who eagerly provided financing.

    I suggest that you some way/how consult legal & accounting experts - to assist you in such implementation - prior to (and if) you make such an approach...   And again - your study of "Conveyor Detection Products" will prove most helpful.

  • I think I made a mistake to move too fast without finishing a basic electronics course, but anyway I practiced and learned alot with the help of you. I'm returning back to my online course to learn more, still missing many basic things. Such as reading technical data sheets, safe operation modes for amplifiers and TM4C, optic sensor types etc. I have also ordered the Horowitz's book.

    My homeworks are:
    1) Return back to this subject in a few weeks time with a solution obtained
    2) Testing the light blockage type sensors you suggested at that time.

    See you, and take care until then
  • emrah erden said:
    I have found quite a good industrial sensors in the internet after your suggestion, which can be/should be used in the final product if all goes well.

    Definitely the approach to take if you can.  They will be more expensive in parts but less expensive to integrate and they will have taken care of a lot of concerns so you don't have to anticipate and work around them.

    emrah erden said:
    I have checked the reflectance of the tennis balls with CNY70, altough they don't have as much as reflection as the white plain paper, there is some.

    Consider sanding the balls (less fuzz on the ball to absorb/scatter) and/or painting the ball to be more reflective.

    Another item to consider is that you may get reflection from the other side of the tube. 

    cb1, I think mentioned using an interruption sensor instead. That may be a good idea and for some the other 1/2 of the sensor is simply a mirror. Some sensors will be easier to align than others.

    Robert

  • Robert Adsett said:
    cb1, I think mentioned using an interruption sensor instead. That may be a good idea and for some the other 1/2 of the sensor is simply a mirror

    Precisely why I suggested that experimenting poster make good effort to see how the industry - in general - attacks.    Re-invention of the wheel - while suggested by some here - really makes little sense.

    Robert's suggested, "mirror at the tube's side - opposite of the source transmitter" indeed demands a fine initial adjustment - and forces both a stronger & more narrowed light beam - to prove robust & adjustment-free over time.   

    In our book - separate transmitter & receiver (one at each tube side) is far simpler, faster to install & align - and proves far more able to, "maintain that needed alignment."   No matter how well a system performs, "post critical alignment" - if it fails later - clients become most unhappy!    Long term robustness should be a major goal - and separate TX & RX-  proves best means to achieve that.

  • Best in the alignment case are fork style interruption sensors, a prefabricated U with transmitter on one side and a sensor or reflector on the other. They even come with multiple beams for more robustness and the throats can get quite large.

    Short of mangling the fork, there is no need to align.

    Robert
  • As I promised I'm back again to inform you that I found the solution, and it was tested and works. Hope this post helps disoriented newbies like me in the future.

    Steps I Have Followed:

    1) Built up some electronics background with the help of Edx courses. Electronic Interfaces course helped me a lot to gain hands on experience.

     https://www.edx.org/course/circuits-electronics-mitx-6-002x-0 (Circuits and Electronics)

     https://www.edx.org/course/electronic-interfaces-bridging-physical-uc-berkeleyx-ee40lx-0 (Electronic Interfaces: Bridging the Physical and Digital Worlds)

    2) I have asked stack exchange forums, how CNY70 works and how to read the data sheet. And got tons of good information:

    http://electronics.stackexchange.com/questions/179115/understanding-the-cny70-reflective-optical-sensor

    Solution to Problem:

    I have built the CNY70 circuit according to data sheet specifications, and connected the CNY70's output and 1.65V to LMC6482 Operational Amplifier (Op Amp) as Robert Adsett72 stated. Op Amp is railed to 0 and 3.3V. Now I get 0 or 3.3V, no need to use ADC of TM4C.

    Plese note that I have obtained 1.65V by using voltage divider on LF33ABV 3.3V voltage regulator. Energy is suplied from battery.

    Thanks for all messages and help.

  • A couple of posts seem to have disappeared here

    Robert
  • Robert Adsett72 said:
    A couple of posts seem to have disappeared here   

    In the (now) immortal words of (WW2 prison guard) Sergeant Shultz, "I know nothing!"

    (note all declarative sentences - w/improperly appended "?" - are duly flagged...)

  • I had come up with a solution after weeks of study, and my post seems like got deleted..

    Edit: Good that my post is back. All fine now

  • emrah erden said:

    Above figure  CNY70 (reflective optical sensor) wiring diagram that I found in the internet. I'm using TM4C123 series MC. Have 2 questions:

    1) Can I use the 3.3V output of the microcontroller rather than 5V? If you suggest external voltage source, which components should I use to protect the MC?

     First question YES you can use due IR diode need 0.9-1.2V forward bias depending on Wavelenght emitted, shorter wave (going to ultraviolet require higher voltage approaching 4 V and far infrared area require under 1V semiconductor physics help understand why due to quanta energy but don't worry about and just learn how much LED voltage is in function of light temperature).

     On micro side two trouble can come in, first your device has a high impedance and ESD/EM/F/RF are forever worst enemy, secondary your output from infrared transistor is from emitter port, so lowest impedance from power rail, if you do a wrong operation setting pin as output you can damage TIVA. So to avoid both trouble add a resistor (470Ohm-few KOhm)  from emitter of cny to TIVA GPIO then a capacitor of 1nF to few tens of nF, you remove all ESD can get from CNY and also remove noise from detecting.

     In this Cell phone pervaded world I also suggest add few tens pF capacitors in parallel to gpio (close path to ground where terminal are attached and another same value on both LED and output of CNY, these can block RF than getting junction ionized or polarized by rectification.

    On CNY side you are exposed to failure too, Tennis ball are not antistatic so it can carry a huge charge, try prevent it from damaging sensor or you get out of business in a few stroke.

  • emrah erden said:
    2) As you see I'm quite noob at electronics, and electronic components. I've started taking Edx: 6.002x Circuits and Electronics. Which courses, or books do you suggest further to study?

     Second question you are on a good boat so choose course there and try graduate.

     When you are more acquainted with all devices and how to do energy calculation evaluate a different approach:

     Don't drive infrared emitter by DC 20mA CW but use an High energy near 1A (check data sheet)  short pulse averaging to CW 20mA, when you drive with ten time the current of CW your energy is the same but pulse carry 10 time more energy and S/N noise is improved by 10dB (20dB in voltage).

     Again you can reveal pulse by measuring width than using a complex ADC evaluation and clearly modulation also reveal if light come from reflection or sun exposure. TV and appliance transmitter IRDA too use an high power narrow pulse to improve transmission over distance.

     Don't use GPIO to drive LED, must use a mosfet driver to obtain lower impedance needed by. Use capacitor close to pulse generating circuits and dont use spare wire, energy of short pulses radiate away from circuits.

  • Roberto Romano said:
    ...or you get out of business in a few stroke.

    As do many tennis players when up against hard (and line hitting) superior players...    (that's clever word-play Roberto - not to be missed...)

    Great detailed tech advice as well.    We note that the "plastic tube" itself is a substantial static generator.   I believe there are special chemical sprays & methods to reduce the undesired ESD which such tubes may create...

  • Hello Robert, Emrah

    I checked the forum logs and it seems the post were not there. May be a server glitch

    Regards
    Amit
  • emrah's post showed up in my e-mail and in notifications at the top of the forum pages (along with a suggestion of a reply from cb1 which did not show up in e-mail so may be the usual forum false flag). So the post definitely made it to the forum if only long enough to send out copies.

    I would appear the logs have a leak as well.

    Robert
  • May I note that w/the last "forum update operation" - each/every post to which I respond lands in my (secondary) email. Surely certain posts warrant such "advice" - but not all - and I try hard to "remove" the default, "notifications on" to reduce the swelling email. Thus far - nothing works!
  • Hello Robert,

    OK, let me check then again into the logs and status for review

    Regards
    Amit
  • Dear Roberto

    That was quite a nice and technical approach to reduce the noise, and to get more reliable results. Never thought pulse inputs have such amazing uses. Your previous post was also quite important for protecting the circuit against ESD. I will add the capacitors of the previous post, but I'm just a newbie getting used to circuit elements. Driving the system with pulse maybe a bit harsh for me at the moment :) By the system I'm building is just a prototype, doesn't have to be very robust and accurate. As the time and my knowledge progress, I will try to apply your suggestions. Thank you my great teacher :)


    Dear Friends

    I should state that, while I was away from the forum, I have changed the design. Lately, I'm using the CNY70 for angle detection of stepper motors, not for detecting balls. (I know there are servo motors, but this was quite a good practice :) ) For the ball detection, I have bought a cheap IR light barrier circuit, as one the cb1's suggestions.

    Anyway, now I can build a working circuit with CNY70. It may not be perfect, but at least it works. Thank you for all the amazing and helpful contributions.


    Dear Amit

    My problem was solved and all the posts were quite helpful. I don't know which post to mark as answer. Could you please make a suggestion or do the marking?
  • Hello Emrah,

    The answer(s) that lead to a solution may all be marked. There may be more than 1 correct method/steps.

    Regards
    Amit
  • emrah erden said:
    That was quite a nice and technical approach to reduce the noise, and to get more reliable results. Never thought pulse inputs have such amazing uses. Your previous post was also quite important for protecting the circuit against ESD. I will add the capacitors of the previous post, but I'm just a n

    ... Snip...

    Hi Emrah, thank for selecting as correct answer,  as Amit wrote I forever supported this policy, please check all answer are close to solving your problem not just one. I am sure none of us who helped you, are there just to collect point like some useless super guru. I trust on correct honest sharing of income to all contributed to solution.
     This is how scientist perceive knowledge and technology, who come here to collect point or do simple "social network" activity is a big loser wasting his and community time.
    When you can take some time invest it to learn some old scientist phrases, they are forever a guide to correct living but forever take care of you against actual world.
     Have good time as I wish for all good people are here sometimes hit by worst policy of insane commercial "bean counters".