Problem Reading UltrasonicSensor

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Problem Reading UltrasonicSensor

Postby brian3f » Mon Jun 25, 2007 8:10 am

I'm new to using the Lejos NXJ software but have had some initial success. I'm stuck right now trying to get the UltrasonicSensor working. I'm unable to get readings off the sensor. I wrote a test program and no matter what the sensor is pointing at it reads 255. Below is my code:

Code: Select all
import lejos.nxt.*;

public class HelloWorld
  static UltrasonicSensor us = new UltrasonicSensor(SensorPort.S4);
  public static void main (String[] aArg)
  throws Exception
     for (int i = 0; i < 100; i++) {
        LCD.drawString("count: " + new Integer(

I'm using the win32 leJOS NXJ version 0.2.0 software.

Any help would be greatly appreciated,

Brian Fisher
New User
Posts: 1
Joined: Mon Jun 25, 2007 8:01 am

Postby andren » Wed Jun 27, 2007 2:03 pm

You can only connect the UltrasonicSensor to port S1
New User
Posts: 2
Joined: Wed Jun 27, 2007 1:58 pm

Postby lawrie » Wed Jun 27, 2007 9:59 pm

I2C sensors including the Ultrasonic sensor currently work on ports S1, S2 and S3, but not S4.
leJOS Team Member
Posts: 934
Joined: Mon Feb 05, 2007 1:27 pm

Return to NXJ Software

Who is online

Users browsing this forum: Majestic-12 [Bot], Yahoo [Bot] and 1 guest

more stuff