Mostafa zaghloulsarah gamalMohamed MostafaHamada HamzaRokaya Elhakim
Published

Accelerometer Car with 4 Motors Controlled

The idea is to send High/Low, or 0/1, to the motor driver to control your car with the accelerometer shield from 1Sheeld.

BeginnerShowcase (no instructions)1,732
Accelerometer Car with 4 Motors Controlled

Things used in this project

Hardware components

1Sheeld
1Sheeld
×1
Arduino UNO
Arduino UNO
×1
4WD Smart Robot Car Chassis Kit
×1
motor drive L239D
×2

Story

Read more

Schematics

unnamed.pdf

Code

The Code

C/C++
Upload your sketch:
Here comes the most important part of the whole tutorial, switch 1Sheeld to the Uploading-mode (this is the switch labeled UART Switch on the board) before you upload your sketch to the Arduino board to avoid serial conflicts between 1Sheeld and Arduino, then press the Upload button in the IDE.
- Once you have completed your upload you need to switch 1Sheeld back to the operating mode.
Don’t forget! If you don’t switch the UART Switch back to the operating mode your project will not work properly as you will have no communication between 1Sheeld and the Arduino board.
Turn on Your 1Sheeld App on your Mobile Phone.
#define CUSTOM_SETTINGS
#define INCLUDE_ACCELEROMETER_SENSOR_SHIELD


#include <OneSheeld.h>

int pin5 = 5;
int pin6 = 6;
int pin9 = 9;
int pin10 = 10;
int pin3=3;
int pin11=11;

void setup()
{
  /* Start communication. */
  OneSheeld.begin();
  /* Set the LED pin as output. */
  pinMode(pin5,OUTPUT);
  pinMode(pin6,OUTPUT);
  pinMode(pin9,OUTPUT);
  pinMode(pin10,OUTPUT);
  pinMode(pin3,OUTPUT);
  pinMode(pin11,OUTPUT);
}

void loop()
{
 
  
  
  if(AccelerometerSensor.getY() > 5 )
  {
    analogWrite(pin5,200);
    analogWrite(pin6,0);
    analogWrite(pin9,255);
    analogWrite(pin10,0);
    analogWrite(pin3,255);
    analogWrite(pin11,0);
    
  }
  if(AccelerometerSensor.getY() < -5 )
  {
    analogWrite(pin5,0);
    analogWrite(pin6,200);
    analogWrite(pin9,0);
    analogWrite(pin10,255);
    analogWrite(pin3,0);
    analogWrite(pin11,255);
  }
   
  if(AccelerometerSensor.getX() > 5)
  {
    analogWrite(pin5,0);
    analogWrite(pin6,0);
    analogWrite(pin9,255);
    analogWrite(pin10,0);
  }
  

  if(AccelerometerSensor.getX() < -5)
  {
    analogWrite(pin5,200);
    analogWrite(pin6,0);
    analogWrite(pin9,0);
    analogWrite(pin10,0);
  }
  if(AccelerometerSensor.getZ() > 9)
  {
    analogWrite(pin5,0);
    analogWrite(pin6,0);
    analogWrite(pin9,0);
    analogWrite(pin10,0);
    analogWrite(pin3,0);
    analogWrite(pin11,0);
  }
  
    
}

Credits

Mostafa zaghloul

Mostafa zaghloul

6 projects • 19 followers
mostafa zaghloul a communication engineer student at "Egypt's Higher Institute Mansoura"
sarah gamal

sarah gamal

4 projects • 10 followers
Mohamed Mostafa

Mohamed Mostafa

4 projects • 9 followers
Mini Engineer
Hamada Hamza

Hamada Hamza

4 projects • 7 followers
عضو فى تيم صغنن خالص تقدر تقول بنستفاد من بعض
Rokaya Elhakim

Rokaya Elhakim

3 projects • 3 followers

Comments