Example Code for Arduino-Signal Level Conversion

This project demonstrates how to use the 2-Channel Level Converter to connect a single-channel common anode 3-wire sensor to DFRduino UNO R3 and read the signal level.

Hardware Preparation

Software Preparation

Wiring Diagram

Connection of Single-channel common anode 3-wire sensor to the UNO board.

Sample Code

    int input_pin = 7;
    void setup()
    {
      Serial.begin(9600);
      pinMode(input_pin, INPUT);
    //  pinMode(inpin, INPUT_PULLUP);//Input mode internal pull-up
    }
    void loop()
    {
       int reading = digitalRead (input_pin);
       Serial.println(reading);
       delay(100);
    }

Result

If the signal input is low level 0, open the UNO serial port, then you can see it stably outputs high level 1.

Additional Information

  • When other different voltages and levels are converted, the resistance values in the diagram are different.
  • The module has a low output current and cannot drive modules such as relays or solenoid valves.

Was this article helpful?

TOP