Arduino Tutorials – Lesson 25 – L298N Motor Driver Module using Arduino UNO

Creating 4 DC motors or 2 DC motors with directional and speed control program using Arduino UNO

Required Components

  1. L298N Motor Driver Module -1 no
  2. Arduino UNO -1 no
  3. DC Motor(gear) -2 no
  4. 12V Battery -1 no
  5. Data Cable -1 no
  6. Connecting Wires -4 no

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect the 12V Battery to the L298N Motor Driver.
  3. Connect the ENA, IN1, IN2, IN3, IN4, ENB pins to the Arduino UNO board pins 4, 2, 3,5, 6, 7 properly.
  4. Connect the DC motor pins to the motor driver output pins.
  5. Connect the ground connection respectively.
  6. Check the Circuit Connections.
  7. Check the Arduino program.
  8. Run the Arduino program.

Arduino Program

int motor1pin1 = 2;
int motor1pin2 = 3;
int enPin1 = 4;

int motor2pin1 = 5;
int motor2pin2 = 6;
int enPin2 = 7;


void setup() 
{
  pinMode(motor1pin1, OUTPUT);
  pinMode(motor1pin2, OUTPUT);
  pinMode(enPin1, OUTPUT);
  digitalWrite(enPin1, HIGH);
  
  pinMode(motor2pin1, OUTPUT);
  pinMode(motor2pin2, OUTPUT);
  pinMode(enPin2, OUTPUT);
  digitalWrite(enPin2, HIGH);
}

void loop() 
{
  digitalWrite(motor1pin1, HIGH);
  digitalWrite(motor1pin2, LOW);
  digitalWrite(motor2pin1, HIGH);
  digitalWrite(motor2pin2, LOW);
  delay(1000);
  
  digitalWrite(motor1pin1, LOW);
  digitalWrite(motor1pin2, HIGH);
  digitalWrite(motor2pin1, LOW);
  digitalWrite(motor2pin2, HIGH);
  delay(1000);
}

Usage

  1. Drive DC motors.
  2. Drive Stepping motors.
  3. In Robotics.

Arduino Tutorials – Lesson 24 – L298N Motor Driver with Node MCU

Creating 2 DC Motors and 2 LEDs using wifi control program using Arduino UNO

Required Components

  1. Node MCU -1 no
  2. L298N Motor Driver -1 no
  3. 9V Battery -1 no
  4. 5V DC Motor -2 no
  5. Motor wheel -2 no
  6. Cable -1 no
  7. Jumper Wires -7 no

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect the 9V Battery to the L298N Motor Driver.
  3. Connect the ENA, IN1, IN2, IN3, IN4, ENB pins to the Node MCU pins D2, D0, D1, D7, D6, D5 properly.
  4. Connect the DC motor pins to the motor driver output pins.
  5. Connect the ground connection respectively.
  6. If you want connect the LED pins Cathode (+) & Anode (-) to the Node MCU pins D3, D4 & gnd respectively.
  7. Check the Arduino program.
  8. Check the Circuit Connections.
  9. Run the Arduino program.

Arduino Program

#include <ESP8266WiFi.h>
const char* ssid = "*****";
const char* password = "********";
int motor1pin1 = 16; //D0
int motor1pin2 = 5; //D1
int enPin1 = 4; //D2
int motor2pin1 = 13; //D7
int motor2pin2 = 12; //D6
int enPin2 = 14;//D5

int led1 = 0; //D3
int led2 = 2; //D4
WiFiServer server(80);

void setup() 
{
  Serial.begin(115200);
  delay(10);
  pinMode(motor1pin1, OUTPUT);
  pinMode(motor1pin2, OUTPUT);
  pinMode(enPin1, OUTPUT);
  digitalWrite(enPin1, HIGH);
  pinMode(motor2pin1, OUTPUT);
  pinMode(motor2pin2, OUTPUT);
  pinMode(enPin2, OUTPUT);
  digitalWrite(enPin2, HIGH);
  
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  server.begin();
  Serial.println("Server started");
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
}

