Arduino Ultrasonic Range Finder, OLED, Rotary Encoder and Saving Settings to EEPROM

Introduction: Arduino Ultrasonic Range Finder, OLED, Rotary Encoder and Saving Settings to EEPROM

About: Arduino fan!

In this tutorial we will use Arduino MEGA from, OLED Lcd, Ultrasonic range finder module,rotary encoder and Visuino to SET and display ultrasonic range on Lcd and set the limit distance with a red LED. We will be able to save the selected range by clicking on a rotary encoder button. Watch a demonstration video.

Step 1: What You Will Need


The Arduino Mega 2560

Ultrasonic Range Finder

Rotary Encoder

OLED Lcd

Red LED

Breadboard

Jumper wires

Visuino program: Download Visuino

Step 2: The Circuit

Connect GND from Arduino to breadboard pin (gnd)

Connect 5V pin from Arduino to breadboard pin (positive)

  • Connect SCL from Arduino to OLED LCD pin (SCL)
  • Connect SDA from Arduino to OLED LCD pin (SDA)
  • Connect OLED LCD pin (VCC) to breadboard pin (positive)
  • Connect OLED LCD pin (GND) to breadboard pin (GND)
  • Connect Ultrasonic module pin (VCC) to breadboard pin (positive)
  • Connect Ultrasonic module pin (GND) to breadboard pin (GND)
  • Connect Ultrasonic module pin (ECHO) to Arduino pin digital (3)
  • Connect Ultrasonic module pin (TRIG) to Arduino pin digital (2)
  • Connect digital pin (13) from Arduino to LED pin (positive)
  • Connect LED pin (negative) to breadboard pin (GND)
  • Connect rotary encoder pin[+] to breadboard pin (positive)
  • Connect rotary encoder pin[GND] to breadboard pin (GND)
  • Connect rotary encoder pin[CLK] to Arduino digital pin (6)
  • Connect rotary encoder pin[DT] to Arduino digital pin (7)
  • Connect rotary encoder pin[SW] to Arduino digital pin (8)

Step 3: Start Visuino, and Select the Arduino MEGA Board Type

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/.

Please be aware that there are some critical bugs in Arduino IDE 1.6.6. Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work! If you have not done follow the steps in this Instructable to setup the Arduino IDE to program ESP 8266! The Visuino also needs to be installed. Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino Mega" as shown on Picture 2

Step 4: In Visuino Add Components

  • Add "Start" component
  • Add "MultiSource" component
  • Add "Integer To Analog" component
  • Add "Rotary Encoder Sensor" component
  • Add "Integer To Analog" component
  • Add "Ultrasonic Ranger" component
  • Add "Compare Range" component
  1. Under Properties window select "Max", Click on a Pin icon and select "Float SinkPin"
  • Add "Display OLED" I2C component
  1. Double click on a "OLED" component and on the right side select "Text Field", drag it to the left and under properties set size:2 , x:40 , y:40
  2. Select another "Text Field", drag it to the left and under properties set size:2 , x:40 , y:0
  3. Select "Draw Text", drag it to the left and under properties set size:2 ,Text: S-
  4. Select another "Draw Text", drag it to the left and under properties set size:2 ,y:40, Text: D-
  5. Select another "Draw Text", drag it to the left and under properties set size:2 ,x:10, y:20, Text: Saved
  • Add "Button" component
  • Add "Inverter" component
  • Add "Up Down Counter" component
  1. Double click on "Up Down Counter" component and select "set value" on the right, now drag it to the left side

Step 5: In Visuino: ​Connecting Components

  • Connect Arduino Digital pin[8] to Button1 pin [in]
  • Connect Button1 pin[out] to Inverter1 pin [in]
  • Connect Nutton1 pin [Out] to DisplayOled1>Elements draw text3> pin[clock]
  • Connect Arduino Digital pin[7] to RotaryEncoderSensor1 pin [Direction]
  • Connect Arduino Digital pin[6] to RotaryEncoderSensor1 pin [Clock]
  • Connect Arduino Digital pin[3] to UltraSonicRanger pin [Echo]
  • Connect Arduino Serial[0] pin [Out] to DisplayOLED1 pin [In]
  • Connect Arduino Modules Eeprom Elements Integer1 pin[Out123] to UpDownCounter2 pin [123 Value]
  • Connect inverter1 pin[Out] to Arduino Modules Eeprom Elements Integer1 pin [Remember]
  • Connect Start1 pin [Out] to MultiSource1 pin [in]
  • Connect MultiSource1 pin [0] to Arduino Modules Eeprom Elements Integer1 pin [Recall]
  • Connect MultiSource1 pin [1] to UpDownCounter2 pin[in]
  • RotaryEncoderSensor1 pin [up] to UpDownCounter2 pin[up]
  • RotaryEncoderSensor1 pin [down] to UpDownCounter2 pin[down]
  • Connect UpDownCounter2 pin [123 Out] to IntegerToAnalog1 pin [132 In] and OLED1 elements TextField2 pin [132 In]
  • Connect IntegerToAnalog1 pin[out] to CompareRange1 pin[max]
  • Connect UltrasonicRanger1 pin[out] to CompareRange1 pin[in] and DisplayOLED1 text Field1 pin[In]
  • Connect CompareRange1 pin [out] to Arduino Digital pin[13]
  • Connect UltrasonicRanger1 pin [Trigger] DisplayOLED1 pin[refresh] and Arduino digital pin[2]
  • Connect UpDownCounter2 pin [Out132] DisplayOLED1 Elements Text Field2 pin[132 In] and Arduino Serial[0] pin[132in ] and to Arduino Modules Eeprom Elements Integer1 pin [132 In]
  • Connect DisplayOLED1 pin [Out] to Arduino I2C pin [In]

Step 6: Generate, Compile, and Upload the Arduino Code

In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE

In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

Step 7: Play

If you power the Arduino Mega module, the OLED Lcd will start showing the value number for the distance of any obstacle. If you put any obstacle near the ultrasonic module the value will change and the LED will flash.
You can select the range of detection by rotating the encoder, the value should change on the Lcd, if you wish to save this value, just press down the rotary encoder and the value will be saved and loaded the next time you turn On the Arduino.

Congratulations! You have completed your Stepper motor project with Visuino. Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino: https://www.visuino.eu

Be the First to Share

    Recommendations

    • Puzzles Speed Challenge

      Puzzles Speed Challenge
    • "Can't Touch This" Family Contest

      "Can't Touch This" Family Contest
    • CNC Contest 2020

      CNC Contest 2020

    Discussions