Book Image

Arduino for Kids

By : Kuber, Rishi Gaurav Bhatnagar, Varada
Book Image

Arduino for Kids

By: Kuber, Rishi Gaurav Bhatnagar, Varada

Overview of this book

The mission of this book is to integrate technology with the tools that children already use for crafts so that they feel that the technology is an extension of their playtime. We use coding, sensors, and micro-controllers integrated with art and craft supplies, origami, and Playdough. There are 10 fun-filled chapters that talk to children directly, and give clear instructions for non-technical parents too. We use Arduino as the controller of choice due to its easy availability and large community. By the end of the book, children will comfortably be able to set up their Arduino, read and understand code, manipulate code, and ultimately write their own code for projects. They will also be able to use basic sensors and know how components connect to each other. All the learning takes place with lots of colorful pictures and the circuits are neatly presented using wiring.
Table of Contents (11 chapters)

Say hello to my little friend!


Now we have everything we need to know to start building our project. Let's start by writing the code:

#include <NewPing.h> 
  
int ledPin=10; 
int trigPin=8; 
int echoPin=9; 
 
NewPing sonar(trigPin, echoPin); 
  
 
void setup() { 
 
pinMode(ledPin,OUTPUT); 
 
} 
 
void loop() { 
  delay(50); 
  int dist = sonar.ping_cm(); 
  if (dist < 15) 
digitalWrite(ledPin,HIGH); 
    else 
         digitalWrite(ledPin,LOW); 
          
} 

Like before, we start by storing the pin numbers in variables, so that it doesn't become confusing, and then initialize our LED pins for output. The code consists of a simple if statement that checks if an object is closer than 15cm, and if it is, lights up our LED's. If not, it turns our LED's off.

Now that our code is ready, let's build our project!

We begin by cutting out a head shape out of cardboard:

We...