Connect with us

time trial using photosensor

Discussion in 'Microcontrollers, Programming and IoT' started by formach, Sep 3, 2012.

  1. formach

    formach

    6
    0
    Sep 3, 2012
    hello..

    i need some help..
    i have to make some device that can record a time of moving object
    so i got some clue that i have to use photosensor, controller and programming
    so anyone can help me with this??
    im not expecting to get 100% help..but atleast some idea..
    i really got stuck here...
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    9,136
    1,844
    Nov 17, 2011
    First get acquainted with photosensors. Here is a tutorail.
    Your description lacks detail, so I can only assume that you probably will need 2 sensors. One for the start trigger signal, a second for the stop trigger signal.

    Connect each trigger to a different input pin of the microcontroller, preferably use an input that can trigger an interrupt in the microcontroller. Set up the microcontroller such that
    - a signal at the start input starts a counter (software loop or hardware timer).
    - a signal at the stop input stops this counter.
    - after the counter has been stopped the counter is a measure of the time difference between start and stop signal. Depending on the counting method and the clock frequency of the microcontroller you can convert the count to a time and display it.

    This article describes the principle using ultrasound. Note that in the article the microcontroller activates a sender and receives only one trigger. You'll have to replace the sender section by an equivalent receiver section for generating the start trigger.
     
  3. formach

    formach

    6
    0
    Sep 3, 2012
    thank you for the reply...

    my idea is like this...once the1st receiver triggered,the programming will start counting until the second receiver triggered it will stop...i think it is same with what u have said...

    i think for the hardware section i still can figure it out...but for the programming..its still blur..
    can i copy the 1st receiver instruction to the 2nd receiver instruction with the 1st will start counting and the second will stop counting...is it like that?
     
  4. wingnut

    wingnut

    233
    8
    Aug 9, 2012
    Your program would be...

    1. Set up a loop to detect when start pin goes low (as light gets blocked from CDs). This seems like a one line instruction such as ... If pin A1 = 0 then goto StartTiming else keep looping

    2. Then you would have a timing loop at StartTiming.

    While A2 is not 0 (blocked by object)
    increment time counter by one microsecond
    keep looping

    3. Then you would just output the value of your timing counter.

    Easy to do in MikroBasic or on the Arduino.
     
  5. wingnut

    wingnut

    233
    8
    Aug 9, 2012
    I wanted to try your project on my Arduino uno.

    On the hardware side all I did was plug to insert two photoresistors (CdS), one with its leads into A0 and +5V and the other into A0 and ground. This is just a voltage divider circuit of two variable resistors connected between +5 and ground, with a tap from between them to analog port A0.

    Here was the Arduino C program to drive it. It worked OK and outputs the time in milliseconds. To start timing, I covered the first sensor (eg ball rolling past sensor) and to stop timing I covered the second sensor (ball rolling past second "eye"). This program can be improved (eg it takes no account of thickness of ball or time C commands take to execute) but it is a start.

    I checked the analog values the sensors gave first, and if one was covered it had values about 40 and if the other was covered it read 200.

    Here was the program...



    */



    // These constants won't change. They're used to give names

    // to the pins used:

    const int analogInPin = A0; // Analog input pin that the potentiometer is attached to



    int sensorValue = 0; // value read from the pot

    int outputValue = 0; // value output to the PWM (analog out)



    void setup() {

    // initialize serial communications at 9600 bps:

    Serial.begin(9600);

    }

    int count = 0; //set up your timing counter

    void loop() {

    // read the analog in value:

    sensorValue = analogRead(analogInPin);

    // map it to the range of the analog out:

    outputValue = map(sensorValue, 0, 1023, 0, 255);

    if (outputValue <100) // you are covering the start semsor

    {count = 0;} // start the time count

    //{Serial.println(outputValue);}

    if (outputValue >200) // you are covering the out sensor

    {Serial.println(count);} // write the time in milliseconds to serial monitor

    delay(10); // delay 10 microseconds

    count = count + 10; // update the time counter by 10 microseconds

    }
     
    Last edited: Sep 4, 2012
  6. formach

    formach

    6
    0
    Sep 3, 2012
    so if i got arduino uno,2 photoelectric sensor ....then ill program the arduino..connect to the laptop...and my project is working...am i right?..im sorry asking this type of question...
     
  7. wingnut

    wingnut

    233
    8
    Aug 9, 2012
    Yes, that is what you need.

    Is this a genuine project, or just some kind of homework?
    What exactly are you planning to time?

    What I described above is just a general setup, but it would have to be tailored for the specific thing you have in mind.
     
  8. formach

    formach

    6
    0
    Sep 3, 2012
    i dont really understand what u mean by genuine project...but this is something that i have to do for my studies..
    the problem is like this...a company try to setup a new conveyor..so they are trying to get how many seconds for a bag moving from one point to another point..they want to test on different surface...to get a precise time..they want this device to be done..i hope this can make u clear...
    and did u know any software to simulate this project?my friend suggest fritzing but it can not do simulation..im trying to simulate first before making a real one..
     
  9. wingnut

    wingnut

    233
    8
    Aug 9, 2012
    Now I understand that this is a project for your studies - and they have set you the problem of determining the time it takes a bag to move between two points.

    Since the problem itself could be solved by taking a stopwatch and timing the bag, I assume that the process itself is what is important, and that process involves using a simulation.

    I have seen simulators for the PIC microprocessor but do not offhand know of one for the Arduino - though there must be. The uno uses the ATmega328 chip - for which there must be a simulator. I dont know how a simulator could simulate how the uno writes data to the com serial port of your pc.

    These only simulate the programs code - they do not simulate the components attached to the microprocessor (which seems to be what fritzing focuses on).

    I really dont know what more to suggest. In the past when doing PIC programming in assembler, the assembler simulator would show what all the registers were doing, when a button was pressed and the microprocessor pins became high or low. But unless you need assembler, writing in assembler is to be avoided.

    Do they tell you which microprocessor to use and which language to write your code in? That would determine the simulator to use.
     
  10. CocaCola

    CocaCola

    3,635
    4
    Apr 7, 2012
    A vast majority of the current micro simulators also have simulations for external components, especially things like LCD displays, or at least let you see the serial output...

    But, personally this is a simple project that I wouldn't even be bothered with simulation, I would just build a quick mock up and tweak it on real hardware...
     
  11. formach

    formach

    6
    0
    Sep 3, 2012
    no specific microprocessor but if i use pic16f877a i can get it free from my university..use assembly..but i want to use arduino so i dont have wasting my time on the circuit..
    i need to do simulation because it is the part of the project..
    how about i program the the microcontroller using mplab and simulation using proteus?
    any advice for photoelectric sensor circuit?
     
  12. wingnut

    wingnut

    233
    8
    Aug 9, 2012
    On the Arduino uno the circuit was as simple as this, and worked fine as an analog input.


    Ground------------CdS---------PinA0---------CdS---------+5V

    In other words both photoresistors acted like a potential divider, with A0 in common with both, and the other legs of each photoresistor going to ground and +5V.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-