Wi-Fi
is an essential bit of kit for any Internet of Things (IoT) DIY projects, but
our favorite Arduino doesn’t come with Wi-Fi, and adding in a Wi-Fi shield can
increase the costs substantially.
Meet
the Arduino Killer: ESP8266 (also known as NodeMCU) was originally marketed as
a low cost Wi-Fi add-on for Arduino boards, until the hacker community realized
you could cut the Arduino out of the equation entirely.
In
less than a year, the ESP8266 has rocketed in popularity, and is now so well
supported and developed that if you’re currently using Arduino, you need to
stand up and take note.
There’s
quite a few models of ESP8266 around now, but we recommend this one: ESP-12E
(also known as NodeMCU 2.0). This board includes the serial driver needed to
program the chip, and has a built-in power regulator, as well as lots of IO
pins.This NodeMCU Devkit is available from our eBay Store.
Getting Started
with ESP8266-12E:
Using Micro usb to standard usb cable Connect ESP8266-12E
to your PC. we are using windows 7.
Please wait and allow the windows to install the USB driver as shown
below.
NodeMCU is connected to COM5 . This can also be verified
from Device Manager.
Method 1: Arduino IDE
This is the easier of the two methods requiring only Arduino IDE
Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
Open Boards Manager from Tools > Board menu and install esp8266 platform
Selecting the NodeMCU baord from Tools Menu
Restart Arduino IDE and select blink Example for ESP8266 and upload.
Results:
Method 2: Flashing the Firmware:
This Method Involves flashing the firmware and then uploading the lua code via ESPlorer.
download the latest firmware from the following link
connect to NodeMCU by pressing the Open button on the top of
right panel.
After successful connection
some message and a prompt is displayed.
Now we are ready to upload our first program
"Blink.lua" to NodeMCU. Press [Save to ESP] button to upload, the red
led on ESP will start flashing with 1 sec interval. Please note 1,000,000 us = 1 sec.
"Blink.lua" code:
while
1 do
gpio.write(0,gpio.HIGH)
tmr.delay(1000000)
gpio.write(0,gpio.LOW)
tmr.delay(1000000)
end
Results:
WIFI Scanner:
Setup:
OLED -> NodeMcu
-SDA -> D5
-SCL -> D6
-VCC -> 3.3V
-GND -> GND
Code:
wifi.setmode(wifi.STATION) --Set mode to STATION so he chip can receive the SSID broadcast
function init_OLED(sda,scl) --Set up the u8glib lib
sla = 0x3c
i2c.setup(0, sda, scl, i2c.SLOW)
disp = u8g.ssd1306_128x64_i2c(sla)
disp:setFont(u8g.font_6x10)
disp:setFontRefHeightExtendedText()
disp:setDefaultForegroundColor()
disp:setFontPosTop()
end
init_OLED(5,6) --Run setting up
tmr.alarm(0,3000,1,function() --A timer, which used to run the following program
wifi.sta.getap(function(t)
disp:firstPage()
repeat
lines = 0
for k,v in pairs(t) do
disp:drawStr(0,lines * 11,k.." "..v:sub(3,5).."dbi") --Print the data out
lines = lines + 1
end
until disp:nextPage() == false
end)
end)
OLED (Organic Light-Emitting Diode) is a self
light-emitting technology composed of a thin, multi-layered organic film placed
between an anode and cathode. In contrast to LCD technology, OLED does not
require a backlight. OLED possesses high application potential for virtually
all types of displays and is regarded as the ultimate technology for the next
generation of flat-panel displays. Blue and White Character OLEDs are available from our eBay Store.
Features:
It's a 0.96" 128X64 OLED, I2C (or IIC) interface, with
SSD1306 driver, 3.3/5V compatible.
1. A simplified manufacturing
process compared to TFT-LCD
2. Self-emitting light, in
contrast to the required backlight for TFT-LCD
3. High luminosity
4. Lightweight and thin (less
than 2 mm)
5. Capable of wide viewing
angles>160
6. Low operating voltage and
power consumption
7. Quick response (< second
level)
8. Wide range of operating
temperatures (-30c to 70c)
Specifications:
High resolution:
128 * 64
Viewing
angle:> 160 degree
Supports many
control chip: Fully compatible with Arduino, 51 Series, MSP430 Series, STM32 /
2, CSR IC, etc.
Ultra-low power
consumption: full screen lit 0.08W
Voltage: 3V ~ 5V
DC
Working
Temperature: -30 c ~ 70 c
Module Size:
27.0MM * 27.0MM * 4.1MM
I2C/IIC
Interface, need 2 IO only.
Driver IC:
SSD1306
Character Colour:
White
Hardware Setup:
There are 4 pin on the OLED
module, GND, VCC, SCL and SDA. Connect the oled module to your Breadboard. Get
four male to male dupont jumper wires and Connect to Arduino as shown in the
following image and table:
OLED -> Arduino
-SDA -> A4
-SCL -> A5
-VCC -> 3.3V
-GND -> GND
Software Setup:
u8glib (Universal Graphics Library for 8 Bit Embedded
Systems) is a graphics library with
support for many different displays.
To install u8glib go to manage libraries in Arduino IDE
menu:
and from the list of available libraries install u8glib by
oliver library.
find and load the HelloWorld example in the library.
In the HelloWorld, only un-comment the following constructor
to make it work:
Like the more common version of I2C 1602 LCD, this LCD also
has blue backlight. It has 4 rows of 20 characters. With this I2C interface LCD
module, you will be able to realize data display via only 2 wires. If you
already has I2C devices in your project, this LCD module actually cost no more
resources at all. It is fantastic for Arduino based project. This LCD is available from our eBay Store.
Features
·Interface: I2C
·I2C
Address: 0x27 or 0x3F
·Pin
Definition : GND,VCC,SDA,SCL
·Back lit
(Blue with White char color)
·Supply
voltage: 5V
·Pcb Size
: 60mm×99mm
·Contrast
Adjust : Potentiometer
·Backlight
Adjust : Jumper
I2C ADDRESS:
There are a few versions of
2004 Lcd available with different I2c address e.g. 0x20, 0x27, 0x3F.
If not sure , I2C address can be verified by running I2C scanner
sketch from the Arduino playground.
For our LCD the address was verified as 0x27.
Hardware Setup:
Get four male to female dupont jumper wiresand connect the LCD module to your Arduino as shown in the following
image and table. Then connect your Arduino to the computer via USB:
Software Setup
The next step is to download
and install the Arduino I2C LCD library for use with the backpack. First of
all, rename the “LiquidCrystal” library folder in your Arduino libraries
folder. We do this just to keep it as a backup.
If you’re not sure where your
library folder can be found – it’s usually in your sketchbook folder, whose
location can usually be found in the Arduino IDE preferences menu:
Next, visit https://bitbucket.org/fmalpartida/new-liquidcrysta…and download the latest
file, currently we’re using v1.3.4. Expanding the downloaded .zip file will
reveal a new “LiquidCrystal” folder – copy this into your Arduino libraries
folder.
Now restart the Arduino IDE if
it was already running – or open it now. To test the module we have a
demonstration sketch prepared, simply copy and upload the following sketch:
After a few moments the
LCD will be initialized and start to display "Hello world", – for
example:
If the text isn’t clear, or you just see white blocks –
try adjusting the contrast using the potentiometer on the back of the module.You can
permanently turn off the backlight by removing the physical jumper on the back
of the module.
4 x Geared motors + 4 x Tyres/wheels + 4 x Motor fixings
4 x black + 4 x red motor cables.
2 x transparent acrylic glass plate 250 x 160 x 3mm
1 x L298N motor driver
1 x Arduino UNO328 controller board (CH340 usb driver installation needed.)
1 x HC-06 Bluetooth module
1 x Mini breadboard
2 x Battery holder (6V , 4 x AA / batteries not included)
1 x Battery holder (9V , batteries not included)
4 x motor speed encoding disks (Use with IR optocoupler sensors which are not included)
30 x 20 cm Dupont jumpers cable, 10 each(M-M,M-F,F-F)
1 x USB cable for arduino
6 x Copper pillar ( 30 mm ), 1 x Screws kit
Some Extras: on/off toggle mini switch, extra screws and nuts, dc jack for Arduino battery, tie cables etc
2. Connect the motors
Connect the motors and wheels as shown in the figure 1. Solder the red and black wires as shown. These correspond to the positive and negative of the motors/battery terminals. If you connect the red and black to the +ve and -ve of the battery , all the motors/ wheels should spin in the same direction. If any wheel spins in a different direction swap the wires on the motor terminals to correct the spin.
Figure 1: Connecting wheels and motors
2. Connect L298n motor board
Connect the red and black wires from two right side motors to +/-ve terminal on L298n board which are numbered 1/2 respectively.
Figure 2: L298N motor driver pin outs
Similarly Connect the red and black wires from two left side motors to +/-ve terminal on L298n board which are numbered 13/14 respectively.
Figure 3 Connecting red and black wires to L298n driver.
4. Connect L298n motor control pins to Arduino
Attach top plate and screw Arduino to it. Next, connect your power supply - the positive to pin 4 on the module and negative/GND to pin 5. If you supply is up to 12V you can leave in the 12V jumper (point 3 in the image above) and 5V will be available from pin 6 on the module. This can be fed to your Arduino's 5V pin to power it from the motors' power supply. Don't forget to connect Arduino GND to pin 5 on the module as well to complete the circuit.
Now you will need six digital output pins on your Arduino, two of which need to be PWM (pulse-width modulation) pins. PWM pins are denoted by the tilde ("~") next to the pin number, as shown in Fig 4:
Figure 4 Arduino Pinouts
Finally, connect the Arduino digital output pins to the driver module. In our example we have two DC motors, so digital pins D9, D8, D7 and D6 will be connected to pins IN1, IN2, IN3 and IN4 respectively. Then connect D10 to module pin 7 (remove the jumper first) and D5 to module pin 12 (again, remove the jumper).
L298n
Arduino
7
D10
IN1(8)
D9
IN2(9)
D8
IN3(10)
D7
IN4(11)
D6
12
D5
Table 1 Arduino connections to L298N
The motor direction is controlled by sending a HIGH or LOW signal to the drive for each motor (or channel). For example for motor one, a HIGH to IN1 and a LOW to IN2 will cause it to turn in one direction, and a LOW and HIGH will cause it to turn in the other direction.
However the motors will not turn until a HIGH is set to the enable pin (7 for motor one, 12 for motor two). And they can be turned off with a LOW to the same pin(s). However if you need to control the speed of the motors, the PWM signal from the digital pin connected to the enable pin can take care of it. The range of speed possible of your hardware, set the PWM values between zero to 255.
Figure 5 Connect to Arduino
5. Connect bluetooth hc-06 module to Arduino
Table 2 and Fig show how you should connect the Bluetooth module to your Arduino.
HC-06
Arduino
VCC
3.3v
GND
GND
TXD
RXD
RXD
TXD
Table 2 Arduino connections to Hc-06
Figure 6: hc-06 connections to Arduino
You can also connect the VCC to 5v though that is not advised, especially if you are using the setup for long.
The HC-06 acts as a serial port through which you can send and receive data. So using a serial terminal or a Bluetooth customized application on your computer or phone, you can control and monitor your project. you can use Teraterm for windows or Bluetooth Termial for android device as the serial terminal.
Before, uploading the code to the Arduino, disconnect the HC-06 module, since it shares the tx/rx pins and will interfere with the upload. Connect it back once the code has been uploaded successfully.
The full setup is shown Fig 7 . I have used 6v (4xAA) to power Arduino and separate 12 V (8xAA) to power the motors board.
Figure 7: hc-06 connection to arduino
6. Arduino code:
// This code is for the bluetooth controlled arduino car.
// Bluetooth is always enabled and available . The password is 1234.