Go Down

Topic: using a fototransistor to control a servo (Read 1 time) previous topic - next topic

I succeeded in controlling a servo motor using the example code of the software.
Now i bought myself a fototransistor and i would like to use it to control the servo with the arduino chip (UNO) (for example a lot of light means go to 45 degrees/no light go to 0).
Does anyone know how to use the output of the fototransistor so i can use this to give the servomotor an input of 0-180?

thx in advance!
django

johnwasser

Connect the phototransistor between pin A0 and +5V.  Connect a resistor between A0 and Ground.  Use analogRead(A0) to get values.  Figure out the range of values you get.  In loop(): Read a value, map the value to the range 0 to 180 using the map() function, and move the servo to that position.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Grumpy_Mike

Note the spelling of phototransistor - it has a silent P as in Bath.  ;)

oh in dutch it is spelled with a 'f'
but thanks! it works now :D

Go Up