Hello,
I'd found on the web a very interesting project to make the IR proximity sensor form IR led and Ir reciver. Everything was ok with the code but when i tried to implement it to my code something is wrong.
The Sensors should act like normal switches, so when the don't sense object they should start the program to fade led up, when they are sensing obcject the program should go oposite.
So, just to be straight program nr 1 fading led up and down with switches was ok, program nr2 just to test the sensor with arduino built in led was also ok, but both together they dont work.
here is the code:
#include <IRremote.h>
#define PIN_IR1 9
#define PIN_IR2 10
#define PIN_IR3 12
#define PIN_DETECT1 2
#define PIN_DETECT2 4
#define PIN_DETECT3 7
#define PIN_STATUS 13
const int ledPin1 = 3;
const int ledPin2 = 5;
const int ledPin3 = 6;
int brightness1 = 0;
int brightness2 = 0;
int brightness3 = 0;
IRsend irsend;
void setup(){
pinMode(PIN_DETECT1, INPUT);
pinMode(PIN_DETECT2, INPUT);
pinMode(PIN_DETECT3, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(PIN_STATUS, OUTPUT);
irsend.enableIROut(17); //IR LED Transmitter PWM Freq (probably in kHz)
irsend.mark(0);
}
void loop()
{
{
int buttonVal1 = !digitalRead(PIN_DETECT1);
if (buttonVal1 == HIGH)
{
if (brightness1 < 255) brightness1++;
}
else
{
if (brightness1 > 0) brightness1--;
}
analogWrite(ledPin1,brightness1);
delay(20);
}
{
int buttonVal2 = !digitalRead(PIN_DETECT2);
if (buttonVal2 == HIGH)
{
if (brightness2 < 255) brightness2++;
}
else
{
if (brightness2 > 0) brightness2--;
}
analogWrite(ledPin2,brightness2);
delay(20);
}
{
int buttonVal3 = !digitalRead(PIN_DETECT3);
if (buttonVal3 == HIGH)
{
if (brightness3 < 255) brightness3++;
}
else
{
if (brightness3 > 0) brightness3--;
}
analogWrite(ledPin3,brightness3);
delay(20);
}
}