Robotics Note
Robotics Note
you can see a photo of an Arduino Uno board and its most important parts. I’ll explain them one by one.
Let’s start with the USB connector. To connect an Arduino to your computer, you just need an USB cable. Then
you can use the USB connection for various purposes:
• Upload new software to the board.
• Communicate with the Arduino board and your computer.
• Supply the Arduino board with power.
To supply power to the Arduino, the USB port only delivers 5 volts, and sometimes you need more therefore,
in these situations, the best solution usually is an AC adapter supplying 9 volts (the recommended range is
7V to 12V). you can also power the Arduino with 9V batteries.
Now you know two ways to supply the Arduino with power. But the Arduino isn’t greedy and happily shares
its power with other devices. At the bottom of Figure 1.2, on the preceding page, you can see several sockets
(sometimes I’ll also call them pins, because internally they are connected to pins in the microcontroller) related
to power supply:
• Using the pins labeled 3.3V and 5V, you can power external devices connected to the Arduino with
3.3 volts or 5 volts.
• Two ground pins labeled Gnd allow your external devices to share a common ground with the Arduino.
• Some projects need to be portable, so they’ll use a portable power supply such as batteries. You
connect an external power source such as a battery pack to the Vin and Gnd sockets. If you connect
an AC adapter to the Arduino’s power jack, you can supply the adapter’s voltage through this pin.
On the lower right of the board, you see six analog input pins named A0–A5. You can use them to
connect analog sensors to the Arduino. They take sensor data and convert it into a number between
0 and 1023.
At the board’s top are 14 digital IO pins named D0–D13. Depending on your needs, you can use
these pins for both digital input and output, so you can read the state of a pushbutton or switch to
turn on and off an LED.
PROJECTSS
THE BUILD
1. Insert your photoresistor into the breadboard. Connect one leg to the +5V rail using a jumper wire.
Connect a 10k-ohm resistor to the other leg, and connect the other side of this resistor to Arduino A0
and GND on the breadboard.
PHOTORESISTOR ARDUINO
Leg 1 +5V
Leg 2 A0 via 10k-ohm resistor and GND
2. Connect the red (positive) wire of the piezo buzzer directly to Arduino pin 11 on the Arduino and
the black (GND) wire to GND on the breadboard.
PIEZO ARDUINO
Black wire GND
Red wire Pin 11
3. Insert the green LED’s long leg into Arduino pin 13 and the short leg into GND.
4. Connect the power rails to the breadboard.
5. Before you upload the code, you need to check the photoresistor’s value in ambient light. Run the
following small program with the photoresistor set up as instructed.
THE CONNECTION
The sketch first sets Arduino pin 11 as an OUTPUT for the piezo buzzer and pin 13 as an OUTPUT
for the LED. The photoresistor is connected to Arduino pin A0. If the analog reading from A0 is more
than 850 (meaning that there is less light and the laser beam has been broken), the buzzer will be
set to HIGH and turn on and the LED will turn off. Remember to change the resistance value
depending on your calibration on this line: As noted earlier, when the laser is shining on the resistor
it reads about 620, so in the sketch I’ve set the buzzer to sound only if the value is more than 850.
This value is between our laser value and our non-laser value, so we know the laser beam to the
resistor has been broken if the value reaches 850.
THE CODE
3. Motion Sensor Alarm
PARTS REQUIRED
• Arduino board • Breadboard • HC SR501 PIR sensor • LED • Piezo buzzer
How It Works
This project is based on the HC SR501 PIR sensor, which is widely available online for a few dollars. We’re
going to set it up so that when someone passes in front of the PIR sensor, the LED will light up and the
piezo buzzer will sound, but you can adapt it for various other output.
The Build
1. Connect the PIR sensor’s +5V and GND wires to the +5V and GND rails on the breadboard, and
connect these rails to the Arduino. Connect the PIR sensor’s output wire to Arduino pin 2.
LED ARDUINO
Positive leg Pin 13
Negative leg GND
3. Connect the piezo buzzer by attaching the red wire to Arduino pin 10 and the black wire to GND.
LED ARDUINO
Red wire Pin 10
Black wire GND
4. Confirm that your setup matches the circuit diagram, and then upload the code in “The Sketch” on.
The Sketch
The sketch works by setting Arduino pin 13 as output for the LED, pin 2 as input for the PIR sensor,
and pin 10 as output for the piezo buzzer. When the PIR sensor is triggered, a HIGH signal is sent
to the Arduino, which will in turn light the LED and play a tone on the piezo buzzer.
THE CODE
4. SMART GATE
Parts Required
• Arduino board • Breadboard • Jumper wires • 38 kHz IR receiver • Remote control • 2 Tower Pro SG90
9g servomotors • Pan-and-tilt housing module
• For older versions of Arduino, you’ll need to unzip the library file and then put the whole folder
and its contents into the sketchbook/ libraries folder on Linux, My Documents\Arduino\Libraries
on Windows, or Documents/Arduino/libraries on OS X. To install a library manually, go to the
ZIP file containing the library and uncompress it. For example, if you were installing a library
called keypad in a compressed file called keypad.zip, you would uncompress keypad.zip,
which would expand into a folder called keypad, which in turn contains files like keypad.cpp
and keypad.h. Once the ZIP file was expanded, you would drag the keypad folder into the
libraries folder on your operating system: sketchbook/ libraries in Linux, My Documents\
Arduino\Libraries on Windows, and Documents/Arduino/libraries on OS X. Then restart the
Arduino application. Libraries are listed at the start of a sketch and are easily identified
because they begin with the command #include. Libraries are surrounded by angle brackets,
<>, and end with .h
• The sketch first calls on the IRremote library, which reads from the IR receiver and sends the
corresponding data to the Arduino. The IR receiver is assigned to pin 11 on the Arduino, and
the sketch begins communicating with the Arduino IDE so that when a button is pressed the input
is displayed in the Serial Monitor in real time. The sketch continues in a loop, looking for button
presses, and shows the corresponding value to the IDE.
4. Open the Serial Monitor in your IDE.
5. Point your remote toward the receiver and try pressing different buttons. They will appear in the Serial
Monitor decoded into letters and numbers in a format known as hexadecimal (HEX), Try short, sharp presses
to get the best results. If you press a button for too long, the Serial Monitor will show Fs for as long as you
hold the button. Write down the numbers that appear and the buttons they correspond to. You will need
these numbers later. Now that we’ve decoded the button signals from the remote control, we can use them
to control two servos.
The Build
1. Using your breadboard setup, with the receiver already connected, attach your servos to the Arduino
by connecting the brown wire on each to GND, and the red wire to +5V. Then, connect the yellow
control wire for the first servo to Arduino pin 10, and the yellow control wire for the second servo to
Arduino pin 9.
SERVOS ARDUINO
RED WIRES +5V
BROWN WIRES GND
YELLOW WIRE (SERVO 1) PIN 10
YELLOW WIRE (SERVO 2) PIN 9
2. Remember to attach power to your breadboard.
The Sketch
Make sure you use the values that you decoded in step 3 of “The Setup” on page 96 in place of the
values included here when completing the sketch. When you’re changing the value in the sketch to match
your own codes, keep the 0x and add your HEX code after it. For example, for the first button I
decoded, the HEX code is FFA05F, which looks like this in the sketch:
5. AUTOMATIC ALARM SYSTEM
Parts Required
• Arduino uno board • Breadboard • Jumper wires • 5V relay module • Real Time Clock (RTC) • LED• Resistor
• Buzzer.
HOW IT WORKS
This project is meant to replace the process of having a human to monitor time and ring the bell at
some specific time. Hence, the time will be monitored by the Arduino and also sound the alarm when
needed.
The Build
1. Connect the 5v of the Arduino to the positive rail of the breadboard and the GND of the
Arduino to the negative rail of the bread board.
2. Connect the clock module as follows:
CLOCK MODULE ARDUINO
VCC +5V
GND GND
CLK PIN 6
DAT PIN 9
RST PIN 8
4. Connect the positive side of the led to the 220-ohm resistor on a rail on the breadboard also take
a jumper wire and connect the positive side which is connected with the resistor to pin 10 in the
Arduino.
5. Connect the buzzer to the relay or any other alarm like the school bell as you will see in the
schematic.
THE CODE
6. ULTRA SONIC INTRUDER ALARM SENSOR.
Parts Required • Arduino board • Breadboard • Jumper wires • Four-pin HC-SR04 ultrasonic sensor •
Servomotor • Red LED • Green LED • 2 220-ohm resistors.
How It Works
This project is versatile and can be used and adapted in various ways. Because the ultrasonic sensor can
define distance, you could, for example, use it to define an area and trigger an alarm when that perimeter
is breached. The sensor works similarly to a radar: it sends out an ultrasonic signal, or ping. When this signal
hits an object, it bounces back like an echo, and the time between the ping and the echo is used to calculate
distance. The Arduino can use this calculation to trigger an event, depending on the value received. In this
project, when the sensor detects an intruder within a predefined vicinity, the red LED will light and the servo
arm will move. You can adapt this project to trigger a different event when the intruder is detected, like
pressing a security system button or locking a door. For a friendlier scenario, you could set the distance really
close so that when you wave your hand in front of the sensor, the servo presses a button to release a treat,
like candy.
The Build
1. Insert the ultrasonic sensor into the breadboard. The sensor we’re using in this project has four pins.
Connect the sensor’s GND to the Arduino GND rail, VCC to Arduino +5V, Trig to Arduino pin 12,
and Echo to Arduino pin 13
SERVO ARDUINO
RED WIRE +5V
BROWN WIRE GND
YELLOW WIRE PIN 9
3. Insert the red and green LEDs into the breadboard with the shorter, negative legs in the Arduino GND
rail. Add a 220-ohm resistor to each of the positive legs, and connect the red LED to Arduino pin 2
and the green LED to pin 3 via the resistors.
LEDS ARDUINO
NEGATIVE LEADS GND
POSITIVE LEAD 1 PIN 2 VIA 220-OHM RESISTOR
POSITIVE LEAD 2 PIN 3 VIA 220-OHM RESISTOR
4. Connect the power rails on the breadboard to Arduino +5V and GND.
THE CODE