rishiraj
Junior Member level 1
- Joined
- Dec 25, 2012
- Messages
- 15
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,393
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.
This is my code:
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'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.
This is my code:
Code:
#define Motor11 5
#define Sensor 9
int val=0;
void setup()
{
pinMode(Motor11,OUTPUT);
pinMode(Sensor,INPUT);
}
void loop()
{
val=analogRead(Sensor);
if(val==HIGH)
{
analogWrite(Motor11,HIGH);
delay(1000);
}
else
{
analogWrite(Motor11,LOW);
delay(1000);
}
}
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.