makeitelectronic244
Published © GPL3+

Ultrasonic light

This is a ultrasonic motion light! WARNING THIS PROJECT NEEDS 120 VOLTS WILL NOT BE RESPONSIBLE FOR ANY HARM THAT MAY COME TO YOU!!

IntermediateFull instructions provided471
Ultrasonic light

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Relay (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LED Light Bulb, Frosted GLS
LED Light Bulb, Frosted GLS
×1

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Schematics

Wiring

Arduino setup

Code

arduino motion light

Arduino
its a motion activated light
/*
HC-SR05 pin   Arduino pin   Relay Board     Light      Plug
  vcc           5V             X            x          x
  Trig         pin 9           X            x          x
  Echo         pin 8           X            x          x
  Gnd          Gnd             Gnd          x          x
   X           pin 12         signal pin    x          x
   X           Vin            +V            x          x
   x           x               NO           com        x
   x           x               x            Gnd        Gnd
   x           x              Com           x          Com         
*/
int s;
int state=0; 
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
   pinMode(8, INPUT);
   pinMode(9, OUTPUT);
   pinMode(12, OUTPUT);  
   digitalWrite(9, LOW);
   digitalWrite(8, LOW);
}

void loop() {
  
  long duration, inches, cm;

  

    digitalWrite(9, HIGH);
    delayMicroseconds(5);
    digitalWrite(9, LOW);
    delayMicroseconds(5);
 
 
  duration = pulseIn(8, HIGH);

  
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);

  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();

 
  if(inches<12){  //   change number too increase/decrease sensor range
 digitalWrite(12, HIGH);
    delay(10000);//change number for how long kight stays on mil sec
    }else{
    digitalWrite(12, LOW);//change number too change off state distance
      }

   delay(100);
}

long microsecondsToInches(long microseconds) {
 
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {
 
  return microseconds / 29 / 2;
}

Credits

makeitelectronic244
0 projects • 0 followers

Comments