void loop() 
{
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
  int value,value1 = LOW,value2 = LOW,value3 = LOW,value4 = LOW;
  if (request.indexOf("/MotorForward") != -1)
  {
    digitalWrite(motor1pin1, HIGH);
    digitalWrite(motor1pin2, LOW);
    digitalWrite(motor2pin1, HIGH);
    digitalWrite(motor2pin2, LOW);
    delay(1000);
    value1 = HIGH;
    value2 = LOW;
    value3 = HIGH;
    value4 = LOW;
  }
  if (request.indexOf("/MotorBackward") != -1)
  {
    digitalWrite(motor1pin1, LOW);
    digitalWrite(motor1pin2, HIGH);
    digitalWrite(motor2pin1, LOW);
    digitalWrite(motor2pin2, HIGH);
    delay(1000);
    value1 = LOW;
    value2 = HIGH;
    value3 = LOW;
    value4 = HIGH;
  }
  if (request.indexOf("/MotorLeft") != -1)
  {
    digitalWrite(motor1pin1, LOW);
    digitalWrite(motor1pin2, HIGH);
    digitalWrite(motor2pin1, HIGH);
    digitalWrite(motor2pin2, LOW);
    delay(1000);
    value1 = LOW;
    value2 = HIGH;
    value3 = HIGH;
    value4 = LOW;
  }
  if (request.indexOf("/MotorRight") != -1)
  {
    digitalWrite(motor1pin1, HIGH);
    digitalWrite(motor1pin2, LOW);
    digitalWrite(motor2pin1, LOW);
    digitalWrite(motor2pin2, HIGH);
    delay(1000);
    value1 = HIGH;
    value2 = LOW;
    value3 = LOW;
    value4 = HIGH;
  }
  if (request.indexOf("/MotorStop") != -1)
  {
    digitalWrite(motor1pin1, LOW);
    digitalWrite(motor1pin2, LOW);
    digitalWrite(motor2pin1, LOW);
    digitalWrite(motor2pin2, LOW);
    delay(1000);
    value1 = LOW;
    value2 = LOW;
    value3 = LOW;
    value4 = LOW;
  }
  
  if (request.indexOf("/LedOn") != -1)
  {
    digitalWrite(led1,HIGH);
    digitalWrite(led2,HIGH);
    delay(2000);
    value = HIGH;
  }
  
  if (request.indexOf("/LedOn") != -1)
  {
    digitalWrite(led1,LOW);
    digitalWrite(led2,LOW);
    delay(2000);
    value = LOW;
  }
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
  client.print("motor is now: ");
  
  if(value1 == HIGH && value2 == LOW && value3 == HIGH && value4 == LOW ) {
    client.print("Forward");
  }
  else if(value1 == LOW && value2 == HIGH && value3 == LOW && value4 == HIGH  ) {
    client.print("Backward");
  }
  else if(value1 == LOW && value2 == HIGH && value3 == HIGH && value4 == LOW  ) {
    client.print("Left");
  }
  else if(value1 == HIGH && value2 == LOW && value3 == LOW && value4 == HIGH  ) {
    client.print("Right");
  }
  else if(value1 == LOW && value2 == LOW && value3 == LOW && value4 == LOW  ) {
    client.print("Stop");
  }
  else if( value = HIGH) {
    client.print("LedOn");
  }
  else if( value = LOW) {
    client.print("LedOff");
  }
  client.println("<br><br>");
  client.println("<a href=\"/MotorForward\"\"><button>Forward </button></a>");
  client.println("<a href=\"/MotorBackward\"\"><button>Backward </button></a><br />");
  client.println("<a href=\"/MotorLeft\"\"><button>Left </button></a>");
  client.println("<a href=\"/MotorRight\"\"><button>Right </button></a><br/>");
  client.println("<a href=\"/MotorStop\"\"><button>Stop </button></a>");
  client.println("<a href=\"/LedOn\"\"><button>LedOn </button></a>");
  client.println("<a href=\"/LedOff\"\"><button>LedOff </button></a>");
  client.println("</html>");
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
}

Projects

  1. DIWA Robot

Arduino Tutorials – Lesson 23- L293D Motor Driver Control Shield with Arduino MEGA 2560.

Creating 2 DC Motors, 2 Servos and 2 LEDs control program using Arduino MEGA 2560

Required Components

  1. L293D Motor Driver Control -1 no
  2. Arduino MEGA 2560 Board -1 no
  3. 5V DC Motors -2 no
  4. Servo -2 no
  5. LED -2 no
  6. 9V Battery -1 no
  7. Bluetooth -1 no
  8. USB cable -1 no
  9. Jumper Wires -10 no

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect the 9V Battery to the L293D Motor Driver.
  3. Connect the 2 Servo motors to the motor driver servo pins properly.
  4. Connect the 2 DC motors pins to the motor driver output pins M3, M4.
  5. Connect the LED Cathodes (+) & Anode (-) pins to the Mega Board pins 50, 52 & gnd respectively.
  6. Connect the ground connection respectively.
  7. Check the Arduino program.
  8. Check the Circuit Connections.
  9. Run the Arduino program.

