Introduction: Use LEGO Mindstorm RCX Light Sensor With Arduino (Program With Visuino)
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
- One Arduino board (I use Arduino MEGA in this tutorial, just because I have one available, but any other will work)
- One LEGO Mindstorm RCX Light Sensor (From an old LEGO set)
- 2 or 3 male-male jumper wires
Step 2: Connect the Light Sensor
- Connect 2 wires to the 2 metal strips(plates) on the bottom of the electrical connection LEGO block as shown in the (Picture 1)
- Connect the single wire from the sensor to the Arduino Ground as shown in (Picture 2)
- Connect the second wire to the Arduino Analog 0 pin (On Arduino UNO Analog 0 and Digital 14 are the same pin) (Picture 3)
- 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
Connect one of the split wires to the Digital 14 pin as shown in (Picture 2)
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!
Step 4: Add LEGO RCX Light Sensor Componnt
- From the toolbar expand the "Measurement" Category, then the "Analog" Sub Category, and select the "LEGO RCX Light Sensor" as shown on the picture
- 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" 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
- Connect the "Out" pin of the Light Sensor (Picture 1)
- To the "In" pin of the "Serial[ 0 ]" on the Arduino component (Picture 2)
Step 8: Generate the Arduino Code, Compile and Upload
- In Visuino press the F9 key. This will generate the Arduino code and start the Arduino IDE
- Connect your Arduino board, with the USB cable
- Click on the Upload button in the Arduino IDE to compile, and upload the sketch
Step 9: And Play!
- In Visuino select the Serial port to which the Arduino is connected, then click on the "Connect" button (Picture 1)
- You will see the data arriving from the sensor in the Terminal (Picture 2)
- 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.
- From the toolbar expand the "Math" Category, and select the "Compare Analog Value" as shown on the picture
- Then drop the component in the design area
Step 11: Connect and Configure the Compare Analog Value Component in Visuino
- Connect the "Out" pin of the Light Sensor to the "In" pin of the Compare Analog Value component (Picture 1)
- Connect the "Out" pin of the Compare Analog Value component to the "Digital" pin of the "Digital[ 13 ]" channel (Picture 2)
- In the object inspector, set the "CompareType" to ctBigger
- 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!
We have a be nice policy.
Please be positive and constructive.