I need help for IR sensor and DC motor wires connection. Also have a code but I think its wrong

Hey guys!

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.

int motor = 10;
int sensor = 2;
int valor = 0;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode (sensor, INPUT);
pinMode (motor, OUTPUT);

}

void loop() {
// put your main code here, to run repeatedly:

valor = digitalRead(sensor);
if (valor == HIGH); {
Serial.println("detectado");
digitalWrite(10, LOW);

if (valor == LOW);
digitalWrite (10, HIGH);
}
}

Please someone here??

Please post a schematic. That will help us help you better.

Can I contact you via mail?

No problem. But if you use the forum a lot more and better help will be available. There are many who know better than me.

1 Like

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.

1 Like

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

Something like this. Pardon the bad handwriting...

The IR sensor too needs to be wired correctly - not shown in my schematic.

Nooo, its good the handwriting :slight_smile:

Thanks for the circuit. I dont understand some of the component that are include there. Like the IN 4007

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...?

1 Like

Hi mate!

I have the 1n4007 diode and a transistor but not the BD139. I have a 2n2222a.

This will work to start programming the sensor and the motor?
Do I need a motor Driver to work on my project? Or I can do it without the motor driver

Thanks!

You want to just start/stop the motor with the remote, right?

If you follow the circuit I suggested, the BD139 is the driver which simply turns it on/off.

2N2222 is a signal/general purpose switching transistor but not a power transistor. It might work but better to use a power transistor.

Yeah, I want to stop and start the motor with the Infrared sensor (object detection).

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?

Exactly!

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.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.