Can't figure this out...ultrasonic sensor/button


#4

Thank you @chuckmcknight for the help. I was uploading it using a USB and I did get it working.
Just curious, what is IDE? Is that using it when it’s still connected to the computer?
Great tip on the arduino mode as well. That will help a lot as I plan on getting my middle school students trying it out. I look forward to the eBook. Any idea where I’ll be able to find it? I’d say that’s definitely something someone needs to make to help people like myself out.


#5

Hi @cpautler1,

My bad, IDE stands for Integrated Development Environment. This is the mBlock programming environment.

With regard to the eBook, I’ll post a notice when it is available. Likely it will either be on Gumroad or Lulu.


#6

This is a fabulous thread. I have been trying to figure out how to read this ultrasonic sensor for a while. If it wasn’t for me wanting to teach my kids, I would probably go straight to the Adrino. I totally understand where cpautler1 is coming from. The documentation issue starts with the Scratch program itself (base of the Mblock). Basically the MIT students who designed it really only did 80% of the work… developing this graphical face to the software coding, but no documentation.


#7

so I just ran this simple code from chuckmcknight. No luck. I am thinking my sensor may be bad. The power light is on on the back of the sensor. Is there another light on the back of the sensor that changes or flickers when there is something in front of the sensor? Or is there somewhere I can put a meter on the ultrasonic sensor and see a voltage change to check to see if it is actually working? I really wish this thing came with a schematic.


#8

Hi @Dorsa,

Interesting, may I assume that you were running the program through mBlock? If so, did you make sure that the mBot was connected to mBlock via the Connect menu? It should say connected at the top of the window if you are connected. I should also mention that the ultrasonic sensor will occasionally return a zero (0). In that case, you should immediately take another reading. One other thing to check is that the cables are firmly seated (there should be a snap as they seat) and to make sure that your ultrasonic sensor block is set to use the same port that your ultrasonic sensor is connected to.

Hope this helps.


#9

I am a complete beginner and have been trying to get the ultrasonic to work on the Tank starter kit, I have been following many threads with no results, I may not be understanding the dialog. I will give this a go, but have been so frustrated with it I have virtually given up, so fingers crossed
Thanks to all you clever people who help :slightly_smiling:


#10

I am following this thread to help resolve my similar problem.
Your comment regarding switching to Arduino mode, has flagged up “Unsupported block found, remove to continue” the block it’s referring to is the blue “say Dis” block, what will removing it do to the programme?
Thanks
Phil


#11

The say [message] block only works if you are running the program from within the mBlock environment.

There are blocks that are not supported when you use the Orion Program header. mBlock uses a code generator to translate the Scratch blocks into Arduino code that can be compiled and run directly on the robot. You are likely using the say [message] block to see what values are being returned by the ultrasonic sensor by displaying those on the screen.

Also, be aware that the ultrasonic sensor “jitters” and may return a value of zero. Normally, I will immediately re-read the ultrasonic sensor to get a good value to work from and just ignore the zero.

Below is a sample program that should work (I say should because I don’t have an Orion board yet).


#12

That is just what I hoped for and I’m sure it will help a lot of people, judging by other threads.
Thank you so much @chuckmcknight for taking the time to help, really appreciate it :grin:


#13

Fascinating, thanks. I am really looking forward to your eBook. I hope to be using Mbot to teach young children (12-14) and i have to say certain code/sensor/block availability inconsistencies bother me as they make things look more difficult than they should be.


#14

First… I apologize for the slow response. I do not get much time to sit and play with this. And certainly appreciate your help.

Here is a screen shot of what I have for code… exact word for word of your earlier post. Also per your questions…I am connected, checked all the cables, verified seating and port connections… etc. When I run the program, I move my hand in front of the sensor and I see no change in the value. Only zero. (shown in screen shot) I have set up ultrasonic sensors in my past life and they tend to be sensitive. So, I expect the value to bounce around a lot even when facing an open space. I really doubt the board itself has a filter on it. So either my code is bad (which the bottom of the Adrino window (not sure what you call that) looks to be showing information read back from the processor… so I am assuming that is basically working) or my sensor is bad. Not sure…

Now I noticed with your next post you had the individual select the Me Orion board. I do have that board. But once selected, I only saw additional sensors in the list. What does that do for me? I also noticed in that post you used a read ultrasonic sensor command. But when I selected the Me Orion Board, I did not find the read ultrasonic sensor command. Where would that command be found? And when would I use it over a set command?


#15

Dorsa,
Could it be that your problem isn’t the sensory specifically, but rather generally that the mBot is not responding to the computer? Are other mBlock instructions successfully executing? (E.g., the “Run forward” or the “Set LED” blocks?).

