top of page
IMG_20170503_173438.jpg

Post

Electronics Projects for Kids: Learn how to measure distance using Arduino and Ultrasonic Sensor


Arduino LED, Ultrasonic Sensor Circuit
Arduino LED, Ultrasonic Sensor Circuit

Introduction


Howdy ! I hope you are having a great day.

Arduino is an excellent platform and comes in hardy when exploring DIY projects for kids, this teaches you on electronics and programming for kids. Arduino offers simple interface and wide range of sensors with endless possibilities for creative projects. One of the most popular sensors is called Ultrasonic sensor and very much useful for electronics projects for kids.

This sensor measures the distance accurately and we shall be exploring it today, sounds interesting to measure distance using a sensor, right ? Let get started by learning what we need for this basic electronic project for kids.


Requirements


schematic main Components plus Arduino board
schematic main Components plus Arduino board

  • Arduino board

  • Breadboard

  • Jumper wires

  • LED

  • 220 - ohm resistor

  • Ultrasonic Sensor


How it works.


In exploring this DIY for basic project for kids, think of a ultrasonic sensor as a bat that sends out sound waves and listens for their echoes to locate objects. Similarly, the Arduino acts like the bat's brain, processing the information received by the sensor and calculating the distance of the object. Simply when you place an object Infront of the sensor, it measure accurately with reference to sensor location. This theory sounds boring ? I suppose not. And if so, let us get to build actual electronic circuit using Arduino.


Building the circuit


This is simple circuit:

The distance measurement sensor called Ultrasonic sensor, has 4 pins, VCC, TRIG, ECHO and GND. This helps measure the distance using Arduino for basic circuit.


Follow the table below to make the connection:


ULTRASONIC SENSOR

WHERE TO CONNECT TO ARDUINO

VCC

5V

TRIG

Digital pin 8

ECHO

Digital pin 7

GND

GND

After making that connection, take your led and mount it in the breadboard using a 220 ohm resistor. The longer side of led should be passed though Resistor and other side of resistor to Digital pin 3 of Arduino, the short pin of LED is passed to the Ground. If you have done previous projects, this concept has been covered before.


Getting confused ?

Follow the circuit below:


Schematic Arduino board and ultrasound sensor
Schematic Arduino board and ultrasound sensor


Actual Circuit


Arduino, LED Ultrasonic Sensor Actual Circuit
Arduino, LED Ultrasonic Sensor Actual Circuit


Code/Arduino Sketch


// constants won't change
const int TRIG_PIN = 8; // Arduino pin connected to Ultrasonic Sensor's TRIG pin
const int ECHO_PIN = 7; // Arduino pin connected to Ultrasonic Sensor's ECHO pin
const int LED_PIN  = 3; // Arduino pin connected to LED's pin
const int DISTANCE_THRESHOLD = 50; // centimeters

// variables will change:
float duration_us, distance_cm;

void setup() {
  Serial.begin (9600);       // initialize serial port
  pinMode(TRIG_PIN, OUTPUT); // set arduino pin to output mode
  pinMode(ECHO_PIN, INPUT);  // set arduino pin to input mode
  pinMode(LED_PIN, OUTPUT);  // set arduino pin to output mode
}

void loop() {
  // generate 10-microsecond pulse to TRIG pin
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  // measure duration of pulse from ECHO pin
  duration_us = pulseIn(ECHO_PIN, HIGH);
  // calculate the distance
  distance_cm = 0.017 * duration_us;

  if(distance_cm < DISTANCE_THRESHOLD)
    digitalWrite(LED_PIN, HIGH); // turn on LED
  else
    digitalWrite(LED_PIN, LOW);  // turn off LED

  // print the value to Serial Monitor
  Serial.print("distance: ");
  Serial.print(distance_cm);
  Serial.println(" cm");

  delay(500);
}


Video/Demo


Confused on how to run the code ?

Follow the steps below!

  • First make sure your circuit connection is as shown in the schematic provided, and connect your Arduino to the computer using the cable.

  • In tools select the right Arduino you are using, if it is Arduino Uno like my case, select it, and select the right COM Port.

  • Open the Arduino IDE > Copy and paste the code above, in the IDE on top left Verify the code, by pressing the mark like icon, after this upload the code by pressing the next icon from verify, by hovering the cursor it is named upload.

Boom, the code should run as mine !




Need to explore more ?


The best challenge for the project would be adding more resistors to blink when the distance is varied.

First, you need to declare the pin,



int led1 = 4; //  Define a variable name and give it a digital pin
int threshold = 20; // set up another threshold 
// edit this section to control LED with changes in threshold

  if(distance_cm < threshold )
    digitalWrite(led1, HIGH); // turn on LED
  else
    digitalWrite(led1, LOW);  // turn off LED


Other cute things to make and hand-crafts for kids




If you are looking for more tiny crafts and stuff to do with your kids, take a look at these other activities:




Conclusion


Congratulations ! You have successfully built an Arduino Ultrasonic Sensor Circuit with blinking LED distance is shortened, for basic circuit. Like this post, share widely and can follow us in our social media platforms. In case you have any topics you want to suggest, leave a message in comment section.



Newsletter, follow, subscribe, and like the social media


If you like STEM challenges and Science activities, consider following us on Social media for the latest updates, and don't miss any STEM events. Don't forget to also subscribe to our newsletter at the bottom of our website ''www.makersgeneration.net'' for more events, tutorials, and freebies.


Stay tuned for the coming online STEM activities, also in Washington DC, Maryland for your kids. It will go from coding (Python, Scratch, etc) to robotics, 3D design, making video games, and much more. So, subscribe to the newsletter to not miss a piece of it. ;-)


Subscribe to the Facebook group if you have yet registered. Content and tutorials are shared daily: Create and build STEM projects for kids



We can be reached at: contact@makersgeneration.net if any questions.




See you on soon.





Comments


Categories

Recent Posts

Archive

Search By Tags

Follow Us

Comments

Share Your ThoughtsBe the first to write a comment.
bottom of page