Champaign-Urbana Community Fab Lab
Champaign-Urbana Community Fab Lab

Arduino I: Intro

For the first week of Arduino project, we were introduced into the essentials of the microcontroller, LED controls, and some of its sensors. With the circuit design experience in the Copper Tape project, most of the materials were not that difficult. Although still relied on Google for figuring out the right resistor. I’ve had some Arduino experience years ago, maybe. The lab session was very handy and helped to bring back those almost lost memories.

Triggering one LED within the loop() was easy. But when asked to add multiple reactions, things got a bit different. Because of the simplicity of Arduino, the program is supposed to be a neverending serial process. At a time, I was trying to have two LEDs blink different patterns. But soon I realized that it might need to have some walkaround. Parallel processing might be possible for Arduino, but that’s still out of my capacity. Might be a good point of discussion in class.

 

For the ideation project, I was thinking about the future of drone deliveries. It would be sweet to know the direction from where they would approach. Maybe not very useful for everyone, but it won’t harm either. And then the notion of a radar system came to my mind–a disk (or other shapes) rotating over and over on a base. Therefore, for the lab’s accessibility, I decided to do a shrunk version based on the availability of materials. Ultrasonic distance sensors on a servo could simulate the most essential form of radar. By periodically rotates the servo, the setup could sense approaching objects with a much wider angle. So in the following week, I’d try this design.

The design has been implemented with UNO x1, servo x1, ultrasonic sensor x2, LED x1, and a resistor. 

The setup was as shown above. The trigger and echo pins from both of the ultrasonic sensors were connected to PWM-capable pins on the board. The code was shown as below. I wrote several functions for this build. The base() function was designed to drive the servo run periodically back and forth. The range was limited to 90-degree because the pin connectors will fight against the servo due to the short arm. This is another shrink from the original sketch. Out of the 360, this ‘radar’ can only scan half of them. So I sliced the two 90-degree sectors into halves–each 45-degree sector represents a geological direction ( North, South, East, and West). This is what the angleToDirection() function was designed for. Then the alarm function was set to be called after each scan, so that if an object is detected within a threshold range,  the alarm (LED) will be triggered. I used both the onboard LED, and another one on the breadboard. Together with single and double blinks, the two LEDs could represent the direction of an approaching object in a very abstract way. Adding to that, I placed a serial output for the alarm message as well. 

As a reflection on this build. The ultrasonic sensors were tricky to deal with. Because it needs to listen for its echo at each step, it is easy to pollute the receiving end with triggers of previous steps. Also, during the test, a delay was necessary each time the servo reverse its rotation direction. Or it tended to generate some irregular signal, could be a false close response, or a far distance. There were a lot of trial and errors in deciding the parameters of the rotation and scanning. But it all worth it.

Tags: , ,