This week I started testing out different sensors to find their ranges.
PIR MOTION SENSOR TEST
I initially thought that I was going to use PIR motion sensor as one of the sensors. I did some testing and was getting very strange and fractured feedback. And the sensor does not seem like the best option for this project. For no motion I was getting a range of 912-914. For Some motion I was getting a range of 284-299. Very rarely would I get a reading in the 100s.
The way the sensor reads the input is a bit much for sensing the proximity of someone to, say, a stuffed dog’s face.
HC- SR04 – ULTRASONIC DISTANCE SENSOR
In the first three tests, I got back varying results of two integers: 1 or 2, 37 or 38, and 7 or 8. I tried a few more times and got some more random readings, with a 1023 popping up every now and then. I was unsuccessful at getting a good read out of this. But perhaps that is because the basic program for ArduinoReadSerial doesn’t apply to this sensor since it has 4 pins. I found this great tutorial that mentions the range is about 0,200 at the max.
I tried reconnecting and reading both the trig and echo and got a reading of 1023 and 987-990.
Two videos that I watched (the one above and this one) had the sensor connected to the digital pins, not the analog pins.
THE (NEW) PLAN:
PHASE I: Tail Wagging
- Use the code to get the distance in centimeters. Map the distance to 0, 1023 which will control the speed of the motor like the potentiometer did in this lab. This will be for the tail wagging.
- Decide on the motor for the tail after testing out the DC motor first.
PHASE II: Eyes
- Develop robotic eyes.
- Figure out a sensor that the eyes can be controlled with (wether it be the same as the tail)
PHASE III: Connect
- Connect and map the tail and eyes to an accelerometer
- Change out Arduino for Arduino Mini
Phase IV: Casing/Prototype
- Put together in some sort of visual order.
- Time willing, Insert the above everything into a stuffed animal prototype
A couple of notes and questions:
Links to the sensors in your posts would be helpful, to make it easier to know what you’re testing. With the PIR sensor, for example, I am confused, as PIR sensors are typically digital sensors, not analog, so I’m not familiar with the one you’re using and how it’s giving an analog reading.
When it comes to readings, it’s helpful to convert the readings to a known physical quantity, At the least, converting to voltage is helpful (see the ReadAnalogVoltage sketch in the File -> Examples -> Basics menu of Arduino). That way, you (and I, reading it) could compare the voltage you’re getting with what the sensor’s data sheet is telling us.
Many times, you can get or derive a formula for the actual physical quantity the sensor is measuring from the data sheet. For example, here’s a nice post on converting the output of an infrared ranger (which is different than a PIR sensor) to a physical distance: https://acroname.com/blog/linearizing-sharp-ranger-data-blog-post.
As to why the Ultrasonic sensor was attached to the digital pins, did you check for a data sheet for it? Here’s one that’s well-written: https://docs.google.com/document/d/1Y-yZnNhMYy7rwhAgyL_pfa39RsB-x2qR4vP8saG73rE/edit Read the Operation section, it’ll explain how the sensor operates and implicitly, why you’d use digital pins
Just because a sensor measures an analog quantity does not mean that it automatically outputs an analog voltage. The ultasonic sensor, for example, sends out an ultrasonic pulse, and when the pulse returns, it changes a second pin from high to low. The distance to the object is proportional to how long the pulse takes to return. So you need to understand the operation of different sensors in order to read the properties they sense.
You might consider a different option: If the sensor detects motion in a close enough range, start the tail wagging. So rather than mapping the tail wag to the sensor distance, do something like this (pseudocode to follow):
if sensor reading > threshold
don’t wag tail
I just went through and added the links to the specific sensors that I had been testing.
I didn’t realize that the PIR sensor was a digital read even though it seems to be delivering information in analog format. I had been looking at that ultrasonic sensor manual but still did not realize that it required only digital and why there were only high and low reads. It seemed to clash with what we learned in class. To be honest, I am still surprised each time physics starts to play a role in all of this. Must learn.