0
#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

  • What is your question? – sa_leinad Nov 30 '16 at 5:53
1

Pin 5 is not analog pins.

On the pro-micro only pins A0-5 and D4, D6, D8-10, D12 can convert an analog voltage to a value.

Just use the A0-5 pins instead, as that will work on any Arduino.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.