Idk if my motor dc doesn't work due to a wrong wires connection or other thing. Also my IR sensor detects objects while there is no object. Idk what is happening. So I need help with the electrical connections and some help with the code.
PD: my IO ports are not defined in the board. There is no number of each IO connector. I just know that the first one starting from the left, is the pin 2. The others Idk.
The arduino 5V seems to be connected to red (+ve) and GND to black (-ve) on the breadboard.
Also the motor should not be powered from the arduino board - you need a switch or relay that is activated by arduino which in turn switches the motor on/off.
But if I use a switch, then it is already something external to the arduino circuit and therefore the motor will not be able to obey the commands of the program, right?
PS: It will not let me post more messages in the forum since I am new and there is a limit of 20 messages. I have contacted you by email. My email is the following one: zakariagamersito@gmail.com
1N4007 is a diode connected across the motor. The motor is an inductive load, so when the transistor (BD139) switches off it absorbs the current spike generated by the load.
Regarding the IR sensor, how are you looking at activating it? I mean the way a typical remote control works, or just to shine an IR source on it without any sort of encoding...?
If I understood correctly you want to start the motor when the IR sensor gets light (or light is blocked) and then stop the motor when the opposite happens, right?
But my question is how to connect the motor to the board. I also have another problem and that is that the infrared sensor does not stop detecting an object.
How can i fix this?
How should the transistor be connected?
I guess if its just object detection and on/off type operation, then an arduino is perhaps not needed. You could look at something like below. Its just an idea, not tested and assumes that the IR sensor is an active low output type (output goes low when IR is present).
How it works:
IR LED shines continuously on the sensor, so its output is low. So Q1 (buffer) output is low, so Q2 is off and no current flows through the motor (M)
When an object comes in between, IR LED light is blocked, sensor output goes high, Q1 output follows this and Q2 turns on thereby activating the motor.