Sensors and libraries

So we’re past the planning phase and have finally acquired the components. Time to start testing them!

WP_20180216_11_20_04_Pro

The end product will most likely use ESP8266, but for testing and development, we use Arduino Uno. It’s faster, and at this stage we don’t need to worry about power consumption.

WP_20180216_11_20_15_Pro

The sensors you can see in this picture are HC-SR04 ultrasonic distance sensor(on the left) and DS18B20 temperature sensor(attached directly to the Arduino). The initial readings seemed fairly accurate, as well.

WP_20180216_11_20_21_Pro

Once we actually measured the distance, though, we got some odd readings. And despite double checking the formula(x=(t*10/2)/vsound where speed of sound = 331.3+0.606*t) the numbers we were getting were still too low! After several measures, we found that multiplying the distance by 1.25 got us numbers that were accurate within a centimeter. The initial calibration was done on a hard floor. The next step was to test on the snow. Unfortunately due the lack of suitable surface to stabilize the arduino(and the attached laptop) on, we were not able to determine whether we were getting accurate numbers. However, a cursory study of the numbers showed that some of them were off the chart! We were getting numbers in excess of 30 meters when the surface was approximately 1 meter away. And the sensor itself is only accurate for up to 5 meters. Hmm. Once the package is finished, it will most likely be standing less than 2 meters from the surface. Therefore, any numbers much higher than that must be erroneous. while(distance>300){measure the distance again}. In retrospect, this really seems like an ugly hack, and I will at least need to add some code to make sure the loop doesn’t keep running indefinitely if something goes wrong, but at least it filters out the noise, so we won’t find our website telling us that there is currently -28 meters of snow out there. That would be embarrassing. However, we still need to calibrate the sensor on snow to see if the results we get are relatively accurate.

WP_20180216_11_20_31_Pro

This picture better shows the layout of our testing setup. As you can see, the thermometer is connected to digital pins 8, 9 and 10, while HC-SR04 has it’s power pin connected to 5V power, ground pin connected to ground, trigpin connected to digital pin 13 and echopin connected to digital pin 12. Most sources on DS18B20 will claim that it requires a pull-up resistor. While that is true, they ignore the fact that Arduino has an internal pull-up resistor that can easily be taken advantage of. Josh Levine has thankfully tested this, and provides a modified OneWire library that makes it easy to use.

That’s it for this week, we are still waiting for our GSM module so we can test our server. If it does not arrive, we will at least have the first drafts of our website to show.

For the sourcecode, see https://github.com/Spodah/virtuaaliluonto-lumivahti/tree/master/arduino

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s