0

Example for MRMS refl. sens. 9x, CAN, anal, I2C, visible light (mrm-ref-vis9), using analog values

Prerequisites

Required hardware:

Task

We will read 9 sensor's analog outputs, reflected light's strength.

Hookup

  1. Do not connect battery yet.
  2. Use ML-R Cable KK254-KK254 20 cm (mrm-kk2.54-2.54-20) and connect regulator's 5 V voltage output to sensor's voltage input (red connector). If You have some other power supply, use 2 Dupont 0.1" wires to deliver 5 V DC to the red connector. Mind + and -! The sensor has reverse input voltage protection, but it is better not to test it. At least, the sensor will not work, if voltage is reversed. If You power the microcontroller card using the same regulator, You will have to rework the wires to supply the both cards.
  3. Connecting 5 V voltage output to Mega 2560 "5V" input, like in the picture, will deliver voltage to Mega 2560 internal linear regulator's output, skipping Mega 2560 protection, but MRMS Power Supply 3x (mrm-ps3x) has the protection built-in. Doing so will replace an inefficient linear regulator with a switching step-down regulator. If You do not have 5 V DC voltage source, You can connect 7 - 12 V (battery output) directly to Mega 2560 pin "VIn".
  4. Connect sensor's analog output pins to Mega's analog inputs, using Dupont wires.
  5. Check all the polarities!
  6. Turn power switch off.
  7. Connect battery.
  8. Turn power switch on.
  9. Sensor's green LED must blink 0.1 sec. every second. If so, You are good to go.
Even if You have some other type of hookup, make sure that the sensor and Mega 2560 have common ground (GNDs connected).

Program

Here is a very simple code.


void setup() {
  Serial.begin(115200);
}

void loop() {
  for (int i = 0; i < 9; i++)
    Serial.print(analogRead(i));
  Serial.println();
  delay(100);
}

setup() starts serial interface with PC so that Serial.print() will work.