Arduino Program

#include <AFMotor.h>
#include <Servo.h>
AF_DCMotor motor1(3);
AF_DCMotor motor2(4);
Servo servo1;
Servo servo2;
Servo servo3;
int pos1=20;
int pos1min=50;
int pos1max=110;
int pos2=90;
int pos2min=110;
int pos2max=170;
int pos3=80;
int pos3min=50;
int pos3max=110;
int i=0;
int delaytime=10;
int led1 = 50;
int led2 = 52;
String inputString = "";
boolean stringComplete = false;

void setup() 
{
  Serial1.begin(9600);
  motor1.setSpeed(200);
  motor2.setSpeed(200);
  motor1.run(RELEASE);
  motor2.run(RELEASE);
  servo1.attach(9);
  servo2.attach(10);
  servo3.attach(48);
  servo1.write(pos1);
  servo2.write(pos2);
  servo3.write(pos3);
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  ledsOn();
}

void loop()
{
  ledsOn();
  serialEvent();
  if (stringComplete)
  {
    processCmd(inputString);
    inputString = "";
    stringComplete = false;
  }
}

void processCmd(String st1)
{
  st1.remove(st1.length());
  String cmd = st1.substring(0,1);
  st1="";
  if (cmd == "f")
  {
    motorForward();
  }
  else if (cmd == "b")
  {
    motorBackward();
  }
  else if (cmd == "r")
  {
    motorRight();
  }
  else if (cmd == "l")
  {
    motorLeft();
  }
  else if(cmd == "s")
  {
    motorStop();
  }
  else if(cmd == "1")
  {
    servoAction1();
  }
  else if(cmd == "2")
  {
    servoAction2();
  }
  else if (cmd=="o")
  {
    eyesBlink();
  }
}

void serialEvent()
{
  while (Serial1.available())
  {
    char inChar = (char)Serial1.read();
    inputString += inChar;
    if (inChar == '$')
    {
      stringComplete = true;
    }
  }
}
for(int i=0;i<5;i++)
{
  moveHandServoMotors(1);
}
delay(2000);
for(int i=0;i<5;i++)
{
  moveHandServoMotors(0);
}
delay(2000);


void motorForward()
{
  motor1.run(FORWARD);
  motor2.run(FORWARD);
  motor1.setSpeed(255);
  motor2.setSpeed(255);
}

void motorBackward()
{
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);
  motor1.setSpeed(255);
  motor2.setSpeed(255);
}

void motorLeft()
{
  motor1.run(BACKWARD);
  motor2.run(FORWARD);
  motor1.setSpeed(255);
  motor2.setSpeed(255);
}

void motorRight()
{
  motor1.run(FORWARD);
  motor2.run(BACKWARD);
  motor1.setSpeed(255);
  motor2.setSpeed(255);
}

void motorStop()
{
  motor1.run(RELEASE);
  motor2.run(RELEASE);
}

void ledsOn()
{
  digitalWrite(led1,HIGH);
  digitalWrite(led2,HIGH);
}

void ledsOff()
{
  digitalWrite(led1,LOW);
  digitalWrite(led2,LOW);
}

void eyesBlink()
{
  for(int i=0;i<8;i++)
  {
    ledsOn();
    delay(250);
    ledsOff();
    delay(250);
  }
}

void servoAction1()
{
  for(int i=0;i<5;i++)
  {
    moveHandServoMotors(0);
  }
}

void servoAction2()
{
  for(int i=0;i<5;i++)
  {
    moveHandServoMotors(1);
  }
}

void moveHeadServoMotor(int tp)
{
  if (tp==0)
  {
    servo3.write(pos3min);
    delay(1000);
    servo3.write(pos3max);
    delay(3000);
  }
  if (tp==1)
  {
    for(int i=0;i<60;i++)
    {
      servo3.write(pos3min+i);
      delay(delaytime);
    }
    delay(1000);
    for(int i=0;i<60;i++)
    {
      servo3.write(pos3max-i);
      delay(delaytime);
    }
    delay(3000);
  }
}

