//Please check there info docs for more advanced description #include //This Library is for the HC-SR04 Ultrasonic proximity sensor module......this is not required coz the HC-SR04 is quite easy to handle.........just that is wanted to make it as simple as possible #include //This Library is for wireless rx and tx modules //Left sensor #define vcc1 A0 //As my sensor is attached directly to the arduino dev. board to make it more compact.......so i am using one of the analog pins to power it #define gnd1 A3 //Same story as mentioned above.....just that its for the ground #define trigger1 A1 //trig pin #define echo1 A2 //echo pin //Right sensor #define vcc2 3 //Same as above #define gnd2 6 //Same as above #define trigger2 4 //Same as above #define echo2 5 //Same as above #define maxDist 201 //Maximum distance for the sensors....201 and not 200 coz......if the ping_cm() function is called and it returns 201 or greater...then it converts it into 0 #define led 13 #define transmit 8 NewPing sonar1(trigger1, echo1, maxDist); //Define the left sensor NewPing sonar2(trigger2, echo2, maxDist); //Define the right sensor unsigned long time; void setup() { Serial.begin(9600); pinMode(vcc1,OUTPUT); //VCC of the first hc-sr04 pinMode(gnd1,OUTPUT); //GND of the first hc-sr04 digitalWrite(vcc1,HIGH); digitalWrite(gnd1,LOW); pinMode(vcc2,OUTPUT); //VCC of the second hc-sr04 pinMode(gnd2,OUTPUT); //GND of the second hc-sr04 digitalWrite(vcc2,HIGH); digitalWrite(gnd2,LOW); vw_set_tx_pin(transmit); // Sets the transmit pin 8 vw_setup(2400); //Bits per second or baud....the most important thing to note that.....the baud rate in both RX and TX module....must be similar.....other wise no data transmission pinMode(led,OUTPUT); for(int i=1;i<=64;i++) // Runs 64 times and transmits 64 distance data form each HC-SR04 for every rotation test(); Serial.println(millis()); // Displays the time taken to send 64 data to the Atmega 2 } void loop() // loop() has nothing to do here { } void test() { //usinged and constrain() are used coz......don't really know what pops up when.......just to play safe and restrict the robot from misbehaving unsigned int uS1 = constrain(sonar1.ping_cm(),0,200); //LEFT sensor reading unsigned int uS2 = constrain(sonar2.ping_cm(),0,200); //RIGHT sensor reading byte msg[2]; // byte arreay to store the two values from the sensors......and send it wirelessly msg[0] = byte(uS1); //Left sensor value msg[1] = byte(uS2); //Right sensor value vw_send(msg,2); //Send in the data digitalWrite(led,HIGH); //Signifies that the data is being sent vw_wait_tx(); // Waits until everything is tranmitted digitalWrite(led,LOW); //Signifies completion //delay(17); }