Heart Lamp With Ultrasonic and Sound Sensors

by SabinaStan in Circuits > Arduino

638 Views, 2 Favorites, 0 Comments

Heart Lamp With Ultrasonic and Sound Sensors

IMG_20191204_163630.jpg
IMG_20191205_215824.jpg
IMG_20191208_180544.jpg

My new project is called "Heavy heart" and as a first step, I will make a series of lamps that react to the environment - this one reacts to someone getting close or to sound.

I want to document this project as I develop it.

Here is the prototype circuit and code for this first lamp.

Initially, I wanted to make it with a pir sensor, but I figured it reacts to easily to movement. More than this, the ultrasound gives more options as it could react to movement coming from different sides in a different way, as well as from different distances.

Supplies

  • Arduino Uno
  • Jumper wires
  • Bread board
  • Sensor ultrasonic HC-SR04
  • Voltage regulator LM317
  • Sound Sensor LM393
  • G4 sockets
  • 12V Battery
  • 12V LEDs

Connecting the 12V LEDs

IMG_20191204_164109.jpg
IMG_20191204_164232.jpg
IMG_20191204_164544.jpg
IMG_20191204_164336.jpg
IMG_20191204_164540.jpg
IMG_20191204_164943.jpg

I use three LEDs for this lamp.

Normally, each LED voltage regulator connects to the battery source, but I connected each of them together and only one to the battery source.

  • VIN - battery source
  • IN - Arduino PINs, in my case 5,6,7
  • the two GND connect to the battery and Arduino ground, respectively

On the other side of the voltage regulator are two connection for the LED. My 12V LEDs are not polarity sensitive so it doesn't matter how I connect them.

Connect the Sound Sensor

IMG_20191205_215859.jpg
IMG_20191208_172321.jpg
  • OUT to Arduino PIN, 2 in my case
  • GND - Arduino ground
  • VCC - Arduino 5V

You can adjust the sensitivity of the sensor using the build-in potentiometer.

Connect the Ultrasound Sensor

IMG_20191208_171906.jpg
IMG_20191208_171917.jpg
IMG_20191208_172243.jpg
  • GND - Arduino ground
  • Echo - Arduino PIN, 4 in my case
  • Trig - Arduino PIN, 3 in my case
  • VCC - Arduino 5V

Code

IMG_20191208_173656.jpg
IMG_20191208_173651.jpg
IMG_20191208_173646.jpg
int trigPin = 3;
int echoPin = 4; long duration, distance; int sensor2 = 2; int val1 = 0; int led1 = 5; int led2 =6; int led3 =7; void setup() { pinMode(sensor2, INPUT); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); } void loop(){ digitalWrite(trigPin, HIGH); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; if (distance > 0 && distance <= 100) { digitalWrite (led3,LOW); digitalWrite (led1, HIGH); delay(1000); } else { digitalWrite (led1, LOW); digitalWrite (led3,HIGH); delay(500); } val1 =digitalRead(sensor2); if(val1==0){ digitalWrite (led3, LOW); digitalWrite(led2,HIGH); delay(1000); } else { digitalWrite(led3,HIGH); digitalWrite (led2, LOW); delay(500); } }

One can add different combinations the LEDs may light in depending on the distance detected by the ultrasound sensor

Make sure to select the right board (Arduino Uno), Serial port (ACM0) and Programmer (AVRISP mkll).

Final Result

videotogif_2019.12.08_17.44.34.gif

Enjoy!