void moveHandServoMotors(int tp)
{
  if (tp==0)
  {
    servo1.write(pos1min);
    servo2.write(pos2min);
    servo3.write(pos3min);
    for(int i=0;i<60;i++)
    {
      servo1.write(pos1min+i);
      servo2.write(pos2min+i);
      servo3.write(pos3min+i);
      delay(delaytime);
    }
    delay(200);
    for(int i=0;i<60;i++)
    {
      servo1.write(pos1max-i);
      servo2.write(pos2max-i);
      servo3.write(pos3max-i);
      delay(delaytime);
    }
    delay(200);
  }
  else if (tp==1)
  {
    servo1.write(pos1min);
    servo2.write(pos2max);
    servo3.write(pos3min);
    for(int i=0;i<60;i++)
    {
      servo1.write(pos1min+i);
      servo2.write(pos2max-i);
      servo3.write(pos3min+i);
      delay(delaytime);
    }
    delay(200);
    for(int i=0;i<60;i++)
    {
      servo1.write(pos1max-i);
      servo2.write(pos2min+i);
      servo3.write(pos3max-i);
      delay(delaytime);
    }
    delay(200);
  }
}

Projects

  1. DIWA Robot

Arduino Tutorials – Lesson 22 – Micro Metal Gear Motor with Encoder

Creating DC Motor control with precise position program using Arduino UNO

Required Components

  1. Arduino MEGA2560 -1 no
  2. Motor control shield(L293D) -1 no
  3. Micro Metal Gear Motor with Encoder -1 no
  4. Motor Wheel -1 no
  5. Bread Board -1 no
  6. Jumper Wires(Male to Male) -11 no
  7. Voltage Converter(5V-3.3V) -1 no
  8. 5V Battery -1 no
  9. USB cable -1 no

Steps

  1. Make sure the components are working properly.
  2. Connect the 5V Battery to the L293D Motor Driver.
  3. Connect the micro motor M1,M2 pins to the L293D Motor Driver M3 respectively .
  4. Connect the Arduino Mega board pins 5V, gnd to the voltage converter V IN, gnd properly.
  5. Connect the Voltage converter V Out, gnd pins to the micro motor gnd, vcc pins & the second micro motor gnd, vcc pins properly.
  6. Connect the micro motor C1,C2 pins to the Arduino Mega board pins 18,19 respectively.
  7. Check the Circuit Connections.
  8. Check the Arduino program.
  9. Run the Arduino program.

Arduino Program

#include <AFMotor.h>
#include <Encoder.h>
AF_DCMotor motor1(4);
Encoder myEnc1(18,19);
long oldPosition1  = -999;
long m1Pos = 0;
long m1Dir = 0;
long md1=2000;


void setup()
{
  Serial.begin(9600);
  Serial.println("Motor test!");
  motor1.setSpeed(200);
  motor1.run(RELEASE);
  motor1Move(md1,0);
}

void loop()
{
  checkMotor1();
  delay(5);
}

void motor1Move(int d1,int d2)
{
  m1Pos=d1;
  m1Dir = d2;
  if (d2==0)
  {
    motor1.run(FORWARD);
  }
  else if (d2==1)
  {
    motor1.run(BACKWARD);
  }
}


void checkMotor1()
{
  long newPosition1 = myEnc1.read();
  if (m1Dir==0)
  {
    if ( newPosition1>m1Pos)
    {
      m1Pos=0;
      motor1.run(RELEASE);
      myEnc1.write(0);
      motor1Move(md1,1);
    }
  }
  else
  {
    if ( abs(newPosition1)>m1Pos)
    {
      m1Pos=0;
      motor1.run(RELEASE);
      myEnc1.write(0);      
      motor1Move(md1,0);
    }
  }
}

Arduino Tutorials – Lesson 21 – Stepper motor control Using Arduino UNO

Creating stepper motor control program using Arduino UNO

Required Components

  1. Stepper Motor (NEMA17) -1 no
  2. A4988 Stepper Driver -1 no
  3. 12V 2A Adapter -1 no
  4. Arduino Board UNO or MEGA -1 no
  5. Connecting wires -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect the servo motor drive to the Arduino UNO.
  3. Connect the Servo motor to their driver circuit.
  4. Connect the external power source to the servo motor.
  5. Connect the Arduino pin 3&4 to driver circuit.
  6. Connect the +5v and ground(gnd) connections respectively.
  7. Check the Circuit Connections.
  8. Check the Arduino program.
  9. Run the Arduino program.

Arduino Program

