Using the Ping))) sensor with an ATmega 328p microcontroller
Hallo I am beginner at embedded c programming. I have ATmega 328p microcontrol that is programmed in C, want to use Ping sensor and I want to blink LED when the objects is 20 cm from the sensor.
Can anyone help me with the code or how to star. I understand how Ping sensor works but i can not write code.
please help
Can anyone help me with the code or how to star. I understand how Ping sensor works but i can not write code.
please help
Comments
const int pingPin = 11; unsigned int duration, inches; void setup() { Serial.begin(9600); } void loop() { pinMode(pingPin, OUTPUT); // Set pin to OUTPUT digitalWrite(pingPin, LOW); // Ensure pin is low delayMicroseconds(2); digitalWrite(pingPin, HIGH); // Start ranging delayMicroseconds(5); // with 5 microsecond burst digitalWrite(pingPin, LOW); // End ranging pinMode(pingPin, INPUT); // Set pin to INPUT duration = pulseIn(pingPin, HIGH); // Read echo pulse inches = duration / 74 / 2; // Convert to inches Serial.println(inches); // Display result delay(200); // Short delay }
I found this http://learn.parallax.com/kickstart/28015 as well. I use these sensors on all of my robots and this code
here is pretty much all you need to get something out of them.
I hope this helps you out.
JT