This is a very basic problem but am not able to find a solution.
I'm just trying to control a motor (ON/OFF) using IR Sensor. I wrote my program code in such a way that if the IR Ray gets reflected then the sensor detects a 'HIGH' signal and he motor should start rotating. But maybe due to my utter stupid programming, its not working. Please help to rectify the code. I googled around other sources to find that whenever IR Sensors are used, the serial communication port of Arduino is also used but I don't know what changes shall I make in my code to make use of them in a productive manner.
Also to mention, I m using a H-Bridge for the motor which is externally powered using a 9V battery, the IR Sensor is powered from the (Vin) pin of Arduino, the entire circut has a common ground.
I am also not well versed with Arduino but from my experience in using IR in other controllers i think that you should use just digital read to get the HIGH/LOW from an IR sensor...no need to link it to the ADC. Use the port as digital Input and use digitalRead(sensor) and also use DigitalWrite(Motor11,HIGH/LOW). Try this hope it works not sure.
Hi..
1.) since u are only interested in whether there is a high o/p from the sensor or not, there is no need to use the ADC. use it as a normal input pin.
2.) what sort of an o/p are u getting.....
I am also not well versed with Arduino but from my experience in using IR in other controllers i think that you should use just digital read to get the HIGH/LOW from an IR sensor...no need to link it to the ADC. Use the port as digital Input and use digitalRead(sensor) and also use DigitalWrite(Motor11,HIGH/LOW). Try this hope it works not sure.
Yeah, changed all inputs and outputs to digital but still its not working. Don't know whats wrong. When I connect a LED to detect weather the high signal from Sensor is working then I found that its working fine. I men, the only problem is that, the motor does not turn on. The motor and H-bridge is working fine, I checked it.
Hi..
1.) since u are only interested in whether there is a high o/p from the sensor or not, there is no need to use the ADC. use it as a normal input pin.
2.) what sort of an o/p are u getting.....
1. Did this way, but problem still persists. Changed all to digital
2. The sensors, Motor, H, bridge are all working fine, I checked it. The sensor can make an LED glow if it detects a HIGH signal (i.e. if the IR is reflected back) but can't run the motor. I'm using an H-Bridge also for the motor but don't know, its not turning up.
Did you change all analog read and write to Digitalread() and Digitalwrite() ??
- - - Updated - - -
if you are using a DC motor you can use an IC L293D it is a motor driver IC which has a built in H bridge. If nothing works try replacing your H bridge with this one.
Did you change all analog read and write to Digitalread() and Digitalwrite() ??
- - - Updated - - -
if you are using a DC motor you can use an IC L293D it is a motor driver IC which has a built in H bridge. If nothing works try replacing your H bridge with this one.
void setup()
{
pinMode(Motor11,OUTPUT);
pinMode(Motor12,OUTPUT);
pinMode(Motor21,OUTPUT);
pinMode(Motor22,OUTPUT);
/////////pinMode(Sensor,INPUT); //not required to defined.by doing so u are using it as a digital input
}
void loop()
{
if it still doesnt work, may be its a hardware issue...
1. try using a ULN driver to drive the motors.....
2. make sure there is a common ground between the power supplies.....
3. post the specs of the motor u are trying to control and a schematic of your hardware arrangement
void setup()
{
pinMode(Motor11,OUTPUT);
pinMode(Motor12,OUTPUT);
pinMode(Motor21,OUTPUT);
pinMode(Motor22,OUTPUT);
/////////pinMode(Sensor,INPUT); //not required to defined.by doing so u are using it as a digital input
}
void loop()
{
if it still doesnt work, may be its a hardware issue...
1. try using a ULN driver to drive the motors.....
2. make sure there is a common ground between the power supplies.....
3. post the specs of the motor u are trying to control and a schematic of your hardware arrangement