We have been working on Stupid Pet Trick project recently. When asked to design something simple and yet hilarious, I came up with the idea of making something works opposite to what would people commonly anticipate. I thought of using the red and green LEDs to represent traffic lights, and make a car with the card board. The green LED will always light up when the car is still, and once it moves, the green LED will turn off and the red LED will turn on. In this case, the car can never drive forward since it will break the traffic regulations once it moves. I also wanted to add some effect, designing a “dead zone” where the car should not drive near, or the alarm will ring. I decided to use buzzer as the alarm to generate the effect. Therefore, to build up my circuit, I need a sensor that senses the movement of the item as well as one that senses the distances between items.
I borrowed a 3-Axis Analog Accelerometer and an Ultrasonic Ranger from the equipment room, using them along with green and red LED lights, a buzzer, two 220V resisters, and several wires to build up my circuit. Since I’ve worked with the Ultrasonic Ranger during last recitation, I’m more familiar with how it works and know more about its coding. The problem lies in the 3-Axis Analog Accelerometer. I looked for its tutorials on-line, connecting the outlets to the pins according to the instructions, only to find the demo packages didn’t work on my Arduino. I then consulted Nick, who showed me the built-in example of 3-Axis Analog Accelerometer in Arduino itself. After modifying the circuit and upload the example code, the series monitor started to output three numeric values, which I didn’t understand. Nick told me the 3-Axis Analog Accelerometer always senses the accelerations respectively on x, y, and z directions, and the three values represent what it senses. However, the output values not merely concern with the acceleration on each direction, but also has something to do with the position of the sensor. If you rotate the sensor a little bit, the output values will change too, for the x, y, and z directions have been changed. That proves to be a problem when I worked with the codes, for even if the accelerometer is still, the output values can be different as it rests at different positions. I originally wanted to use an if condition to control the effect of the LEDs according to the output values of the accelerometer, but I found it’s impractical to do so, for the output values are unstable even if it is still. Moreover, as I tried to stick the accelerometer in the car I made with card board, it is barely possible for the car to stand steady without outside force and thus makes it hard for the accelerometer to maintain its still position.
I also met some difficulties when setting the buzzer. As I never used it before, I didn’t learn about its codes. I analogized it with the LED, using “digitalWrite()” function to set it to be “HIGH” when the if condition that confines the distances is satisfied. The code failed to function when the uploading is finished. I searched for tutorials on-line, and found that the codes for the buzzer is different. To make it ring, “tone()” function is needed, and the ringing tone is set by the numeric value put in the parenthesis. To turn it off, simply use the “noTone()” function. With these, I was able to make the buzzer function well.
Except for the trouble mentioned above, constructing of the other parts of the circuits went on quite smoothly. I referred to the codes of the Ultrasonic Ranger I used during last recitation, setting up the sensor and controlling the buzzer. In order to make the Ultrasonic sensor more sensitive, I added a board at the end of the card car. I also set up the red and green LEDs, but when writing the relevant codes, I left out the if condition part which is related to the accelerometer. The picture below is my circuit.
When working on it in class, Professor Sean suggested me to get rid of the 3-Axis Analog Accelerometer, for distances can also be used as a controlled condition for the LEDs, and removing a sensor would greatly simplify my circuit and the codes. I followed his advice and modified my codes, trying to alter the lighting LED when the car moves near the Ultrasonic sensor. Some problems occurred again, for the green LED was always on even if I set it to “LOW”. I commented all the codes about the if condition controlling the LEDs, and found that the two LEDs were still lighted. I realized the problem must lie in either my circuit or the previous codes. I checked my circuit, but it seemed to be correct. With the help of the assisting fellows, I found a part of the codes was missing in setup part. It turned out that I forgot to set the pinMode of the LEDs and the buzzer as OUTPUT. After modifying my codes, the circuit worked successfully. The effect is shown in the following video.
During the exhibition at Friday’s recitation, Professor Antonius gave me a piece of advice. I originally set the scenario to be a car driving on the highway and met a dead zone. The traffic light will turn red and the alarm will be set off if the car drives near to the zone. Professor Antonius suggested me to make it as a rear parking sensor, warning the driver about the distances when he parks the car. I consider this suggestion very useful, and I tried to alter the codes afterwards. I made a small adjustment, making the buzzer ringing continually and the red LED sparkling when the car drives near, and the buzzer ring continuously and the red LED lighting when the car drives even nearer. The following video shows the final effect.
From this project, I learned that sometimes I don’t need too much components to make the circuit works. It’s important and yet a little bit challenge to keep the idea simple while maintaining its creativeness. In addition, it’s essential to try and explore, testing new ideas and trying on new functions. I think my project worked quite well in the end. To improve it, I would move the traffic lights to the other side of the road, so that the driver can see the lights in front of them when parking the car.