


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















Principle of an active sonar (photo source wikipedia.org)
Using an Ultrasonic Sensor (HC-SR04) with a Tiva C
Series micro-controller and Energia
This guide will provide you with everything needed to connect an Ultrasonic Sensor (HC-SR04) to your Tiva C Series based micro-controller. In essence, this guide will work for most 3.3v based controller’s
such as a 3.3v based Arduino and compatible boards as the Energia development platform is based off of the Arduino IDE.
It is a relatively cheap sensor to measure distance between itself and another object by sending an ultrasonic pulse and listening for an echo response. This sensor can be connected to many devices that provide 5v or 3.3v logic. As I will be using a 3.3v logic micro-controller for this demonstration, a 1K resistor will be required in order to not damage the GPIO on the micro-controller. You can purchase these HC-SR04 Sensor’s from SainSmart, they offer pretty decent prices as well as quick shipping.
There are four pins on the sensor, and they are fairly straight forward to connect. VCC requires a 5v signal, which in my case is coming from the VBUS pin on the Tiva C Series. If you were using the Arduino, you simply connect to the +5v pin. The GND pin goes to any common ground pin’s on your micro-controller, and the pins “TRIG” and “ECHO” will be connected to any available GPIO pins on your micro-controller. Keep in mind, when using a 3.3v logic controller you will be required to use a 1K resistor between the “ECHO” pin and your GPIO pin on the micro-controller as it by default will send 5v and we need to regulate this.
As I am using a Tiva C Series and like the Arduino IDE, I have adapted to using Energia IDE as it brings the Arduino way of coding to the Tiva. As I am new programmer, I have decided to attempt to write my first C++ library for this sensor. You can download this class library from GitHUB here. Installation is very straight forward and there is an example included to get you up and running quickly
Using an FSR
Simple Demonstration of Use
Simple Code for Analog FSR Measurements
1.1. /* FSR simple testing sketch. 1.2. 1.3. Connect one end of FSR to power, the other end to Analog 0. 1.4. Then connect one end of a 10K resistor from Analog 0 to ground 1.5. 1.6. For more information see www.ladyada.net/learn/sensors/fsr.html */ 1.7. 1.8. int fsrPin = 0; // the FSR and 10K pulldown are connected to a 1.9. int fsrReading; // the analog reading from the FSR resistor divider 1.10. 1.11. void setup(void) { 1.12. // We'll send debugging information via the Serial monitor 1.13. Serial.begin(9600); 1.14. } 1.15. 1.16. void loop(void) { 1.17. fsrReading = analogRead(fsrPin); 1.18. 1.19. Serial.print("Analog reading = "); 1.20. Serial.print(fsrReading); // the raw analog reading 1.21.
1.1. /* FSR testing sketch. 1.2. 1.3. Connect one end of FSR to power, the other end to Analog 0. 1.4. Then connect one end of a 10K resistor from Analog 0 to ground 1.5. 1.6. For more information see www.ladyada.net/learn/sensors/fsr.html */ 1.7. 1.8. int fsrPin = 0; // the FSR and 10K pulldown are connected to a
1.43. Serial.println(fsrConductance); 1.44. 1.45. // Use the two FSR guide graphs to approximate the force 1.46. if (fsrConductance <= 1000) { 1.47. fsrForce = fsrConductance / 80; 1.48. Serial.print("Force in Newtons: "); 1.49. Serial.println(fsrForce); 1.50. } else { 1.51. fsrForce = fsrConductance - 1000; 1.52. fsrForce /= 30; 1.53. Serial.print("Force in Newtons: "); 1.54. Serial.println(fsrForce); 1.55. } 1.56. } 1.57. Serial.println("--------------------"); 1.58. delay(1000); 1.59. (^) }
BONUS! Reading FSR Measurements Without Analog Pins.