Fun with Arduino Open Source Hardware

Welcome to follow the “Geoscience New Horizons” WeChat public account

Fun with Arduino Open Source Hardware

Arduino is an open-source hardware platform that can be used to develop various interactive application devices. It is one of the commonly used platforms for technology learning, product prototyping, and maker activities. It is also one of the best platforms for cultivating maker spirit and hands-on abilities. The emergence of Arduino has greatly lowered the threshold for interactive design, allowing amateurs to create various creative works such as robots, wearable devices, smart homes, toys, etc. Arduino is fun and interesting, and frequent use can greatly enhance our hands-on abilities and may also help prevent dementia in the elderly.

1. Arduino Hardware Platform

Arduino is an open-source hardware project platform originating from Italy. This platform consists of a controller with USB interface and simple I/O interface board, and provides an integrated development platform similar to C language. The core of Arduino is based on the AVR instruction set microcontroller, but it simplifies the workflow of the microcontroller and re-compiles and encapsulates the AVR library, allowing users to use simple and practical functions without worrying about the complicated programming details of the microcontroller (such as registers, address pointers, etc.), thus greatly reducing the difficulty of developing microcontroller systems, making it particularly suitable for teachers, students, and hobbyists, and can also serve as a working platform for makers.

Arduino controllers have the following features:

(1) Open-source hardware circuit design diagrams, users can simplify or connect more sensors and controllers based on the official circuit diagrams provided;

(2) Open-source software development platform, program development interfaces and integrated development environments can be downloaded for free and can be modified according to needs;

(3) Powered by USB interface, external power supply is also available, convenient for development debugging and independent operation;

(4) Supports online burning, making it easy to update programs via USB;

(5) Supports various interactive programs such as Flash, Max/Msp, VVVV, C, Processing, etc.

Arduino controllers have many series of products, such as Arduino Duemilanove, Arduino Nano, Arduino mini, Arduino BT, Arduino Leonardo, Arduino Uno, etc. Different models of controllers have significant differences in function, performance, shape, and size, and can be selected according to needs.

Below are some common Arduino controllers.

Fun with Arduino Open Source Hardware

Fun with Arduino Open Source Hardware

Fun with Arduino Open Source Hardware

Fun with Arduino Open Source Hardware

Fun with Arduino Open Source Hardware

Fun with Arduino Open Source Hardware

Fun with Arduino Open Source Hardware

Taking a common model, Arduino Bluno as an example, it is actually an Arduino Uno controller integrated with Bluetooth functionality. The size of this controller is approximately 5x7cm, and it has 14 digital I/O ports (GPIO, of which 6 channels support PWM output), 6 analog I/O ports, a reset switch, and an ICSP download port.

Fun with Arduino Open Source Hardware

Arduino Bluno control board

Fun with Arduino Open Source Hardware

Arduino UNO control board interface position

Arduino controllers can connect to various input and output devices. Common input devices (sensors) include: touch sensors, ultrasonic sensors, temperature and humidity sensors, air quality sensors, infrared sensors, light sensors, sound sensors, etc.; common output devices (control devices) include: LED lights, buzzers, displays, motors, etc. Specialized communication modules such as Bluetooth communication, WIFI communication, Ethernet communication modules can also be connected, as well as dedicated music playback modules, voice recognition modules, speech synthesis modules, laser ranging (LiDAR) modules, etc. Additionally, to facilitate the connection of external devices, many I/O expansion boards (called Shields) are available for selection.

Various controllers and external connection devices can be purchased on e-commerce sites like Taobao.

Fun with Arduino Open Source Hardware

I/O expansion board

Fun with Arduino Open Source Hardware

Connecting ultrasonic ranging module

Fun with Arduino Open Source Hardware

Connecting music playback module

Fun with Arduino Open Source Hardware

Connecting various input and output modules

2. Software Development Platform

The Arduino open-source hardware platform provides an integrated development platform (IDE) similar to C language, which can be downloaded from www.arduino.cc. The current latest version is 1.8.5. The installation of Arduino IDE software is very simple; just download the software, unzip it to a directory, and use it directly.

Before using Arduino IDE, you need to connect the Arduino control board to the PC via USB, install the Arduino control board driver, and find the communication port and control board model (e.g., Arduino Uno is located at COM9 port).

Fun with Arduino Open Source Hardware

Arduino control board connection port and control board model

Start Arduino IDE, select the control board communication port and control board model (COM9 and Arduino Uno) in the tools menu.

Fun with Arduino Open Source Hardware

Set the Arduino control board programming communication port and control board model

