Mahmoud Ayad
Published © GPL3+

Controlled Board Eraser using Arduino and 1Sheeld

Erase your board according to your smart phone accelerometer sensor values or using the 1sheeld gamepad

IntermediateWork in progress9,715
Controlled Board Eraser using Arduino and 1Sheeld

Things used in this project

Hardware components

Android device
Android device
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
1Sheeld
1Sheeld
×1
Micro Metal DC motor kit
×2
L298 Dual H-Bridge Motor Driver
×1
Magnetic Disk
×2
LED (generic)
LED (generic)
×1

Hand tools and fabrication machines

Magnetic Board Eraser

Story

Read more

Schematics

Fritzing Project Diagram

Fritzing Diagram

Code

Automatic_Eraser.ino

C/C++
This is the code for the board eraser to be controlled either by a game pad shield or by the mobile accelerometer sensor values to move in all directions and erase the board. A LED is used to give a clear sign for user that it is erasing now.
#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_SHIELD
#define INCLUDE_LED_SHIELD
#define INCLUDE_ACCELEROMETER_SENSOR_SHIELD


float x, y, z;


/* Include 1Sheeld library. */
#include <OneSheeld.h>

/* A name for the LED on pin 7. */
const int ledPin = 13;



/* Pin configuration of the Seeedstudio's motor shield. */
int motorAPin1 = 8;
int motorAPin2 = 11;
int motorBPin1 = 12;
int motorBPin2 = 7;
int motorASpeedPin = 9;
int motorBSpeedPin = 10;

void setup()
{
  /* Start communication. */
  OneSheeld.begin();
  /* Set the LED pin as output. */
  pinMode(ledPin, OUTPUT);

  /* Seeedstudio's motor shield initialization. */
  pinMode(motorAPin1, OUTPUT);    // IN1 of motor A
  pinMode(motorAPin2, OUTPUT);    // IN2 of motor A
  pinMode(motorBPin1, OUTPUT);    // IN3 of motor B
  pinMode(motorBPin2, OUTPUT);    // IN4 of motor B
  pinMode(motorASpeedPin, OUTPUT); // Speed of motor A
  pinMode(motorBSpeedPin, OUTPUT); // Speed of Motor B
}

void loop()

{ x=AccelerometerSensor.getX();
  y=AccelerometerSensor.getY();
  z=AccelerometerSensor.getZ();
  
  /* If up is pressed, move the car forward. */
  if (GamePad.isUpPressed()|| y < -5)
  {
    analogWrite(motorASpeedPin, 255);
    analogWrite(motorBSpeedPin, 255);
    digitalWrite(motorAPin1, LOW);
    digitalWrite(motorAPin2, HIGH);
    digitalWrite(motorBPin1, LOW);
    digitalWrite(motorBPin2, HIGH);
    digitalWrite(ledPin, HIGH);

  }
  /* If down is pressed, move the car backwards. */
  else if (GamePad.isDownPressed()||  y > 6)
  {
    analogWrite(motorASpeedPin, 255);
    analogWrite(motorBSpeedPin, 255);
    digitalWrite(motorAPin1, HIGH);
    digitalWrite(motorAPin2, LOW);
    digitalWrite(motorBPin1, HIGH);
    digitalWrite(motorBPin2, LOW);
    digitalWrite(ledPin, HIGH);


  }
  /* If right is pressed, turn the car to the right. */
  else if (GamePad.isRightPressed() || x < -6)
  {
    analogWrite(motorASpeedPin, 255);
    analogWrite(motorBSpeedPin, 255);
    digitalWrite(motorAPin1, LOW);
    digitalWrite(motorAPin2, HIGH);
    digitalWrite(motorBPin1, HIGH);
    digitalWrite(motorBPin2, LOW);
    digitalWrite(ledPin, HIGH);

  }
  /* If left is pressed, turn the car to the left. */
  else if (GamePad.isLeftPressed()|| x > 6)
  {
    analogWrite(motorASpeedPin, 255);
    analogWrite(motorBSpeedPin, 255);
    digitalWrite(motorAPin1, HIGH);
    digitalWrite(motorAPin2, LOW);
    digitalWrite(motorBPin1, LOW);
    digitalWrite(motorBPin2, HIGH);
    digitalWrite(ledPin, HIGH);

  }
  /* If nothing is pressed stop all motors. */
  else
  {
    analogWrite(motorASpeedPin, 0);
    analogWrite(motorBSpeedPin, 0);
    digitalWrite(ledPin, LOW);
  }
 
}

Credits

Mahmoud Ayad

Mahmoud Ayad

1 project • 11 followers
Electronics and communication engineer

Comments