JcOaCrO 0 Posted February 18, 2013 Share Posted February 18, 2013 Hi I have the old board with 2231 and tried connecting the ultrasonic sensor without success. First, here's the code I'm using: void setup() { Serial.begin (); pinMode(P1_5, OUTPUT); pinMode(P1_4, INPUT); } void loop() { int duration; int distance; digitalWrite(P1_5, HIGH); delayMicroseconds(1000); digitalWrite(P1_5, LOW); duration = pulseIn(P1_4, HIGH); distance = (duration/2) / 22; //za cm Serial.print(distance); delay(100); } The sensor vcc and gnd is connected on external 5v supply from the usb on the board. The trigger pin is directly connected to P1_5. The echo pin is connected trough 2 resistors like this GND | | | | | 27Kohm | |--------------------------- P1_4 | | | | | 18Kohm | SENSOR Echo PIn --| So i should probably get around 2.8v output on P1_4 . On the serial console i just get 0. Can someone please suggest whats seems to be wrong with this setup.(the crystal on the board is soldered if it has some importance) Quote Link to post Share on other sites
roadrunner84 466 Posted February 18, 2013 Share Posted February 18, 2013 If you're using the launchpad power, you should probably change the bottom resistor with a 15k version. The launchpad provides 3.6v and accepts vcc-0.7 as its input high. Which would be 2.9; just above your input voltage. Quote Link to post Share on other sites
JcOaCrO 0 Posted February 18, 2013 Author Share Posted February 18, 2013 If you're using the launchpad power, you should probably change the bottom resistor with a 15k version. The launchpad provides 3.6v and accepts vcc-0.7 as its input high. Which would be 2.9; just above your input voltage. Just tried with 15k, no change Quote Link to post Share on other sites
energia 484 Posted February 18, 2013 Share Posted February 18, 2013 Your voltage divider is good. If you have 5 Volt on the HC-SR04 you should end up with 3.2 volt on P1_4 (27/15 divider). Do you have access to a scope or a logic analyzer to look at the signal on P1_4? Quote Link to post Share on other sites
JcOaCrO 0 Posted February 19, 2013 Author Share Posted February 19, 2013 Your voltage divider is good. If you have 5 Volt on the HC-SR04 you should end up with 3.2 volt on P1_4 (27/15 divider). Do you have access to a scope or a logic analyzer to look at the signal on P1_4? No scope. I found fluke graphic multimeter but probably signal is fast to be measured. There's a ttl test with beep on it and when i make the delay between measurements 1 second i get the beep in that interval both on the echo and trig. pin. So i guess it works . I though there's a problem in the software. Also found an arduino example with the same sensor where the 1000 microseconds is replaced with 10. Tried that an still no sucess. When i try to print the duration variable on the console it's also 0 so seems there's no echo signal. Hope it's not a broken module since i would have to wait a whole month for another one Quote Link to post Share on other sites
zoomx 0 Posted February 22, 2013 Share Posted February 22, 2013 I believe that your timing is wrong. Try this digitalWrite(P1_5, LOW); delayMicroseconds(100); digitalWrite(P1_5, HIGH); delayMicroseconds(100); digitalWrite(P1_5, LOW); duration = pulseIn(P1_4, HIGH); distance = (duration/58); //za cm Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.