• 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 , arduino hc-sr04 и светодиоды , ультразвуковой датчик hs-sr04 ардуино пример схемы на arduino uno , arduino sr04 with led blinking , arduino ultrasonic code and light , arduino ultrasonic led light , arduino ultrasonic lights , arduino ultrasonic sensor hc-sr04

This Article Has Been Shared 953 Times!

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

  • What is a Micropump?

    For many reasons we need miniature things for special works, like bigger pumps there are Micropumps. This article tells what is a Micropump.

  • Breadboard & Breadboarding Basics : Before Arduino

    Arduino Possibly a Very Good Approach But Unless the Basics Like Breadboard & Breadboarding is Known, All Will Suck Money For Simple Stuffs.

  • Buying Arduino Original Versus Arduino Clones

    Arduino Clone in this article means Arduino Compatible. Buying Arduino original versus Arduino clone has difference from many less known aspects.

  • Taking Out Hard Disk Motor For DIY Project

    Here is What Exactly You Will Do For Taking Out Hard Disk Motor For DIY Project. Probably You Need Just a Torx Screwdriver For Clean Work.

  • Servo Motor Arduino Code : Basic

    Here is Basic Servo Motor Arduino Code to Test Newly Purchased Servo Motor or Perform Some Basic Action. We Can Fine Tune Degrees of Sweep.

Additionally, 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 (22.1K 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

  • Why You Need A Big Data Consultant May 15, 2022
  • The Connection Between AI And Online Slots May 13, 2022
  • How To Choose Your Niche As An Instagram Influencer May 12, 2022
  • How to Choose a Powerful Domain Name for Your New Venture May 12, 2022
  • How To Leverage Big Data In Social Media May 11, 2022

About This Article

Cite this article as: Abhishek Ghosh, "Light a Bulb With Arduino Ultrasonic Sensor HC-SR04," in The Customize Windows, November 4, 2015, May 16, 2022, https://thecustomizewindows.com/2015/11/light-a-bulb-with-arduino-ultrasonic-sensor-hc-sr04/.

Source:The Customize Windows, JiMA.in

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Privacy Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

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

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