#include <Stepper.h>
const int stepPin = 3;
const int dirPin = 4;

void setup( )
{
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
}
void loop( )
{
  digitalWrite(dirPin,HIGH);
  for(int x = 0; x < 200; x++)
  {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(500);
  }
  delay(1000);
  digitalWrite(dirPin,LOW);
  for(int x = 0; x < 400; x++)
  {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(500);    
  }
  delay(1000); 
}

Usage

  1. Packaging
  2. Industry automation
  3. Conveyer belt

Projects

  1. Robot arm
  2. Dustbin

Arduino Tutorials – Lesson 20 – Color Sensor Using Arduino UNO

Creating the reflected color when the light sensor shining a white light at an object program using Arduino UNO

Required Components

  1. Arduino UNO -1 no
  2. Color Sensor -1 no
  3. USB cable -1 no
  4. Jumper Wires -7 no

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect the Color Sensor S0, S1, S2, S3 &Out pins to the Arduino UNO board pins 4,5,6,7 &8 respectively.
  3. Connect the sensor vcc pin to the Arduino UNO 5V pin.
  4. Connect the ground connection respectively.
  5. Check the Arduino program.
  6. Check the Circuit Connections.
  7. Run the Arduino program.

Arduino Program

#define s0 4
#define s1 5
#define s2 6
#define s3 7
#define out 8
int data=0;

void setup()
{
  pinMode(s0,OUTPUT);
  pinMode(s1,OUTPUT);
  pinMode(s2,OUTPUT);
  pinMode(s3,OUTPUT);
  pinMode(out,INPUT);
  Serial.begin(9600);
  digitalWrite(s0,HIGH);
  digitalWrite(s1,HIGH);
}

void loop()
{
  digitalWrite(s2,HIGH);
  digitalWrite(s3,HIGH);
  Serial.print("Red value= ");
  GetData();
  digitalWrite(s2,LOW);
  digitalWrite(s3,HIGH);
  Serial.print("Blue value= ");
  GetData();
  digitalWrite(s2,LOW);
  digitalWrite(s3,LOW);
  Serial.print("Green value= ");
  GetData();
  Serial.println();
  delay(500);
}

