loading

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!

Step 1: Components

  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

Step 2: Connect the Light Sensor

  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 secondwire 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.

Step 3: Start Visuino, and Select the Arduino Board

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 Visuinoas 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)

Step 4: Add LEGO RCX Light Sensor Componnt

  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

Step 5: Connect the LEGO Component's Charge Digital Pin in Visuino

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

Step 6: Connect the LEGO Component's Sensor Analog Pin in Visuino

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)

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

  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)

Step 8: Generate the Arduino Code, Compile and Upload

  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

Step 9: And Play!

  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)

Step 10: Add Compare Analog Value Component in Visuino

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

Step 11: Connect and Configure the Compare Analog Value Component in Visuino

  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)

Step 12: And Play!

  • 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

About This Instructable

5,161views

29favorites

License:

More by BoianM:Assemble Kuman Wi-Fi Robot With Camera and Manipulator Arduino and Visuino: Long Distance Remote Light Sensor With RFM95W/RFM98W Makerfabs LoRa Shields  Arduino Nano and Visuino: Animate the Colors of RGB LED 
Add instructable to: