#include <Keyboard.h>
int IRpin = 5;
int IRpin2 = 6;
int IRpin3 = 8;
int IRpin4 = 9;
int led = 13;
void setup() {
Serial.begin(9600);
//start the serial port
Keyboard.begin();
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
}
void loop() {
float volts = analogRead(IRpin);
Serial.println("volts1:");
Serial.println(volts);
delay(1000);
if (volts>500.00){
Keyboard.press(KEY_RIGHT_ARROW);
Keyboard.releaseAll();
}
float voltss = analogRead(IRpin2);
Serial.println("volts2:");
Serial.println(voltss);
delay(1000);
if (voltss>600.00){
Keyboard.press(KEY_LEFT_ARROW);
Keyboard.releaseAll();
}
float voltsss = analogRead(IRpin3);
Serial.println("volts3:");
Serial.println(voltsss);
delay(1000);
if (voltsss > 500.00) {
Keyboard.press(KEY_UP_ARROW);
Keyboard.releaseAll();
}
float voltssss = analogRead(IRpin4);
Serial.println("volts4:");
Serial.println(voltssss);
delay(500);
if (voltssss > 600.00) {
Keyboard.press(KEY_DOWN_ARROW);
Keyboard.releaseAll();
}
}
I connected 4 IR infrared sensors to Pro micro and only 2 of them are working. The other 2 are sending random values. Connection for all 4 IR sensors.: IR VCC->Arduino VCC IR GND -> Arduino GND Output-> 5,6,8,9