i am brand new with Arduino....as in i got a kit a few days ago. so any guidance is helpful.
I am looking to trigger a dc motor with a cell phone flash. i am thinking of using a phototransistor. will this be possible?
i am brand new with Arduino....as in i got a kit a few days ago. so any guidance is helpful.
I am looking to trigger a dc motor with a cell phone flash. i am thinking of using a phototransistor. will this be possible?
I am looking to trigger a dc motor with a cell phone flash. i am thinking of using a phototransistor. will this be possible?
Yes perfectly possible.
Get your photo transistor, wire it up to a digital input, collector to the input emitter to ground and enable the pull up resistors.
Then have another pin set to be an output, connect it to the base of a transistor through a 1K resistor. Emitter of this transistor to ground. Collector to the motor, other end of the motor to the + of the motor power supply. Connect the - of the motor power supply to the Arduino ground. Connect a 1N4001 diode anode to the collector cathode to the + of the motor supply.
Software.
When you see a LOW on the digital input pin, put a HIGH on the output pin.
I am trying to trigger a dc motor to rotate 360 degrees when a flash from a cell phone hits a phototransistor but i am having some issues figuring out how to do this. any help would be amazing.
I have attached a photo of my setup. not sure if going in the right direction.
I have attached a photo of my setup. not sure if going in the right direction.
No you haven't.
I am trying to trigger a dc motor to rotate 360 degrees
Just 3600? That is impossible without some feedback mechanism and some gearing.
I guess what I am looking to do is for the flash to turn the motor on for one second and then turn off.
Simplest possible version
// you can use any digital pins here...
int flash_in = 3; // flash sensor connected to digital input 3
int motor_out=5; // motor connected to pin 5
void setup() {
// initialize the digital pins.
Serial.begin(9600);
pinMode(flash_in, INPUT);
pinMode(motor_out, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
if (digitalRead(flash_in)) {
digitalWrite(motor_out,1); // turn on the motor
delay(1000); // wait for a second
digitalWrite(motor_out,0); // turn off
};
}
Better version (avoids using delay() so other things can happen in between)
// you can use any digital pins here...
int flash_in = 3; // flash sensor connected to digital input 3
int motor_out=5; // motor connected to pin 5
void setup() {
// initialize the digital pins.
Serial.begin(9600);
pinMode(flash_in, INPUT);
pinMode(motor_out, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
unsigned long int motor_off_time=0;
if (digitalRead(flash_in)) {
digitalWrite(motor_out,1); // turn on the motor
motor_off_time=millis()+1000;
}
if (millis()>=motor_off_time) {
digitalWrite(motor_out,0); // turn off
};
}