Then you can write program code in the Arduino IDE. The programming adopts a C-like language, and specific programming methods can be found in various reference books provided at the end of the article. After completing the program writing, you need to verify the program first, and if correct, upload (load) it to the Arduino control board. This control board and other connected devices can then operate independently from the programming PC.

Fun with Arduino Open Source Hardware

Arduino IDE interface

3. An Example: Smart Four-Wheel Drive Car

We built a smart four-wheel drive car using Arduino. The four-wheel drive car consists of a four-wheel drive mechanical kit (chassis, four independently driven wheels), an Arduino Romeo control board, a motor driver board, a battery box, a touch and tracking sensor, and an ultrasonic ranging sensor, all parts purchased from Taobao, costing several hundred yuan, and all prices can be checked on Taobao.

———————————————————-

Introduction to Romeo Controller

The Romeo controller is a multi-integrated practical controller developed exclusively by DFRobot for robot enthusiasts, capable of utilizing the rich open-source code resources on the Arduino platform. This controller not only inherits all the features of the Arduino328 controller but also integrates motor drive, keyboard, I/O expansion board, wireless data serial communication interfaces, etc. This means that Romeo can not only be compatible with almost all Arduino series sensors and expansion boards but can also directly drive up to 12 servos. Beginners generally need to use I/O expansion and motor drive devices. Moreover, many projects have certain requirements for size and weight. Stacking multiple devices together not only makes it bulky and heavy but also makes numerous interfaces hard for beginners to grasp. The dense wiring and soldering can also be troublesome. Therefore, our Romeo was born, highly integrated, easy to identify, simple to use, and rich in tutorials.

Romeo integrates L298 dual-channel high-current motor drive, which can directly control 2 DC motors with a peak current of up to 2A. This feature makes Romeo a powerful tool for controlling smart cars. You can directly and stably drive high-current motors on the car platform. Even more valuable is that you can add wireless data transmission modules like APC220 and Bluetooth on Romeo, allowing you to remotely control the car wirelessly and collect data from onboard cameras and other sensors. Most motor driver boards on the market do not have this feature. Remo is widely used in mobile robots due to its high integration, and we provide more application examples and code.

Romeo adds more user-friendly designs, using 3P color pin headers that correspond to our sensor connection wires, preventing incorrect insertion from burning components. Additionally, each port has male and female headers, so no matter what kind of wire material you use, you can confidently plug it into Romeo. The red corresponds to power, blue corresponds to analog ports, green corresponds to digital ports, and black corresponds to GND.

———————————————————-

Fun with Arduino Open Source Hardware

Fun with Arduino Open Source Hardware

Four-wheel drive car

The four motors can control the wheels to move forward, backward, and speed through PWM (Pulse Width Modulation) output interfaces. The touch and tracking sensors, as well as the ultrasonic ranging sensors, are used to detect obstacles in the forward direction to determine whether the four-wheel drive car should continue moving forward, turn around, or turn.

Fun with Arduino Open Source Hardware

Ultrasonic ranging sensor

Fun with Arduino Open Source Hardware

The four-wheel drive car connected to the PC for program debugging and loading

The control program used for this four-wheel drive car is as follows:

/*

Motor4WD

Jan. 28,2014

Gaishan ZHAO

*/

/***** Global Defines ****/

// defines to identify sensors

const int SENSE_IR_LEFT = 0;

const int SENSE_IR_RIGHT = 1;

// defines for directions

const int DIR_LEFT = 0;

const int DIR_RIGHT = 1;

const int DIR_CENTER = 2;

const char* locationString[] = {“Left”, “Right”, “Center”};

const int OBST_NONE = 0; // no obstacle detected

const int OBST_LEFT_EDGE = 1; // left edge detected

const int OBST_RIGHT_EDGE = 2; // right edge detected

const int OBST_FRONT_EDGE = 3; // edge detect at both left and right sensors

/**** End of Global Defines ****************/

const int MotorE1=5;

const int MotorE2=6;

const int MotorM1=4;

const int MotorM2=7;

const int MotorE3=3;

const int MotorE4=10;

const int MotorM3=9;

const int MotorM4=11;

const int LED_PIN = 13;

const int ClipPin = 12;

const int TripPin = 2;

const int EchoPin = 8;

/**************************************************************************

ir reflectance sensor code

***************************************************************************/

const byte NBR_SENSORS = 3; // this version only has left and right sensors

const byte IR_SENSOR[NBR_SENSORS] = {0, 1, 2}; // analog pins for sensors

int irSensorAmbient[NBR_SENSORS]; // sensor value with no reflection

