Use LEGO Mindstorm RCX Light Sensor With Arduino (Program With Visuino)

by BoianM in Circuits > Arduino

9619 Views, 32 Favorites, 0 Comments

Use LEGO Mindstorm RCX Light Sensor With Arduino (Program With Visuino)

Visuino programmed Arduino: LEGO Mindstorm RCX Light Sensor

In this Instructable you will learn how to program Arduino to control, and get data from LEGO Mindstorm RCX Light Sensor with the help of Visuino - an easy to use graphical development environment for Arduino.

Please note that the annotation on some of the pictures in this Instructable will work correctly on some browsers only after you click on the image to expand it.

Please make sure you click on the image to see the annotation showing the correct spot on the image!

Components

5661fa3b937ddb271700013e.jpeg
  1. One Arduino board (I use Arduino MEGA in this tutorial, just because I have one available, but any other will work)
  2. One LEGO Mindstorm RCX Light Sensor (From an old LEGO set)
  3. 2 or 3 male-male jumper wires

Connect the Light Sensor

5661fa9650e1b6e54b0019c1.jpeg
DSC02085.JPG
DSC02088.JPG
5661fab450e1b6e54b0019c3.jpeg
  1. Connect 2 wires to the 2 metal strips(plates) on the bottom of the electrical connection LEGO block as shown in the (Picture 1)
  2. Connect the single wire from the sensor to the Arduino Ground as shown in (Picture 2)

Arduino UNO:

  1. Connect the second wire to the Arduino Analog 0 pin (On Arduino UNO Analog 0 and Digital 14 are the same pin) (Picture 3)

Arduino MEGA:

  1. If you use Arduino MEGA as in my case, split the second wire into 2 wires. You can use a Female-Female wire as I did or a Breadboard
  2. Connect one of the split wires to the Digital 14 pin as shown in (Picture 2)

  3. Connect the other one to Analog 0 pin (Picture 3)

You can see the Arduino MEGA connected on (Picture 4) . In my case I used a spare LEGO wire so I can experiment easily with different sensors. This is not needed for this project, so you can connect directly to the sensor without the additional wire.

Start Visuino, and Select the Arduino Board

SelectBoard.png
Step2.png

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.5 or one of the nightly 1.6.7 builds, otherwise this Instructable will not work!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuino as shown in the first picture.
  2. Click on the tools button on the Arduino component in Visuino, and when the dialog appears, select your Arduino board type as shown in Picture 2 (In my case I selected Arduino Mega)

Add LEGO RCX Light Sensor Componnt

AddLEGOLightSensorCropped.png
  1. From the toolbar expand the "Measurement" Category, then the "Analog" Sub Category, and select the "LEGO RCX Light Sensor" as shown on the picture
  2. Then drop the component in the design area

Connect the LEGO Component's Charge Digital Pin in Visuino

AddLEGOLightSensorConnectDigital.png

Connect the "Charge" output pin of the Light Sensor component to the "Digital" input pin of the "Digital[14]" of the Arduino component as shown on the picture

Connect the LEGO Component's Sensor Analog Pin in Visuino

AddLEGOLightSensorStartConnectAnalog.png
AddLEGOLightSensorEndConnectAnalog.png

Connect the "Sensor" input pin of the Light sensor (Picture 1) to the "Out" pin of the "AnalogInput[ 0 ]" channel of the Arduino component (Picture 2)

Connect the LEGO Component's Analog Output Pin to the Serial Port in Visuino

AddLEGOLightSensorStartConnectSerial.png
AddLEGOLightSensorEndConnectSerial.png
  1. Connect the "Out" pin of the Light Sensor (Picture 1)
  2. To the "In" pin of the "Serial[ 0 ]" on the Arduino component (Picture 2)

Generate the Arduino Code, Compile and Upload

ArduinoIDE.png
  1. In Visuino press the F9 key. This will generate the Arduino code and start the Arduino IDE
  2. Connect your Arduino board, with the USB cable
  3. Click on the Upload button in the Arduino IDE to compile, and upload the sketch

And Play!

VisuinoConnectToSerialCropped.png
VisuinoSerialTerminal.png
VisuinoSerialScope.png
  1. In Visuino select the Serial port to which the Arduino is connected, then click on the "Connect" button (Picture 1)
  2. You will see the data arriving from the sensor in the Terminal (Picture 2)
  3. You can also switch to the Scope tab to see the data plotted in the Scope (Picture 3)

Add Compare Analog Value Component in Visuino

VisuinoAddCompareCropped.png

Now we will extend it, to turn ON the pin 13 LED of the Arduino board when the sensor is over white surface.

  1. From the toolbar expand the "Math" Category, and select the "Compare Analog Value" as shown on the picture
  2. Then drop the component in the design area

Connect and Configure the Compare Analog Value Component in Visuino

VisuinoConnectSensorToCompare.png
VisuinoConnectCompareToLED.png
VisuinoConnectConfigureCompare.png
  1. Connect the "Out" pin of the Light Sensor to the "In" pin of the Compare Analog Value component (Picture 1)
  2. Connect the "Out" pin of the Compare Analog Value component to the "Digital" pin of the "Digital[ 13 ]" channel (Picture 2)
  3. In the object inspector, set the "CompareType" to ctBigger
  4. In the object inspector, set the "Value" property to between 0.25 to 0.35 ( you may need to experiment to find the best value) (Picture 3)

And Play!

DSC02093.JPG
DSC02097.JPG
  • Move the sensor over black, and while surface.
  • If the sensor is over black surface, the LED on pin 13 will turn off (Picture 1)
  • If the sensor is over white surface, the LED on pin 13 will turn on (Picture 2)

Congratulations! You created your own Arduino program to read data from LEGO Mindstorm RCX Light Sensor in just few minutes!

Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino : https://www.visuino.com