I ask because I’ve found, with my mBot, that after I’ve run an Arduino program on the mBot (i.e., an mBlock sketch that starts with the “mBot Program” block, transferred to the mBot via USB in Arduino mode using “upload to Arduino” button), then any mBlock sketch running on the computer (i.e., an mBlock sketch that starts with the “when GreenFlag clicked” block) will only work after I’ve reset things by clicking “Connect/Reset Default Program”. The Default Program seems to contain the code that allows the mBot to communicated with the computer and successfully respond to its commands.
SK


#16

So @Dorsa, what robot do you have?

If it is the mBot, you could use the code I posted before. If it’s an Orion board, you can do the same thing. The key is that a variable named Dis was created on the Data&Blocks palette. If you do that first, it will provide the set block used to set Dis to the reading provided by the ultrasonic sensor [Port] distance block. Looking at your screen shot, that block is under the button pressed block in the Robots palette.

The code should run on the mBot, or any of the Orion board robots (Starter Robot, Ultimate Robotic Kit, etc.). Also, if the light on the ultrasonic sensor is on, then it’s getting power from the board. The questions I have are:

  1. Which port is the ultrasonic sensor plugged into?
  2. Try moving your hand very slowly toward the sensor while in front of it. Does that make a difference?

Of course, it could be a defective sensor, but that would be the last thing I would suspect.

@CoolPink also makes a good point that when you start seeing weirdness, try resetting the default program (I usually upgrade the firmware then reset the default program just to make sure).


#17

CoolPink,

Good thoughts. I have had very basic motion profiles work in Mblock based on time. But I went ahead and reloaded the test code to read the sensor to try out your suggestion. Unfortunately, the Reset Default Program is grey. So, I am unable to test out your thinking. I did find the points on the sensor board to put a meter to for checking sensor response. No change. I wanted to double check what I metered, so I also loaded the sample Adrino program for testing the Ultrasonic Sensor. (I really should have done this in the beginning) The screen shot below of the serial monitor kind of confirms what I am finding. I am getting straight zeros back from the sensor. I should see some bounce/fluctuation in the signal.


#18

Just saw your post.

  1. The sensor is plugged into port 3
  2. Speed of my hand does not make a difference. I also loaded the Adrino test code for the ultrasonic sensor and the serial monitor shows a flat zero coming back with no fluctuation. see screen shot below. I did find the points on the sensor board labeled sig, 5v, and gnd. So I took my meter across the sig and gnd to see if there was any change in the 0-5v. no change.


#19

Dorsa,
If the “Connect/Reset Default Program” is grey, then I think that means you are not succesfully connected through the USB connection from your computer to the robot. Is “Connect/Upgrade Firmware” also grey? Under “Conect/Serial Port” do any options show?
SK


#20

CoolPink,

You are right. I double checked and those items are grey when not connected. But selecting the connect/reset default program does not fix my problem. I did try again. Thank you for your help though. I went ahead and emailed tech support. I am fairly certain that the problem lies with the sensor. Which actually turns out to be a good thing… it forced me to find the test points on the board to check for the signal… so once I get a working sensor, I can show my little ones the 0 to 5 volt swing of the sensor using a multi-meter.


#21

I had the same problem of not being able to get the ovals into the square holes of the operators. I’m on a Mac using Chrome.

The bug is that if your mouse is in the middle of a long oval when you drag it, the “target” box won’t “light up” to accept the drag-and-drop.

However, if you put the mouse cursor most of the way to the left of a long oval, then when the mouse cursor is over the target box, it WILL light up and allow the drag and drop.

The actual “logic” is that the left-hand side of the oval is what has to be over the target. When your mouse cursor is in the middle, you put the mouse over the box and it doesn’t drop. With the mouse cursor at the left, it corresponds with the “hot spot” of the oval, and it seems to work.

In actuality, it doesn’t matter where your mouse cursor is; you just need to drop the far-left side of the oval onto the target box of the operator.

Roger


#23

Thanks, @CoolPink! I thought this would solve my problem on switching from Arduino mode back to mBlock IDE, but it didn’t work. So I just did Connect > Upgrade firmware and that did it. I’m beginning to think that my Ultrasonic sensor is also not working, or is buggy.


#24

Has anyone tried hooking up a waterproof ultrasonic sensor. I’m trying to use my mBot to measure my water tank.

I want to hook this sensor to my mBot.

I think I need to connect it to one of these.
http://learn.makeblock.com/en/me-rj25-adapter/

Any help on this would be greatly appreciated.