0

Analog output example for ML-R Reflectance Sensor A (mrm-ref-a)

Prerequisites

If not already done so already, install Arduino software and make basic connections, as described in page for MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus (mrm-esp32). This setup is convenient, but it is not mandatory. You can connect some other microcontroller and power supply.

Task

We will read analog output of the sensor in order to determine reflected light's intensity.

Connections

Starting from the basic connection, let's add a ML-R Reflectance Sensor A (mrm-ref-a). 5 V supply can be made using a Dupont cable with 0.1" plugs. If there is only one sensor, You will be able to use Molex KK254 header of the MCU board, like in the right picture. If You have more of them, an adapter will be handy, like ML-R Distribution Pins 3x Passive (mrm-distrib-c). For this sensor we can also use 3.3 V source instead of 5 V. Lower voltage is more appropriate for smaller distance to the surface. You can experiment with different distances and voltages, up to 5 V.

Analog output should be connected to a MCU's pin which supports analog input. We will use ESP32 GPIO pin 36 (blue link in the picture). Output produces a maximum of 3.3 V, even when 5 V power supplied.

Program

Here is the simplest code.

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

void loop() {
  Serial.println(analogRead(36));
}
It reads GPIO 36 and prints its value to console. As ESP32 uses 12-bit ADC, the values are in range 0 - 4095 (212).

We could use any other of the 16 analog pins, as long as no other device uses them, but read the paragraph "Limitations".

The sensor measures reflected light. It will increase if the surface is more reflective or when the sensor is closer. If the distance is roughly equal, it is possible to distinguish between black and white very well. It is also possible to detect a highly reflective surface, as aluminum foil. Be sure that the sensor is not too close for the last task. If it is, white surface will overwhelm the phototransistor and there will be just a very small difference between white and a foil.

Limitations

Some pins are not available or are limited in usage. Check this list.

Alternative connection

Lijevo je primjer spajanja na Arduino Nano u ML-R Arduino Nano Adapter (mrm-nano) pločici. Spojite GND i 5 V, a izlaz iz senzora spojite na bilo koji analogni ulaz mikrokontrolera (A0 na slici). Senzor čitajte analogRead(A0) naredbom.

Napajanje mora biti 5 V jer takav napon zahtijeva infracrveni LED. Znači, ulaz "5V" se mora spojiti na 5 V. Izlaz "OUT 3V3" daje napon od 0 do 3.3 V pa se može spojiti i na 3.3 V (npr. Teensy i STM mikrokontroleri) i na 5 V analogni ulaz. Kad se spoji na 3.3 V, dobiva se puni opseg signala, npr. 0 - 1024 za 10-bitni ADC. Kad se spoji na 5 V, kao što je na slici za Arduino Nano, dobije se 3.3/5 = 66% signala. Znači da će analogRead() za Nano davati vrijednosti 0 do 1024 * 3.3 / 5 = 676.

Ukoliko želite napraviti složeniji FischerTechnik sistem, pogledajte ovaj spoj .