void GetData()
{
  data=pulseIn(out,LOW);
  Serial.print(data
  Serial.print("\t");
  delay(20);
}

Usage

  1. Color temperature measurement
  2. RGB LED consistency control
  3. Medical diagnosis systems
  4. Health fitness systems
  5. Industrial process control

Arduino Tutorials – Lesson 19 – Sound And Light Program Using Arduino UNO

Creating LEDs flash program Using Sound sensor

Required Components

  1. Arduino UNO -1 no
  2. Sound sensor -1 no
  3. Resistor 150 ohm -6 no
  4. LEDs -6 no
  5. Connecting wires -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect the Sound sensor to the Arduino UNO board.
  3. Connect the Arduino UNO board 8, 9 ,10 ,11 ,12 ,13- pins to the LEDs.
  4. Connect the Arduino UNO board A0 pin to the Sound sensor.
  5. Connect the 150 Ohm Resistor to all the LEDs.
  6. Connect Sound sensor board VCC, GND to 5V, GND of Arduino Uno Board.
  7. Check the Cicuit Connections.
  8. Check the Arduino program.
  9. Run the Arduino program.

Arduino Program

int ledPin1= 8; 
int ledPin2= 9;
int ledPin3= 10;  
int ledPin4= 11;
int ledPin5= 12;
int ledPin6= 13;
int sensorPin= A0; 
int val = 0;

void setup( )
{
  pinMode(ledPin1, OUTPUT); 
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(sensorPin, INPUT); 
  Serial.begin (9600);
}

void loop (  )
{
  val =analogRead(sensorPin);
  Serial.println (val);
  if (val >= 127) 
  {
    digitalWrite(ledPin1, HIGH); 
  }else {
    digitalWrite(ledPin1, LOW);
  }
  if (val >= 378) 
  {
    digitalWrite(ledPin2, HIGH);
  }else {
    digitalWrite(ledPin2, LOW);
  }
  if (val >= 505) 
  {
    digitalWrite(ledPin3, HIGH);
  }else {
    digitalWrite(ledPin3, LOW);
  }
  if (val >= 632)
  {
    digitalWrite(ledPin4, HIGH);
  }else 
  {
    digitalWrite(ledPin4, LOW);
  }
  if (val >= 759) {
    digitalWrite(ledPin5, HIGH);
  }else 
  {
    digitalWrite(ledPin5, LOW);
  }
  if (val >= 886)
  {
    digitalWrite(ledPin6, HIGH);
  }else 
  {
    digitalWrite(ledPin6, LOW);
  }
}

Usage

  1. Security system for Office or Home
  2. Spy Circuit
  3. Home Automation
  4. Smart Phones
  5. Ambient sound recognition
  6. Audio amplifier

Projects

  1. Lightning cloud

Arduino Tutorials – Lesson 18 – A Solenoid Valve Control Using Arduino UNO

Creating A Solenoid Valve program using Arduino UNO

Required Components

  1. Solenoid valve -1 no
  2. Darlington Transistor -1 no
  3. Resistor(10K) -1 no
  4. IN4001 Diode -1 no
  5. Arduino UNO -1 no
  6. Bread board -1 no
  7. Connecting wires -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect the Transistor to the Arduino UNO board & Solenoid valve.
  3. Connect the 10K resistor to the Transistor.
  4. Connect the Power supply to the Solenoid valve.
  5. Connect the Solenoid valve to the Arduino UNO board.
  6. Connect the 10K resistor to the 2nd pin of Arduino UNO board.
  7. Check the Cicuit Connections.
  8. Check the Arduino program.
  9. Run the Arduino program.

Arduino Program

int solenoidPin = 9;
                                   
void setup( )
{
  pinMode(solenoidPin, OUTPUT);          
}

void loop( )
{
  digitalWrite(solenoidPin, HIGH);           
  delay(1000);                                             
  digitalWrite(solenoidPin, LOW);            
  delay(1000);                                             
}

Usage

  1. Computer printers
  2. Fuel injection gear
  3. Vehicles like cars
  4. Industrial setting

Arduino Tutorials – Lesson 17 – Soil Moisture Sensor Using Arduino UNO

Creating Soil Moisture Sensor program using Arduino UNO

Required Components

  1. Soil sensor -1 no
  2. Arduino UNO -1 no
  3. Connecting Wires -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect the Soil moisture to the Arduino UNO board.
  3. Connect the Arduino UNO board A0 pin to the Soil moisture(Analog or Digital).
  4. Connect the interfacing to the Arduino UNO board.
  5. Connect Humidity Sensor board VCC, GND to 5V, GND of Arduino Uno Board.
  6. Check the Cicuit Connections.
  7. Check the Arduino program.
  8. Run the Arduino program.

Arduino Program

int sensorPin = A0;
int sensorValue;
int limit = 300;

void setup( )
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop( )
{
  sensorValue = analogRead(sensorPin);
  Serial.println("Analog Value : ");
  Serial.println(sensorValue);
  if (sensorValue<limit)
  {
    digitalWrite(13, HIGH);
  }
  else{
    digitalWrite(13, LOW);
  }
  delay(1000);
}

Usage

  1. Agricultural science and horticulture
  2. Irrigation planning
  3. Climate research
  4. Solute transport studies
  5. Auxiliary sensors for soil respiration

Arduino Tutorials – Lesson 16 – Humidity Sensor Using Arduino UNO

Creating Humidity Sensor program using Arduino UNO

Required Components

  1. Humidity Sensor(DHT22) -1 no
  2. Arduino UNO -1 no
  3. Connecting wires -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect the Humidity Sensor to the Arduino UNO board.
  3. Connect the Arduino UNO board 2nd pin to the Humidity Sensor.
  4. Connect Humidity Sensor board VCC, GND to 5V, GND of Arduino Uno Board.
  5. Check the Cicuit Connections.
  6. Check the Arduino program.
  7. Run the Arduino program.

Arduino Program

#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

void setup() 
{
  Serial.begin(9600);
  Serial.println("DHTxx test!");
  dht.begin();
}

void loop( )
{
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);
  if (isnan(h) || isnan(t) || isnan(f)) 
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);
  Serial.print ("Humidity: ");
  Serial.print (h);
  Serial.print (" %\t");
  Serial.print ("Temperature: ");
  Serial.print (t);
  Serial.print (" *C ");
  Serial.print (f);
  Serial.print (" *F\t");
  Serial.print ("Heat index: ");
  Serial.print (hic);
  Serial.print (" *C ");
  Serial.print (hif);
  Serial.println (" *F");
}

Usage

  1. Industrial process &control systems
  2. Office automation
  3. Clothes dryer
  4. Microwave ovens
  5. Printers