int irSensorReflect[NBR_SENSORS]; // value considered detecting an object

int irSensorEdge[NBR_SENSORS]; // value considered detecting an edge

boolean isDetected[NBR_SENSORS] = {false,false}; // set true if object detected

const int irReflectThreshold = 10; // % level below ambient to trigger reflection

const int irEdgeThreshold = 90; // % level above ambient to trigger edge

void irSensorBegin()

{

for(int sensor = 0; sensor < NBR_SENSORS; sensor++)

irSensorCalibrate(sensor);

}

// calibrate for ambient light

void irSensorCalibrate(byte sensor)

{

int ambient = analogRead(IR_SENSOR[sensor]); // get ambient level

irSensorAmbient[sensor] = ambient;

// precalculate the levels for object and edge detection

irSensorReflect[sensor] = (ambient * (long)(100-irReflectThreshold)) / 100;

irSensorEdge[sensor] = (ambient * (long)(100+irEdgeThreshold)) / 100;

}

// returns true if an object reflection detected on the given sensor

// the sensor parameter is the index into the sensor array

boolean irSensorDetect(int sensor)

{

boolean result = false; // default value

int value = analogRead(IR_SENSOR[sensor]); // get IR light level

if( value <= irSensorReflect[sensor]) {

result = true; // object detected (lower value means more reflection)

if( isDetected[sensor] == false) { // only print on initial detection

Serial.print(locationString[sensor]);

Serial.println(” object detected”);

}

}

isDetected[sensor] = result;

return result;

}

boolean irEdgeDetect(int sensor)

{

boolean result = false; // default value

int value = analogRead(IR_SENSOR[sensor]); // get IR light level

if( value >= irSensorEdge[sensor]) {

result = true; // edge detected (higher value means less reflection)

if( isDetected[sensor] == false) { // only print on initial detection

Serial.print(locationString[sensor]);

Serial.println(” edge detected”);

}

}

isDetected[sensor] = result;

return result;

}

void MotorTestAround(void);

void MotorTestDance(void);

long USDistance(int, int) ;

long Voice(int);

long Speed2(int, int);

long Clip(int);

void MotorTestDance()

{

motorForward(200,200);

delay(2000);

motorBack(200,200);

delay(2000);

motorForward(200,200);

delay(2000);

motorLeft(200,200);

delay(2000);

motorForward(50,200);

delay(2000);

motorBack(50,200);

delay(2000);

motorForward(200,50);

delay(2000);

motorBack(100,50);

delay(2000);

motorLeft(200,200);

delay(2000);

}

void MotorTestAround()

{

motorStop();

delay(1000);

motorForward(200,200);

delay(4000);

motorLeft(200,200);

delay(1000);

motorForward(200,200);

delay(4000);

motorLeft(200,200);

delay(1000);

motorForward(200,200);

delay(4000);

motorLeft(200,200);

delay(1000);

motorForward(200,200);

delay(4000);

motorLeft(200,200);

delay(1000);

}

void motorStop() {

Serial.print(“Stop…”);

Serial.println();

analogWrite(MotorE1,LOW);

analogWrite(MotorE2,LOW);

analogWrite(MotorE3,LOW);

analogWrite(MotorM3,LOW);

analogWrite(MotorE4,LOW);

analogWrite(MotorM4,LOW);

}

void motorForward(char s1,char s2) {

Serial.print(“Go Forward…”);

Serial.println();

analogWrite(MotorE1,s1);

analogWrite(MotorE2,s2);

digitalWrite(MotorM1,HIGH);

digitalWrite(MotorM2,HIGH);

analogWrite(MotorE3,s1);

analogWrite(MotorM3,LOW);

analogWrite(MotorE4,LOW);

analogWrite(MotorM4,s2);

}

void motorBack(char s1,char s2) {

Serial.print(“Go Back…”);

Serial.println();

analogWrite(MotorE1,s1);

analogWrite(MotorE2,s2);

digitalWrite(MotorM1,LOW);

digitalWrite(MotorM2,LOW);

analogWrite(MotorE3,LOW);

analogWrite(MotorM3,s1);

analogWrite(MotorE4,s2);

analogWrite(MotorM4,LOW);

}

void motorLeft(char s1,char s2) {

Serial.print(“Turn Left…”);

Serial.println();

analogWrite(MotorE1,s1);

analogWrite(MotorE2,s2);

digitalWrite(MotorM1,LOW);

digitalWrite(MotorM2,HIGH);

analogWrite(MotorE3,LOW);

analogWrite(MotorM3,s1);

analogWrite(MotorE4,LOW);

analogWrite(MotorM4,s2);

}

