UltraSonic Arduino Video instructions How To – Parking your car with an Arduino

How To – Parking your car with an Arduino

Code:

// Back up Helper, by Kevin Darrah v4

#include <SoftwareSerial.h>// to read the data fron the range finder on any digital pin

SoftwareSerial sonar(5, 6); // RX, TX   //we're only using the RX pin (5), so who cares about the TX pin

int huns, tens, ones, distance, returnbyte, sonar_data, i; //blah blah variables

//************CHANGED FROM VIDEO************
unsigned long time_start;//changed to unsigned long (allows to count up to 32bits-1 positive)

void wake_up(){}//  This routine does nothing but is needed by the interrupt to wake the arduino up

void setup(){ //set up stuff

  Serial.begin(9600);// for debugging and viewing distances
  pinMode(2, INPUT);//interrupt pin off of CDS

  // Common Anode RGB LED so writing LOW turns it ON
  pinMode(3, OUTPUT);//GREEN
  pinMode(4, OUTPUT);//RED
  pinMode(6, OUTPUT);//BLUE
  digitalWrite(3, HIGH);//off
  digitalWrite(4, HIGH);//off
  digitalWrite(6, HIGH);//off
  pinMode(7, OUTPUT);//Sonar Activate, goes to power pin of range finder
  digitalWrite(7, HIGH);//turn on range finder
   sonar.begin(9600);//start listening to range finder

}//setup

void go_to_sleep(){// put the arduino to sleep when called
  digitalWrite(7, LOW);//turn off range finder
   sonar.end();// IMPORTANT!  you have to stop the software serial function before sleep, or it won't sleep!

   // attach the interrupt on INT0 or digital pin 2, call wake_up, and do it when the pin falls from 5V to 0V
   attachInterrupt(0, wake_up, FALLING);

   SMCR = B00000101;//Sleep mode control register, Power Down mode and Enable Sleep
   __asm__  __volatile__("sleep");// In line assembler to execute the sleep function
  //once digital pin 2 Falls, from seeing light, the program will resume here after waking up

   SMCR = B00000100;// turn off bit 0 to disable the ability to sleep
   detachInterrupt(0);//turn off the interrupt, so the program doesn't go crazy when awake
   delay(1000);// let everybody get up and running for a sec
    digitalWrite(7, HIGH);//turn on the range finder
    delay(1000);//let it wake up for a sec, it goes through some self calibration stuff before its ready
    sonar.begin(9600);//start listing to the range finder
  for(i=0; i<10; i++){//flash the Blue LED letting us know everybody is ready to go
  digitalWrite(6, LOW);
  delay(50);
  digitalWrite(6, HIGH);
  delay(50);
}

//time stamp the free running timer, so we know how long we are awake for, and go back to sleep after a certain time
time_start= millis();
}//sleep over

For more detail visit: UltraSonic Arduino  Video instructions How To – Parking your car with an Arduino


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top