• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Light a Bulb With Arduino Ultrasonic Sensor HC-SR04

By Abhishek Ghosh November 4, 2015 9:33 am Updated on November 4, 2015

Light a Bulb With Arduino Ultrasonic Sensor HC-SR04

Advertisement

We can Blink a 1.8V Bulb with our previous Arduino Project. Ultrasonic Sensor HC-SR04 is a Cheap Proximity Sensor For Robotics Projects. We can Light a Bulb With Arduino Ultrasonic Sensor Easily by Modification of the Previous Project. This sensor can measure a distance of 2 cm to 4 meters. This is very commonly used sensor for wheeled Robot to avoid the obstacles. Usability of this Arduino Ultrasonic Sensor HC-SR04 is higher and we can use for any other projects.

 

Light a Bulb With Arduino Ultrasonic Sensor HC-SR04 : Buying Guide

 

Perform a Web Search with the phrase Ultrasonic Sensor HC-SR04 and you will get various Adverts from Ebay, Amazon etc. It should not cost more than $1.5. There is no special precaution or guide needed for this stuff. Other needed materials has been in our previous Arduino Project. However, one can Blink only a LED to avoid the need of the other things. In such case, only an Arduino board, the Ultrasonic Sensor HC-SR04 module and some jumpers becoming the need.

 

Light a Bulb With Arduino Ultrasonic Sensor HC-SR04 : Circuit and Coding Part

 

We will code in a way, so that we can improve the project in future. In the Ultrasonic Sensor HC-SR04 module, there are 4 pins :

Advertisement

---

VCC is applied voltage from 4.5 V to 5.5 V
Trig is the Sensor input – trigger.
Echo is the Output Sensor.
GND is Ground or -ve pole.

Circuit is easy, it is modification of the previous bulb blink :

Attach the Ultrasonic Sensor to the breadboard
Connect the GND pins to Bulb’s one pole, one red LED’s -ve and the sensor (GND).
Attach the Bulb to Pin 3 on the Arduino
Attach the Red LED to Pin 2 on the Arduino
Attach the VCC pin on the Ultrasonic Sensor to 5V
Attach the trig pin on the Ultrasonic Sensor to Pin 13 on the Arduino
Attach the echo pin on the Ultrasonic Sensor to Pin 12 on the Arduino

Copy the code written below. There is nothing to see as circuit diagram. We have no Green colored LED but bulb with a different power source. For compatibility reasons, we used bulbLed to indicate Bulb. One can replace the Bulb with a Green LED. This is the approximate circuit :

Light a Bulb With Arduino Ultrasonic Sensor HC-SR04

Desired result :

When something is 5 cm away from the Ultrasonic Sensor HC-SR04 module, the bulb will light, else the red LED will light up.

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const int pingPin = 13;
int inPin = 12;
int bulbZone = 5;
int bulbLed = 3,
redLed = 2;
void setup() {
  Serial.begin(9600);
}
void loop()
{
  long duration, cm;
  pinMode(pingPin, OUTPUT);
  pinMode(bulbLed, OUTPUT);
  pinMode(redLed, OUTPUT);  
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  pinMode(inPin, INPUT);
  duration = pulseIn(inPin, HIGH);
  cm = msCms(duration);
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  if (cm > bulbZone)
  {
    digitalWrite(bulbLed, HIGH);
    digitalWrite(redLed, LOW);
  }
  else
  {
    digitalWrite(redLed, HIGH);
    digitalWrite(bulbLed, LOW);
  }
  delay(100);
}
long msCms(long microseconds)
{
  return microseconds / 29 / 2;
}

Here is the gist on GitHub of the above code.

Tagged With https://thecustomizewindows com/2015/11/light-a-bulb-with-arduino-ultrasonic-sensor-hc-sr04/ , arduino ultrasonic sensor light code , sensor ultrasonico com led arduino , led reactive ultrasonic , arduino hc-sr04 и светодиоды , arduino sr04 with led blinking , arduino ultrasonic code and light , Ультразвуковой датчик на ардуино проекты , arduino ultrasonic lights , arduino ultrasonic sensor hc-sr04
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Light a Bulb With Arduino Ultrasonic Sensor HC-SR04

  • Arduino and LED Bar Display : Circuit Diagram, Code

    Here is a Guide Explaining the Basics, Circuit Diagram, Code on Arduino and LED Bar Display. LED Bar Display is Actually Like Multiple LED.

  • Arduino : Light ON One By One Following Foot Steps on Hallway

    This idea is good for automatic turning on and off multiple lights one by one while a person is walking staircase or walking through a passage or hallway. As IR Obstacle Sensors has physical limits, we can not use if the passage is wide like a road – it will fail for physical reasons. Human […]

  • Mini Christmas Light With Arduino (Very Easy)

    Here is a Mini Christmas Light With Arduino as Project Which Needs 3 Resisters and 3 LEDs, No External Power Supply. It Has 2 Blink Effects.

  • Arduino LDR/Photoresistor and LED Based Light Meter

    Exactly Like Basic Sound Meter With Microphone, We Can Build Arduino LDR/Photoresistor and LED Based Light Meter. Here is circuit & code.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy