Page 1 of 1

Arduino Sketches

Posted: Fri Apr 03, 2015 10:12 pm
by SKYLINE1000000
I've been working on a robot using a ping sensor which has 4 pins. Power, Gnd, Trigger and echo.

This small piece of coding I did is to see if my new ping sensor is working but it seems my PC isn't detecting
the board with the ping sensor powered to the 3.3volt pin. I tried increasing the voltage on the main power source but it
didn't ended well with my board...

Code: Select all

int echo = 2; //Pin Number
int ping = 4; //Pin Number
float distCM = 0;

void setup(){
  pinMode(ping, OUTPUT);
  pinMode(echo, INPUT);
  Serial.begin(9600);
}

void loop(){
  digitalWrite(ping, LOW);
  delayMicroseconds(2);
  digitalWrite(ping, HIGH);
  delayMicroseconds(5);
  digitalWrite(ping, LOW);
  
  distCM = pulseIn(echo, HIGH);
  
  Serial.print(distCM);
  delay(5000);
}