I was going to use serial communication to simulate a photoelectric sensor, but I’m not sure it would serve my purpose. My final program will employ edge connection and timing is key. Could I simulate a sensor by connecting an output pin to an input pin?
Unless your sensor uses serial communication, the answer is almost certainly no.
There is nothing wrong with connecting an output to an input, it just isn’t terribly likely to be useful. If your sensor simply toggles a pin high or low, you could indeed simulate that behavior, but you’d be doing it from within the same program you are trying to debug.
Your question doesn’t really make sense. Which sensor? What purpose?How does a program use edge connection? What aspect of timing is key, and what level of precision?
Well, to elaborate, I’m using two photoelectric sensors to measure the speed and axle spacing of cars traveling down to road. There will be an algorithm to calculate the needed quantities, and that’s what I need to test. When I present this program, it will be difficult to secure each class of vehicle and drive them down the street, so I’d like to be able to send my program which vehicle to simulate using the serial port (ie. typing MOTORCYCLE would tell my designated outputs to send pulses at the correct time to simulate a motorcycle passing by my sensors.) The rest of my program besides this serial communication and output portion could care less where this output came from, as long as it acted in the same manner the photoelectric sensors do, with zero when the receiver gets the transmitted signal, and one when it does not.
I will of course be debugging the regular program on a real street, but the purpose I’m asking about is simulation to present this project. It definitely wouldn’t be useful in the real world while set up this way.
Thanks
Edit: Haha I didn’t see that I had typed edge connection. I definitely meant edge detection.
The potential problem is that the code running to emulate the sensor and it’s output may affect the timing of the program you’re testing. Without knowing more details I can’t say how large the risk is. One thing is for sure, if you used 2 Arduinos, one to do what you want and one to emulate the sensor and it’s output, you’d have a better test bed.
quinman22:
Well, to elaborate, I’m using two photoelectric sensors to measure the speed and axle spacing of cars traveling down to road. There will be an algorithm to calculate the needed quantities, and that’s what I need to test. When I present this program, it will be difficult to secure each class of vehicle and drive them down the street, so I’d like to be able to send my program which vehicle to simulate using the serial port (ie. typing MOTORCYCLE would tell my designated outputs to send pulses at the correct time to simulate a motorcycle passing by my sensors.) The rest of my program besides this serial communication and output portion could care less where this output came from, as long as it acted in the same manner the photoelectric sensors do, with zero when the receiver gets the transmitted signal, and one when it does not.
I will of course be debugging the regular program on a real street, but the purpose I’m asking about is simulation to present this project. It definitely wouldn’t be useful in the real world while set up this way.
Thanks
Edit: Haha I didn’t see that I had typed edge connection. I definitely meant edge detection.
Do the algorithm on a PC. In C/C++. Feed it tables of numbers to simulate the hardware, e.g., tables of timer values that would be obtained on the eventual target system.
When that works properly, adapt it to the AVR.
re the photo sensors… be sure you’ll encounter only one way roads with one lane, like a driveway.
i did an technique similar to that: Two pairs of garage door safety-beam IR sensors. One near ground level, one at fender height of the car. Algorithm used time of beam-breaks to determine if car was entering or leaving based on the two sensors and that the beam break of the higher sensor-pair was before that of the one sending the tires. These garage door safety beam pairs can be had on eBay inexpensively. The Genie brand use a clever scheme for beam-break sensing, which I can explain if interested. The IR is essential - visible light won’t work. And the IR isn’t DC - it’s modulated with a carrier - kind of like the TV remotes with 38KHz. This is needed to get a reasonable signal to noise ration due to the IR receptor be a very narrow-band receiver.