This project makes use of two servos (Tiankongrc MG995), servo mounting brackets a 2-axis thumb joystick, an active buzzer, and an Arduino Uno R3. To operate the two servos together it is necessary to mount them perpendicular to each other. Where one servo moves along 180 degrees horizontally (x-axis) and the other moves 180 degrees vertically (y-axis). While the joystick VRx, VRy, and SW terminals are read by the Arduino through its GPIO pins, their coordinates are interpreted and sent to each servo for positioning. Either by a single manual motion event or as movement continuously read at the servos to rotate from one position to the next.
The active buzzer sounds when the joystick is depressed. It acts as a toggle to represent a select function that corresponds to typical X,Y positioning at a specific point along its movement.
Project Schematic:
Through pulse width modulation pin connections on the Arduino, simultaneously movement control is achieved at both servos. Along with voltage and ground connections shared with the joystick, separate analog connections are terminated for analogRead instructions at the Arduino controller.
Project Review:
This video demonstrates the servo motor’s range of motion and precise positioning as the joystick is controlled with its push-button switch.
Code Example:
#include <Servo.h> Servo Xservo; Servo Yservo;
int Xpin=A0; int Ypin=A1; int Spin=2; int XSpin=9; int YSpin=10; int buzzPin=7; int WVx; int WVy; int Xval; int Yval; int Sval; int dt=200;
delay(dt); Serial.print(“X Value = “); Serial.print(Xval); Serial.print(” Y Value = “); Serial.print(Yval); Serial.print(” Switch State is “); Serial.println(Sval); }
This project involved a 5VDC stepper motor and its corresponding ULN2003 driver assembly. Stepper motors are unique from servos or DC motors because they are very precise, have a full range of motion, and they can produce a lot of torque. This specific motor permits 2048 steps according to its specifications, so each step represents a high level of rotational movement granularity in a small package. –The purpose of the system is to evaluate a simple stepper motor along with its driver assembly to understand their behavior, limitations, and performance characteristics.
The normally closed micro-switch provides a toggle for the stepper motor shaft to move in either a forward or reverse direction. Directionality is set by a code condition determined by the toggle switch transition states whereas the switch is depressed to activate a change of direction opposite the prior rotational motion. Programmatically, the rotational speed is set to about 10 RPM in this project, but speeds are assigned slower as desired.
Stepper motors are found among many applications today. They allow for precision movement and control of hardware throughout various industries, households, or personal devices. They open lids, doors, and windows. They drive gears to rotate lamps, sensors, cameras, and so forth. The use-cases of stepper motors are very wide-spread.
The ULN2003 IC chip located on this assembly is really an array of Darlington pairs that drive up to 500mA at 50VDC. As a current boost is produced from the second Darlington transistor staged after the first of its pair, sufficient current capacity is presented to the terminals of the assembly that hosts the ULN2003. This assembly provides for input and output connections between the stepper motor and an Arduino unit along with LEDs and voltage supply terminals.
Each LED on the ULN2003 indicates the step activity of all four stators. Notice that each stator is in a fixed position with coil wrapping. As each coil is charged on and off, the motor shaft rotates a single step.
The internal workings of the stepper motor convert electrical energy (5VDC in this case) to mechanical movement. In an incremental fashion, all four coils in a fixed position advance the internal rotation in clockwise or counter-clockwise steps (depending upon motor capability). The shaft assembly that extends outside of the motor enclosure provides for a mechanical attachment to get practical use of the stepper motor.
The 28BYJ-48 stepper motor and its ULN2003 driver assembly are separately powered from the Arduino UNO R3 host. Stepper motors draw extra high current to require more power than what an Arduino can support. So this motor runs from a separate wall adapter that delivers 5VDC at 3.5A (~18W).
It is because of this higher motor current requirement that the Darlington pair boost is provided through the ULN2003 assembly. So it is necessary to recognize that motors must be matched with a corresponding driver board that includes a suitable current capacity along with the appropriate types of input and output terminations matched to the motor. Normally, stepper motors have four wires for driver connectivity.
Project Schematic:
Project Review:
This video demonstrates the stepper motor’s direction of rotation as the pushbutton switch is toggled.
Arduino IDE:
Code Setup:
#include <Stepper.h> int stepsPerRevolution=2048; //get this step count from the spec sheet int motSpeed=10; //10 RPM int dt=500;
int buttonPin=2; int motDir=1; //variable to keep track direction of motor shaft int buttonValNew; //present state of the button switch int buttonValOld=1; //prior state of the button switch initiated as 1 (not pressed)
Stepper myStepper(stepsPerRevolution, 8,10,9,11); //the numbers are the pin sequence for a specific driver and specific motor connected in a specific way
void setup() { Serial.begin(9600); myStepper.setSpeed(motSpeed); pinMode(buttonPin,INPUT); digitalWrite(buttonPin,HIGH); //puts a pullup high state onto the button pin }
void loop() { buttonValNew=digitalRead(buttonPin); if (buttonValOld==1 && buttonValNew==0){ motDir=motDir(-1); } //button transition (1,0) sets condition for motor direction change buttonValOld=buttonValNew; myStepper.step(motDir1);
This project was about making a tilt sense system that involves a motor or fan. The system is also programmed and set up with a tip sense light. It simulates a tip-over or roll-over situation and when the system reaches a 90-degree angle from level. At 90 degrees, the sensor drive signal shuts everything down through the Nano. It also has industrial applications as there are different tilt switches at different angles.
Project Schematic:
A tilt switch is really just a type of motion sensor that activates after a certain angle from a reference point is reached. Among various approaches toward level detection and sensor motion, this project uses a canister tilt switch that uses a small internal ball that interrupts a closed switch path as it is rolled from one position to another at the component’s specified angle.
At the specified angle, the tilt switch path is open and no further connection between its leads is permitted. For example, in a level state, a tilt device’s upright position settles an internal miniature metal ball for a closed switch path (or “on” function). Conversely, when the position tips beyond its specified angle, the internal metal ball moves to another position where the connection path between the two switch leads become interrupted (or “off” function).
Project Operation:
The demonstration of this system zooms in on the states of LED illumination and fan movement as its position changes from level (0-degrees) to upright (90-degrees).
Code Setup:
int speedPin=5; int dir1=4; int dir2=3; int mSpeed=255; int tiltPin=2; int tiltVal;
This project makes use of a photoresistor as a light sensor to control the movement of a servo motor’s shaft. The change of position in the servo motor’s output shaft moves from 0 degrees to 180 degrees maximum depending upon the light intensity present at the photoresistor. The highest level of light places the output shaft arm to 0 degrees while the absence of light at the sensor moves the output shaft arm to about 180 degrees. The actual range of motion is limited to the quality of the servo, but 180 degrees is generally the limit.
All components in the system are powered by the Arduino Uno (R3) through the USB connection from a local supply or computer.
The purpose of the project is to demonstrate the simple use of a servo for the automatic positioning of a physical object as a function of light intensity. The light sensor is read at an analog GPIO pin to get continuously variable values to read into memory via an analogRead operation. The motor response to continuous analog read activity (with a small 250ms delay between each) is calculated to a PWM output level written to a port where the output shaft moves at a corresponding angle.
Project Operation:
Project Schematic:
Arduino IDE:
Servo Output Angle Calculations:
Code Setup:
#include <Servo.h> int lightVal; int lightPin=A4; int dt=250; int angle; int servoPin=9; int servoPos=165; Servo myServo; //create object with a name
This project runs with an IR sensor that reads a remote control’s Hexadecimal data bursts as its buttons are selected. Each button represents a function that becomes executed programmatically within the Nano to affect the color and light intensity at the LED. As hex values are decoded into the Arduino Nano via the IR sensor, a conditional statement evaluates the decoded value held in memory. For each button selected, the conditional statement evaluates the hex value unique to each.
Functional Demonstration Video:
The video demonstrates a visual walkthrough of power on, off, color selection, and increase or decrease of each color brightness. Control is demonstrated through the remote control through the wireless communication made through infrared modulation of binary data decoded or translated into useful hex values for programming and operation.
Project Schematic:
The schematic diagram of the circuit is simple. The connections are defined as illustrated as power, ground, and pin-to-pin terminations are made. The RGB LED supported with three 330-ohm current limiting resistors, but this value can be adjusted higher as desired.
Arduino IDE:
The IR sensor reads a remote control’s Hexadecimal data stream as its buttons are selected. Each button represents a function that becomes executed programmatically. As hex values are decoded into the Arduino Nano via the IR sensor, a conditional statement evaluates the decoded value held in memory. For each button selected, the conditional statement evaluates the hex value unique to each.
Code Setup:
#include <IRremote.h> int IRpin=9; IRrecv IR(IRpin); decode_results cmd; String myCom;
int rPin=6; int gPin=10; int bPin=5;
int rBright=255; int gBright=255; int bBright=255;
This project accomplishes a few objectives. First, the use of a KY-022 Infrared sensor is incorporated for general familiarity. Second, the IR remote control emits HEX codes for each button pressed, so it is necessary to capture those HEX codes to map them to specific button IDs and functions later developed. Third, to integrate the motor control driver (L293D) with the Arduino Nano to control motor activity such as speed and direction.
Arduino Setup:
Code Setup:
#include <IRremote.h>
int IRpin=9; IRrecv IR(IRpin); decode_results cmd; String myCom;
int speedPin=5; int dir1=4; int dir2=3; int mSpeed=205;
This project involves the use of an HC-SR04 proximity sensor commonly used among robotic devices for purposes of collision avoidance. In this project, the sensor is applied to an Arduino Nano system measure distance from an object and report back the results to a serial monitor on a computer, and an LCD display. This unit is powered via a battery or USB power back for portability.
Each measurement is taken once the sensor appears before an object, or if a target object is placed in front of the sensor. Once the target is placed, a user is prompted to press the circuit switch to activate the measurement activity that occurs. The measurement reported to a computer and LCD display is an average of 100 readings between the sensor and the placed object. The Nano programmatically operates a high-speed loop by which each reading event (0 to 100) is cumulatively stored into a memory bucket. Once all reading measurements are taken, the average measurement is obtained by calculating the total by dividing the number of measurements completed into the total bucket value. This function is repeated for each switch/button-press event to activate a measurement.
Functional Demonstration Video:
Project Schematic:
Arduino Setup:
Code Example:
#include <LiquidCrystal.h> int rs=7; int en=8; int d4=9; int d5=10; int d6=11; int d7=12; int buttonPin=A0; int buttonVal; int numMeas=100; float avMeas; // make float not int to avoid rounding error int j; float bucket=0; // make float not int to avoid rounding error
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
int trigPin=3; int echoPin=2; int pingTravelTime; float pingTravelDistance; float distanceToTarget; int dt=5000; //int dt(5000);
void setup() { Serial.begin(9600); lcd.begin(16,2); pinMode(trigPin,OUTPUT); pinMode(echoPin,INPUT); pinMode(buttonPin,INPUT); digitalWrite(buttonPin,HIGH); //initializes analog A0 pin for digital use through an internal pull up resistor. }
void loop() { lcd.setCursor(0,0); lcd.print(“Place the Target”); lcd.setCursor(0,1); lcd.print(“Press to Measure”); buttonVal=digitalRead(buttonPin); while (buttonVal==1){ buttonVal=digitalRead(buttonPin); } lcd.setCursor(0,0); lcd.clear(); lcd.print(“Measuring…”); for (j=1;j<=numMeas;j=j+1){ digitalWrite(trigPin,LOW); delayMicroseconds(10); digitalWrite(trigPin,HIGH); delayMicroseconds(10); digitalWrite(trigPin,LOW); pingTravelTime=pulseIn(echoPin,HIGH); delay(25); pingTravelDistance=(pingTravelTime*765.*5280.*12)/(3600.*1000000); distanceToTarget=pingTravelDistance/2; bucket=bucket+distanceToTarget; } avMeas=bucket/numMeas;
The purpose of this build is to become more familiar with how to develop a free-standing Arduino system using the Arduino Nano. The Nano is a smaller equivalent to the Arduino Uno, but with fewer interface options. It obviously occupies less space since it is a smaller footprint while having reduced overall dimensions. The project makes use of a DHT temperature and humidity sensor that interfaces with the Nano and it includes a 16×2 LCD display to indicate measurement results.
1602A LCD Display Pinout
Pin
Symbol
Function
1
VSS
Ground
2
VDD
+5VDC
3
V0
Contrast
4
RS
Register
5
R/W
Read/Write
6
E
Enable
7
D0
Data
8
D1
Data
9
D2
Data
10
D3
Data
11
D4
Data
12
D5
Data
13
D6
Data
14
D7
Data
15
A
Anode (+5VDC)
16
K
Cathode (Ground)
Arduino Setup:
Code Setup:
#include <DHT.h> #include <LiquidCrystal.h> int rs=7; int en=8; int d4=9; int d5=10; int d6=11; int d7=12; LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
int sensePin=2; DHT HT(sensePin,Type); float humidity; float tempC; float tempF; int setTime=500; int dt=1000;
A common Arduino system typically includes a display of some type. This project was to set up a 16×2 LCD display to an Arduino unit and run it with simple messages that render it available for inputs or computational processing. It produces an informational output of its own, or to correspond to another event controlled by a wider system.
The physical connections between the Arduino and LCD display are through direct jumper connections between GPIO pins to data, control, power, and ground. The potentiometer is simply for character illumination intensity.
The digital GPIO pins that interface to the LCD connect to its data pins. R/W is strapped low to ground.
1602A LCD Display Pinout
Pin
Symbol
Function
1
VSS
Ground
2
VDD
+5VDC
3
V0
Contrast
4
RS
Register
5
R/W
Read/Write
6
E
Enable
7
D0
Data
8
D1
Data
9
D2
Data
10
D3
Data
11
D4
Data
12
D5
Data
13
D6
Data
14
D7
Data
15
A
Anode (+5VDC)
16
K
Cathode (Ground)
Program & Functional Operation:
Code Setup:
#include <LiquidCrystal.h> int rs=7; int en=8; int d4=9; int d5=10; int d6=11; int d7=12; LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
This project controls an increasing and decreasing voltage level in increments to represent a dimmer present at an LED. An in-circuit buzzer serves as an alarm to indicate either a maximum or minimum level is attained. Two separate pushbutton switches are up / down controls at programmable increments.
One pull up resistor for each pushbutton switch is necessary to correctly assert each GPIO input to control circuit and code activity. Four total GPIO pins used, each one for its dedicated function. There is no attempt to make dual use of a GPIO port.
Program & Functional Operation:
Code Setup:
int buttonPin1=12; int buttonPin2=11; int buzzPin=2; int LEDPin=3; int buttonVal1; int buttonVal2; int LEDbright=0; int dt=500;
This project involves a toggle switch that an Arduino UNO recognizes through code as necessary to activate an LED over a GPIO pin. Assembly of the circuit requires a 330 resistor, 10K resistor, normally open pushbutton switch, and a red LED plus some jumpers. For added clarity about the assembly refer to the photos below. The schematic illustration merely offers a symbolic representation of the setup. The prior project involved the use of pushbutton switch that temporarily enabled an output (LED) from a GPIO pin.
This project changes the state of the GPIO (LED) each time the pushbutton is pressed. The pushbutton switch in this way operates as a toggle as a steady-state on/off through conditional instruction statements written into the code.
Simple set up of a small circuit to interface with the Arduino UNO R3 SBC. Includes 330 ohm, 10K ohm current limiting resistors, a RED LED, and a small pushbutton normally open switch. Circuit jumpers interface to the Arduino’s GPIO ports.
Top down view of circuit connections.
To register active high and active low states at a GPIO port, it is necessary to apply pull up or pull-down resistors to a circuit’s normally open or normally closed pushbutton switch. It is not an acceptable practice to place a GPIO pin directly to a +5V source, or Ground in order to operate a directly connected switch. The purpose of a pulldown or pullup resistor placed onto a switch is to correctly register an active high or low state at an assigned GPIO measurement pin. To illustrate the connections see the diagrams below:
Simply put, there just must be a circuit path to either a voltage reference or ground reference using a resistor connected to a switch for proper operation. The active voltage present at pin-12, while the button switch is not pressed, is 5VDC. When the pushbutton switch is pressed this voltage level drops to 0VDC. As a 0VDC state is read into pin 12 by the digitalRead operation (i.e. pin 12 becomes grounded), pin 8 presents 5VDC to R2 for the Red LED to illuminate. While the pushbutton switch is pressed and held closed, the serial monitor presents a digital “0” state. This is due to the placement of the digitalRead command within the continuous program loop.
To run the project it is necessary to assemble the circuit onto a breadboard using the components identified above. When the hardware is set up, it is then necessary to write and run the code to get functional use of the project.
Code Setup:
int LEDState=0; int LEDPin=8; int buttonPin=12; int buttonNew; int buttonOld=1; int dt=100;
void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(LEDPin, OUTPUT); pinMode(buttonPin, INPUT); }
With all suitable integer variables declared, operational instructions become written to perform their intended purpose. Standard pin mode set up declarations are made, and thereafter, the main loop program begins.
The digitalRead operation is executed as the buttonPin command is asserted. The physical state change that occurs from the button switch is detected at the Arduino port (pin 12) and that change is digitally read into memory and stored to the buttonNew variable. Once a switch state is read into memory via the GPIO port, the next set of instructions act upon those states held into memory.
The if-else statement parameters check for the high or low (5VDC or 0VDC) level presented to GPIO pin 12. As the buttonOld and buttonNew variables are checked for true status against assigned states “0” to buttonOld and “1” to buttonNew, the next if-statement is executed. The LEDState is checked for a logic 0 state and if it is true, the digitalWrite command places a HIGH state (logic 1, 5VDC) to the LEDPin (pin 8) GPIO port. The LEDState is then given a logic 1 into its memory space to initialize it for repeat evaluation during the continuous loop in function. Once the true state instructions are executed within both ‘if’ commands, the program falls through the function to bypass the ‘else’ code segment and continues through to the rest to the program until completion where the loop again begins.
The second half of the conditional function, ‘else’ supports the logic evaluation that previously occurred between the buttonNew and buttonOld ‘recognized’ states. If the combination of both variable assessments proves false, the else statement becomes effective within the loop to set the LEDPin to Low. This is the equivalent of a logic evaluation that checks for voltage transitions low to high and turn the LED off. Each time this transition occurs, the program loop writes the active high to turn the LED on or off. The next low-to-high button switch transition evaluation occurs within the ‘else’ segment of the conditional loop to again set the GPIO pin to low (pin-8 LED off) if that else condition should become true.
As the program loop continuously runs, the GPIO pin accepts state changes to operate as a toggle on and off, then on and off again.
This project involves a push-button switch that an Arduino UNO recognizes through code as necessary to activate an LED over a GPIO pin. Assembly of the circuit requires a 330 resistor, 10K resistor, normally open pushbutton switch, and a red LED plus some jumpers. For added clarity about the assembly refer to the photos below. The schematic illustration merely offers a symbolic representation of the setup.
To register active high and active low states at a GPIO port, it is necessary to apply pull up or pull-down resistors to a circuit’s normally open or normally closed pushbutton switch. It is not an acceptable practice to place a GPIO pin directly to a +5V source, or Ground in order to operate a directly connected switch. The purpose of a pulldown or pullup resistor placed onto a switch is to correctly register an active high or low state at an assigned GPIO measurement pin. To illustrate the connections see the diagrams below:
Simply put, there just must be a circuit path to either a voltage reference or ground reference using a resistor connected to a switch for proper operation. The active voltage present at pin-12, while the button switch is not pressed, is 5VDC. When the pushbutton switch is pressed this voltage level drops to 0VDC. As a 0VDC state is read into pin 12 by the digitalRead operation (i.e. pin 12 becomes grounded), pin 8 presents 5VDC to R2 for the Red LED to illuminate. These states correspond to the Sketch serial monitor “0” or “1” messages presented. While leaving the pushbutton switch unpressed, the serial monitor presents a digital “1” state. While the pushbutton switch is pressed and held closed, the serial monitor presents a digital “0” state. This is due to the placement of the digitalRead command within the continuous program loop.
To run the project it is necessary to assemble the circuit onto a breadboard using the components identified above. When the hardware is set up, it is then necessary to write and run the code to get functional use of the project.
Program & Functional Operation:
Code Setup:
int LEDPin=8; int buttonPin=12; int buttonRead; int dt=250;
void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(LEDPin, OUTPUT); pinMode(buttonPin, INPUT); }
void loop() { // put your main code here, to run repeatedly: buttonRead=digitalRead(buttonPin); Serial.println(buttonRead); delay(dt); if(buttonRead==1){ digitalWrite(LEDPin, LOW); } if(buttonRead==0){ digitalWrite(LEDPin, HIGH); } }