void motorRight(char s1,char s2) {

Serial.print(“Turn Right…”);

Serial.println();

analogWrite(MotorE1,s1);

analogWrite(MotorE2,s2);

digitalWrite(MotorM1,HIGH);

digitalWrite(MotorM2,LOW);

analogWrite(MotorE3,LOW);

analogWrite(MotorM3,s1);

analogWrite(MotorE4,s2);

analogWrite(MotorM4,LOW);

}

long USDistance(int pin1,int pin2) {

long duration, cm;

digitalWrite(pin1, LOW);

delayMicroseconds(2);

digitalWrite(pin1, HIGH);

delayMicroseconds(10);

digitalWrite(pin1, LOW);

duration = pulseIn(pin2, HIGH);

if (duration>=20000) return 100;

cm = duration/58-1;

Serial.print(duration);

Serial.print(“us, “);

Serial.print(cm);

Serial.print(“cm”);

Serial.println();

delay(100);

return cm;

}

long Voice(int voicePin)

{

long v;

v=analogRead(voicePin);

Serial.print(“Voice=”);

Serial.print(v);

Serial.println();

return v;

}

long Speed2(int pin1,int pin2)

{

long v1,v2;

v1=analogRead(pin1);

v2=analogRead(pin2);

Serial.print(“Speed = “);

Serial.print(v1);

Serial.print(” , “);

Serial.print(v2);

Serial.println();

return v1;

}

long Clip(int clip)

{

long v;

v=digitalRead(clip);

if (v>0) {

Serial.print(“Clip = “);

Serial.print(v);

Serial.println();

}

return v;

}

void setup() {

// Back wheel control

pinMode(MotorE1,OUTPUT);

pinMode(MotorE2,OUTPUT);

pinMode(MotorM1,OUTPUT);

pinMode(MotorM2,OUTPUT);

// Front wheel control

pinMode(MotorE3,OUTPUT);

pinMode(MotorE4,OUTPUT);

pinMode(MotorM3,OUTPUT);

pinMode(MotorM4,OUTPUT);

// Sonar Distance

pinMode(TripPin,OUTPUT);

pinMode(EchoPin,INPUT);

pinMode(ClipPin,INPUT);

Serial.begin(9600);

Serial.print(“Four-Wheel Robot ……”);

Serial.println();

Serial.print(“Driving around Box’side…”);

Serial.println();

// MotorTestAround();

// Serial.print(“Driving …”);

// Serial.println();

// MotorTestDance();

}

// the loop routine runs over and over again forever:

void loop() {

long cm,clip;

// motorForward(200,200);

cm=USDistance(TripPin,EchoPin);

if (cm<=16) {

Serial.print(“Left Turn ……”);

Serial.println();

motorLeft(200,200);

delay(1000);

}

clip=Clip(ClipPin);

if (clip>0) {

Serial.print(“U Turn “);

Serial.println();

motorBack(100,100);

delay(2000);

motorLeft(200,200);

delay(2000);

}

motorForward(200,200);

delay(200);

}

4. References

There are already many publications on how to apply Arduino open-source hardware to build various interactive works and robots. The author has two Chinese books in hand: “Arduino Development Practical Guide – AVR Edition”, “Arduino Robotics Production Guide”, and “Arduino Development Practical Guide – Robot Edition”, etc. Many such books can be found in WeChat Read.

Fun with Arduino Open Source Hardware

Fun with Arduino Open Source Hardware

Fun with Arduino Open Source Hardware

Additionally, the author has collected several very useful e-books on Arduino, shared with friends. Among them are authoritative books like “Arduino Cookbook”, “Arduino Robotics”, “Arduino from Basics to Practice”, and “Fun Electronic Production Based on Arduino”:

Fun with Arduino Open Source Hardware

“Arduino Cookbook”

(Baidu Cloud Disk link: https://pan.baidu.com/s/1miW1dJa)

Fun with Arduino Open Source Hardware

“Arduino Robotics”

(Baidu Cloud Disk link: https://pan.baidu.com/s/1d9vh50)

Fun with Arduino Open Source Hardware

“Arduino from Basics to Practice”

(Baidu Cloud Disk link: https://pan.baidu.com/s/1nxpCf8H)

Fun with Arduino Open Source Hardware

“Fun Electronic Production Based on Arduino”

(Baidu Cloud Disk link: https://pan.baidu.com/s/1c37pjag)

Please pay attention to the “Geoscience New Horizons” WeChat public account

Fun with Arduino Open Source Hardware

Leave a Comment

Your email address will not be published. Required fields are marked *